mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-22 05:09:37 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
40 lines
1007 B
C#
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; }
|
|
}
|
|
}
|