Skip to main content

DeferredBuilding

deferred-building

It is used when you want to defer the rendering of a widget.

See the DeferredBuildingDemo.cs.

namespace Gridrand.RimGui.Manual
{
/// <summary>
/// This is a demo using <see cref=Context.BeginDeferredBuilding"/> and
/// <see cref=Context.EndDeferredBuilding"/>.
/// It is used when you want to defer the rendering of a widget.
/// </summary>
class DeferredBuildingDemo : ManualBase, IManual
{

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

public void Draw()
{
using var vertRects = LayoutBuilder.Fit(1f).Fit(1f).Fit(1f).BuildAllocatedHorizontal(height: 100f);

/// Within this scope, widget rendering is deferred and drawn after the next widget.
///
/// If you want to render a widget in the foreground, you need to execute it later.
/// However, executing it later will cause its input processing to be prioritized
/// over the widget executed earlier.
/// In such cases, using <see cref="Context.BeginDeferredBuilding"/> allows
/// you to render the widget after the next widget.
using (Ctx.BeginDeferredBuilding())
{
using (Style.Button.Colors.Begin(Style.Button.Colors.Get().ChangeAlpha(220)))
using (Style.Button.HoveredColors.Begin(Style.Button.HoveredColors.Get().ChangeAlpha(220)))
{

// Rendered in the foreground.
if (Gui.NextRect(vertRects.R1.CreateCenteredWithHeight(30f * Style.ScaleFactor)).Button("Front"))
{
Logger.Debug("IsPressed Front");
}
}
}

using (Style.FontSizes.Begin(70f))
{
// Rendered in the background.
if (Gui.NextRect(vertRects.Whole).Button("Back"))
{
Logger.Debug("IsPressed Back");
}
}
}
}

}