Scroll
See the ScrollDemo class.
void DrawSettings()
{
Gui.Heading("Settings");
var rects = RectsBuilder.AllocateMainAndToolTipRect();
Gui.NextRect(rects.Main).LabelInputBool("FixToBottom", ref shouldFixToBottom);
Gui.NextRect(rects.ToolTip).ToolTip("Keep the scroll fixed at the bottom even when new widgets are added.");
}
void DrawWithDynamic()
{
Gui.NextWidth(Ctx.GetCurrentRegionWidth() - CharFixedMap.CalcToolTipXAdvance() - Style.SpacingXs.Get())
.Heading("Dynamic");
Gui.NextRect(Ctx.GetHorizontalRemainRect())
.ToolTip(
"A scroll that allows dynamic addition of widgets.\n" +
"Suitable when the number of widgets is not large, as it processes all of them.");
// Controls for modifying scroll properties.
Gui.LabelSlider("OuterTextCount", ref outerTextCount, 0, 100);
Gui.LabelSlider("innerTextCount", ref innerTextCount, 0, 100);
Gui.LabelSlider("OuterHeight", ref outerHeight, 0, 300);
Gui.LabelSlider("InnerHeight", ref innerHeight, 0, 300);
using var p = Gui.BeginFramePadding1();
Gui.NextHeight(Size.Fixed(outerHeight));
// Outer scrollable area.
if (Gui.BeginScroll())
{
using (Gui.BeginFramePadding1())
{
// Inner scrollable area.
Gui.NextHeight(Size.Fixed(innerHeight));
if (Gui.BeginScroll())
{
for (int i = 0; i < innerTextCount; i++)
{
using (Ctx.PushId(i))
Gui.Text($"inner:{i}");
}
Gui.EndScroll();
}
}
for (int i = 0; i < outerTextCount; i++)
{
Gui.Text($"outer:{i}");
}
Gui.EndScroll();
}
}
void DrawUsingHandler()
{
Gui.NextWidth(Ctx.GetCurrentRegionWidth() - CharFixedMap.CalcToolTipXAdvance() - Style.SpacingXs.Get())
.Heading("Fixed");
Gui.NextRect(Ctx.GetHorizontalRemainRect())
.ToolTip(
"A scroll where the number and height of widgets must be determined before processing.\n" +
"It only processes the displayed widgets, making it fast even when there are many.");
// Controls for modifying fixed scroll properties.
Gui.LabelInputNumeric("Height", ref height);
Gui.LabelSlider("TextCount", ref textCountWithIterator, 0, 100);
using var p = Gui.BeginFramePadding1();
// Create a scroll handler with fixed height and item count.
var handler = Gui.CreateScrollHandler(height, textCountWithIterator, Style.StandardHeight);
// Render only visible items based on the scroll handler.
while (handler.Next())
{
Gui.Text($"{handler.CurrentIndex}");
}
}
/// <summary>
/// Demonstrates a scroll handler that automatically extends to the bottom of the window.
/// </summary>
void DrawToBottomOfWindow()
{
Gui.Heading("To the bottom of the window");
using var p = Gui.BeginFramePadding1();
Ctx.AddSpaceIfNeeded();
// Create a scroll handler that fills the remaining height in the window.
var handler = Gui.CreateScrollHandler(Ctx.GetRemainRect().height, 100, Style.StandardHeight);
// Render only visible items based on the scroll handler.
while (handler.Next())
{
Gui.Text(handler.CurrentIndex.ToString());
}
}