Skip to main content

Button

button

See the ButtonDemo.cs.

using Gridrand.Contracts;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demo of various buttons such as:
/// <see cref="Gui.Button(int)"/>
/// <see cref="Gui.BeginButton(int)"/>
/// <see cref="Gui.RadioButton(bool, int)"/>
/// <see cref="Gui.ToggleButton(ref bool, int)"/>.
/// </summary>
class ButtonDemo : ManualBase, IManual
{
bool isOnRadioButton1;
bool isOnRadioButton2;
Direction direction;

bool isSelected1 = true;
bool isSelected2 = true;
bool isSelected3 = true;

public ButtonDemo(ManualBaseResource p) : base(p)
{
}

public void Draw()
{
Gui.Heading("Button");
DrawButtons();
Gui.Heading("Radio Button");
DrawRadioButtons();
Gui.Heading("Toggle Button");
DrawToggleButtons();
}

void DrawButtons()
{
// An empty button that draws nothing except for the button itself.
// Returns true when pressed.
if (Gui.Button())
Logger.Debug("Pressed");

if (Gui.Button("Button"))
Logger.Debug("Pressed");

// Set the padding of the Button within the scope.
using (Style.Button.Paddings.Begin(new(2, 2, 2, 2)))
{
if (Gui.NextWidthHeight(30f, 30f).SpriteButton(Assets.SampleSprite))
Logger.Debug("Pressed");
}

// Begin the button scope.
using (Gui.BeginButton())
{
Gui.Text("0");
Gui.Text("1");
Gui.Text("2");
}
}

void DrawRadioButtons()
{
Gui.RadioButton(ref isOnRadioButton1);

Gui.NextWidthHeight(40f, 40f).RadioButton(ref isOnRadioButton2);

// Draw radio buttons horizontally.
using (Ctx.Horizontal())
direction = Gui.RadioButtons(direction);
}

void DrawToggleButtons()
{
if (Gui.ToggleButton(ref isSelected1))
{
Logger.Debug("Pressed");
}

using (Gui.BeginToggleButton(isSelected2))
{
Gui.Text("0");
Gui.Text("1");
Gui.Text("2");
}
// Determine whether it is selected through Context.
isSelected2 = Ctx.IsLastSelected();

Gui.ToggleButton("ToggleButton", ref isSelected3);
}
}
}