Axis
See the AxisDemo.cs.
using Gridrand.Contracts;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// A demo that renders using a specific axis with
/// <see cref="Context.Horizontal(int)"/>,
/// <see cref="Context.Vertical(int)"/>, or
/// <see cref="Context.BeginAxis(Axis, int)"/>.
/// </summary>
class AxisDemo : ManualBase, IManual
{
float width = 50f;
bool isOnCheckBox;
int sliderWidth = 100;
float sliderValue;
bool showExtra;
public AxisDemo(ManualBaseResource p) : base(p)
{
}
public void Draw()
{
Gui.Heading("Using SizeType.Fixed");
DrawUsingFixed();
Gui.Spacing();
Gui.Heading("Using SizeType.Ratio");
DrawUsingRatio();
Gui.Spacing();
Gui.Heading("Horizontal and Vertical");
DrawUsingHorizontalAndVertical();
Gui.Spacing();
Gui.Heading("Combination of padding and axis");
DrawWithPadding();
Gui.Spacing();
Gui.Heading("Misc");
DrawMisc();
Gui.Spacing();
}
void DrawUsingFixed()
{
Gui.LabelInputNumeric("width", ref width);
// Start horizontal rendering.
using (Ctx.Horizontal())
{
isOnCheckBox = Gui
.NextWidth(40)
.NextHeight(Size.Fixed(40))
.CheckBox(isOnCheckBox);
for (int i = 0; i < 3; i++)
{
using var s = Ctx.PushId(i);
if (Gui
.NextWidth(width)
.Button($"{i}"))
{
Logger.Debug("IsPressed");
}
}
}
}
void DrawUsingRatio()
{
// Start horizontal rendering.
using (Ctx.Horizontal())
{
// note:Due to the spaces, even with this ratio setting, it cannot be rendered at 1:1.
if (Gui.NextRatioWidth(1 / 2f).Button($"0"))
{
}
if (Gui.NextRatioWidth(1 / 1f).Button($"1"))
{
}
}
}
// Combination of padding and Axis.
void DrawWithPadding()
{
// Start vertical rendering.
using (Ctx.Vertical())
{
TextButton("0");
using (Ctx.BeginPadding(new Padding(20, 20, 20, 20)))
TextButton("1");
using (Ctx.Horizontal())
{
TextButton("2");
TextButton("3");
}
TextButton("4");
}
void TextButton(string s)
{
Gui.NextWidth(50).Button(s);
}
}
void DrawUsingHorizontalAndVertical()
{
var i = 0;
using (Ctx.Horizontal())
{
Text();
// If switched to vertical rendering during horizontal rendering,
// rendering will continue horizontally from the current position.
using (Ctx.Vertical())
{
Text();
Text();
using (Ctx.Horizontal())
{
Text();
Text();
// The rendering result does not change if the Axis and Alignment are the same.
using (Ctx.Horizontal())
{
Text();
}
}
Text();
}
Text();
}
void Text()
{
Gui.NextWidth(50).Button(i.ToString());
i++;
}
}
void DrawMisc()
{
Gui.LabelInputNumeric("slider width", ref sliderWidth);
using (Ctx.Horizontal())
{
Gui.NextWidth(20f).CheckBox(ref showExtra);
sliderValue = Gui.NextWidth(sliderWidth).SliderNumeric(sliderValue, 0f, 100f);
using (Ctx.Vertical())
{
Gui.Image(Assets.SampleTexture);
Gui.FixedWidthText($"{sliderValue}");
if (showExtra)
Gui.Text("AAA");
}
}
}
}
}