Skip to main content

Dropdown

dropdown

See the DropdownDemo.cs.

using System;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demos such as
/// <see cref="Gui.Dropdown(System.Collections.Generic.IReadOnlyList{string}, ref int, int)"/> and
/// <see cref="Gui.InputDropdown(System.Collections.Generic.IReadOnlyList{string}, ref int, int)"/>
/// </summary>
class DropdownDemo : ManualBase, IManual
{
SampleEnum sampleEnum1;
SampleEnum sampleEnum2;
SampleFlagEnum sampleFlagEnum;
int selectedIndex1;
int selectedIndex2;
readonly string[] items1 = new string[3]
{
"AAA",
"BBB",
"CCC",
};
string[] items2 = new string[9]
{
"012",
"123",
"234",
"345",
"456",
"567",
"678",
"789",
"890",
};
public DropdownDemo(ManualBaseResource p) : base(p)
{
}

public void Draw()
{
Gui.Heading("Dropdown");
// Pass the selected enum as the argument.
Gui.Dropdown(ref sampleEnum1);
Gui.Dropdown(items1, ref selectedIndex1);

// Multiple selections possible
Gui.Dropdown(ref sampleFlagEnum);

Gui.Heading("LabelDropdown");
Gui.LabelDropdown("with label", items1, ref selectedIndex1);
Gui.LabelDropdown("with label", ref sampleEnum2);

Gui.Heading("InputDropdown");
Gui.InputDropdown(items1, ref selectedIndex1);
Gui.InputDropdown(ref sampleEnum2);

// The items will be scrolled because their total height is greater than MaxHeights.
using (Style.Dropdown.MaxHeights.Begin(100))
Gui.InputDropdown(items2, ref selectedIndex2);
}

enum SampleEnum
{
Element0,
Element1,
Element2
}

// If FlagsAttribute is attached, multiple selection is possible.
[Flags]
enum SampleFlagEnum
{
None = 0,
Element1 = 1 << 0,
Element2 = 1 << 1,
Element3 = 1 << 2,
Element4 = 1 << 3,
}
}
}