Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Razor/RenderTree.Events.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

47 lines
1.9 KiB
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
{
/// <summary>
/// Handles @onclick=@( () => DoSomething( "boobies" ) )
/// </summary>
public void AddAttributeAction( int sequence, string attrName, Action value )
{
// There's no real good way to cache this shit. The function is a local function, the captured variables could change at any time.
// The cost here is removing and adding to a list. We could find a way to make that less impactful. But lets wait until
// it is impactful.
//Log.Info( $"AddEventListener {attrName}" );
CurrentScope.Element.RemoveEventListener( attrName );
CurrentScope.Element.AddEventListener( attrName, value );
}
/// <summary>
/// Handles @onclick=@( () => await DoSomethingAsync( "boobies" ) )
/// </summary>
public void AddAttributeAction( int sequence, string attrName, Func<Task> value )
{
var e = CurrentScope.Element;
AddAttributeAction( sequence, attrName, () => { _ = value(); e?.StateHasChanged(); } );
}
/// <summary>
/// Handles @onclick=@( ( PanelEvent e ) => DoSomething( e.This, "boobies" ) )
/// </summary>
internal void AddPanelEventAttribute( int sequence, string attrName, Action<PanelEvent> value )
{
// There's no real good way to cache this shit. The function is a local function, the captured variables could change at any time.
// The cost here is removing and adding to a list. We could find a way to make that less impactful. But lets wait until
// it is impactful.
//Log.Info( $"AddEventListener {attrName}" );
CurrentScope.Element.RemoveEventListener( attrName );
CurrentScope.Element.AddEventListener( attrName, value );
}
}