SubWindow
A SubWindow is a child-like window associated with a Window.
Multiple SubWindows can be linked to a single Window.
See the SubWindowDemo.cs.
using Gridrand.Contracts;
using Gridrand.RimGui.Manual.Utility;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demonstrates the usage of sub-windows in the GUI.
/// A SubWindow is a child-like window associated with a Window.
/// Multiple SubWindows can be linked to a single Window.
/// </summary>
class SubWindowDemo : ManualBase, IManual
{
bool show;
bool showMousePos;
static readonly Gridrand.Contracts.Rendering.TextStyle textStyle = new();
Vector2Int subWindow1Pos = new(300, 300);
Vector2Int subWindow1Size = new(200, 200);
public SubWindowDemo(ManualBaseResource p) : base(p)
{
// Setting the text color range for the style
textStyle.Insert(new RangeColor(Color.Gray, 0..5));
}
public void Draw()
{
// UI to control the visibility of the first sub-window
Gui.LabelInput("Show", ref show);
Gui.LabelInput("Pos", ref subWindow1Pos);
Gui.LabelInput("Size", ref subWindow1Size);
if (show)
{
// Layout the sub-window with the specified position and size
using (Style.SubWindow.BeginLayout(subWindow1Pos, subWindow1Size))
{
// Begins a SubWindow.
if (Gui.BeginSubWindow("Demo"))
{
Gui.Text("AAA");
Gui.Text("BBB");
Gui.Text("CCC");
Gui.TextColorTexture(Assets.SampleTexture);
// Must be executed if BeginSubWindow() returns true.
Gui.EndSubWindow();
}
}
}
Gui.Separator();
Gui.Text("Display while hovering.");
// Apply the text style for the tooltip display
using (Style.Text.Styles.Begin(textStyle))
Gui.NextTextWidth(" (?) ").Text(" (?) ");
// Check if the mouse pointer is over the last widget and show a tooltip sub-window if true
if (Gui.Context.IsValidPointerIn(Gui.Context.GetLastWidgetRect()))
{
// Position and layout the tooltip sub-window based on the mouse position
using (Style.SubWindow.BeginAutoSizeLayout(Input.Pointer.Pos + new Vector2(15, -15), new Vector2(400, 400)))
{
if (Gui.BeginSubWindow("Demo"))
{
Gui.NextTextWidth("Tooltip").Text("Tooltip");
Gui.EndSubWindow();
}
}
}
Gui.Separator();
Gui.LabelInput("Show mouse pos", ref showMousePos);
if (showMousePos)
{
// Position and layout the sub-window near the mouse position
using (Style.SubWindow.BeginAutoSizeLayout(Input.Pointer.Pos + new Vector2(15, -15), new Vector2(200, 200)))
{
if (Gui.BeginSubWindow("Demo"))
{
var mousePosStr = Input.Pointer.Pos.ToString();
Gui.NextTextWidth(mousePosStr).Text($"{mousePosStr}");
Gui.EndSubWindow();
}
}
}
}
}
}