Style
See the StyleDemo.cs.
using Gridrand.Contracts;
using Gridrand.RimGui.Manual.Utility;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// This is a demo using <see cref="Style"/>.
///
/// <see cref="Style"/> is a class used to configure the overall settings of the GUI and individual widget settings.
///
/// For Button Style, see <see cref="ButtonStyleDemo"/>.
/// </summary>
class StyleDemo : ManualBase, IManual
{
float width = 100f;
float height = 50f;
bool isDisabled = true;
int sliderInt = 0;
float scaleFactor = 1.5f;
bool isChecked;
float spacingX = 10f;
float spacingY = 10f;
public StyleDemo(ManualBaseResource p) : base(p)
{
}
public void Draw()
{
DrawWidthAndHeight();
DrawUsingDisabledScope();
DrawUsingScaleFactor();
DrawSpacing();
}
void DrawWidthAndHeight()
{
Gui.Heading("Width And Height");
Gui.LabelSliderInputFloat("Width", ref width, 10f, 500f);
Gui.LabelSliderInputFloat("Height", ref height, 10f, 500f);
// Set the width and height.
using (Style.WidgetWidths.Begin(Size.Fixed(width)))
using (Style.WidgetHeights.Begin(Size.Fixed(height)))
{
Gui.Button("Button");
}
}
// It allows you to disable widgets, making them unresponsive to input.
void DrawUsingDisabledScope()
{
Gui.Heading("Disabled Scope");
Gui.LabelInput("Disabled", ref isDisabled);
using (Gui.BeginFrame())
{
// Within this scope, widgets are enabled or disabled based on isDisabled.
using (Style.BeginDisabled(isDisabled))
{
// When disabled, this button cannot be clicked.
if (Gui.Button("Button"))
{
Logger.Debug("Pressed Button");
}
if (Gui.Foldout("Foldout"))
{
using (Ctx.BeginIndent())
Gui.LabelSliderInputInt("Slider int", ref sliderInt, 0, 100);
}
}
}
}
void DrawUsingScaleFactor()
{
Gui.Heading("Scale Factor");
Gui.LabelSliderInputFloat("ScaleFactor", ref scaleFactor, 0.1f, 5f);
// The size of all widgets can be scaled.
using (Style.ScaleFactors.Begin(scaleFactor))
using (Gui.BeginBox())
{
using (Style.Text.Colors.Begin(new Color32(50, 150, 50, 255)))
Gui.Text("ABC");
isChecked = Gui.RadioButton(isChecked);
}
}
void DrawSpacing()
{
Gui.Heading("Spacing");
Gui.LabelSliderInputFloat("SpacingX", ref spacingX, 0.0f, 100f);
Gui.LabelSliderInputFloat("SpacingY", ref spacingY, 0.0f, 100f);
// Spacing is the space between widgets.
using (Style.SpacingXs.Begin(spacingX))
using (Style.SpacingYs.Begin(spacingY))
{
using (Ctx.BeginHorizontal())
{
if (Gui.NextWidth(70).Button("Button1"))
Logger.Debug("Pressed Button1");
if (Gui.NextWidth(70).Button("Button2"))
Logger.Debug("Pressed Button2");
if (Gui.NextWidth(70).Button("Button3"))
Logger.Debug("Pressed Button3");
}
using (Ctx.BeginHorizontal())
{
if (Gui.NextWidth(70).Button("Button4"))
Logger.Debug("Pressed Button4");
if (Gui.NextWidth(70).Button("Button5"))
Logger.Debug("Pressed Button5");
if (Gui.NextWidth(70).Button("Button6"))
Logger.Debug("Pressed Button6");
}
using (Ctx.BeginHorizontal())
{
if (Gui.NextWidth(70).Button("Button7"))
Logger.Debug("Pressed Button7");
if (Gui.NextWidth(70).Button("Button8"))
Logger.Debug("Pressed Button8");
if (Gui.NextWidth(70).Button("Button9"))
Logger.Debug("Pressed Button9");
}
}
}
}
}