mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
69 lines
1.2 KiB
Plaintext
69 lines
1.2 KiB
Plaintext
@using System
|
|
@namespace Sandbox.UI
|
|
@inherits BaseControl
|
|
@attribute [CustomEditor( typeof(bool) )]
|
|
|
|
<root class="switchcontrol @StateClass">
|
|
|
|
<div class="switch-frame">
|
|
<div class="switch-inner">
|
|
</div>
|
|
</div>
|
|
|
|
@if ( Label != null )
|
|
{
|
|
<div class="switch-label">
|
|
@Label
|
|
</div>
|
|
}
|
|
|
|
</root>
|
|
|
|
@code
|
|
{
|
|
public override bool SupportsMultiEdit => true;
|
|
|
|
public RenderFragment Label { get; set; }
|
|
|
|
public Action<bool> OnValueChanged { get; set; }
|
|
|
|
string StateClass => Value ? "active" : "inactive";
|
|
|
|
bool _value;
|
|
|
|
public bool Value
|
|
{
|
|
get => Property?.As.Bool ?? _value;
|
|
|
|
set
|
|
{
|
|
if ( Property is not null )
|
|
{
|
|
Property.As.Bool = value;
|
|
StateHasChanged();
|
|
return;
|
|
}
|
|
|
|
if (_value == value)
|
|
return;
|
|
|
|
_value = value;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
public SwitchControl()
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnMouseDown( MousePanelEvent e )
|
|
{
|
|
base.OnMouseDown( e );
|
|
|
|
Value = !Value;
|
|
OnValueChanged?.Invoke( Value );
|
|
e.StopPropagation();
|
|
}
|
|
}
|