Nodes/Core/Display/DisplayPanel.razor
@namespace Nodebox
<root>
<label @ref="Label">@Text</label>
@if (Type == typeof(Color))
{
<div class="color">
<div class="colorstrip" style="background-color: @(((Color)Value).Rgba)"></div>
</div>
}
</root>
@code
{
[Property] public object Value { get; set; } = null;
public Type Type => Value?.GetType();
[Property, TextArea] public string Text => Value?.ToString() ?? "null";
[Property] public bool FitText { get; set; } = false;
[Property] public float? FontSizeOverride { get; set; } = null;
public Panel Label { get; set; }
protected override void OnAfterTreeRender(bool firstTime) {
if (FontSizeOverride.HasValue) {
Label.Style.FontSize = FontSizeOverride.Value;
return;
}
var length = Text.Length;
Label.Style.FontSize = 18f * 12 / Math.Max(length, 12);
}
protected override int BuildHash() => System.HashCode.Combine( Value );
}