Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Razor/RenderTree.Scope.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

40 lines
1007 B
C#

namespace Sandbox.UI;
/// <summary>
/// This is a tree renderer for panels. If we ever use razor on other ui we'll want to make a copy of
/// this class and do the specific things to that.
/// </summary>
public partial class PanelRenderTreeBuilder : Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder
{
Stack<Scope> stack = new();
Scope CurrentScope;
void PushScope( int sequence, object key )
{
var loop = CurrentBlock.Increment( sequence );
stack.Push( CurrentScope );
CurrentScope.Sequence = sequence;
CurrentScope.Loop = loop;
CurrentScope.ChildIndex = 0;
CurrentScope.Hash = HashCode.Combine( key ?? CurrentScope.Loop, CurrentScope.Sequence );
}
void PopScope()
{
contentBuilder.Clear();
CurrentScope = stack.Pop();
}
struct Scope
{
public int Sequence { get; set; }
public int Loop { get; set; }
public Panel Element => Block?.ElementPanel;
public Block Block { get; set; }
public int ChildIndex { get; set; }
public int Hash { get; set; }
}
}