mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
Add ColorControl
This commit is contained in:
committed by
Matt Stevens
parent
1595f035d2
commit
ab1ae86f88
38
game/addons/base/code/UI/Controls/ColorControl.cs
Normal file
38
game/addons/base/code/UI/Controls/ColorControl.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
namespace Sandbox.UI;
|
||||
|
||||
/// <summary>
|
||||
/// A control for editing Color properties. Displays a text entry that can be edited, and a color swatch which pops up a mixer.
|
||||
/// </summary>
|
||||
[CustomEditor( typeof( Color ) )]
|
||||
public partial class ColorControl : BaseControl
|
||||
{
|
||||
readonly TextEntry _textEntry;
|
||||
readonly Panel _colorSwatch;
|
||||
|
||||
public ColorControl()
|
||||
{
|
||||
_colorSwatch = AddChild<Panel>( "colorswatch" );
|
||||
|
||||
_textEntry = AddChild<TextEntry>( "textentry" );
|
||||
_textEntry.OnTextEdited = OnTextEntryChanged;
|
||||
}
|
||||
|
||||
public override void Rebuild()
|
||||
{
|
||||
if ( Property == null ) return;
|
||||
|
||||
_textEntry.Value = Property.GetValue<Color>().Hex;
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
base.Tick();
|
||||
|
||||
_colorSwatch.Style.BackgroundColor = Property.GetValue<Color>();
|
||||
}
|
||||
|
||||
void OnTextEntryChanged( string value )
|
||||
{
|
||||
Property.SetValue( value );
|
||||
}
|
||||
}
|
||||
43
game/addons/base/code/UI/Controls/ColorControl.cs.scss
Normal file
43
game/addons/base/code/UI/Controls/ColorControl.cs.scss
Normal file
@@ -0,0 +1,43 @@
|
||||
ColorControl
|
||||
{
|
||||
gap: 0.5rem;
|
||||
flex-grow: 1;
|
||||
pointer-events: all;
|
||||
background-color: #000a;
|
||||
border-radius: 4px;
|
||||
padding: 2px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
ColorControl TextEntry
|
||||
{
|
||||
flex-grow: 1;
|
||||
flex-shrink: 0;
|
||||
color: #aaa;
|
||||
font-size: 1.2rem;
|
||||
|
||||
&:hover, &:focus
|
||||
{
|
||||
color: #ddd;
|
||||
|
||||
.icon
|
||||
{
|
||||
color: #3af;
|
||||
}
|
||||
}
|
||||
|
||||
&:active
|
||||
{
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
|
||||
ColorControl > .colorswatch
|
||||
{
|
||||
aspect-ratio: 1;
|
||||
border-radius: 4px;
|
||||
height: 100%;
|
||||
flex-shrink: 0;
|
||||
cursor: pointer;
|
||||
border: 2px solid #000;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Sandbox.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Like TextEntry, except just for numbers
|
||||
/// A control for editing enum properties. Can either display a dropdown or a button group depending on the number of options.
|
||||
/// </summary>
|
||||
[CustomEditor( typeof( Enum ) )]
|
||||
public partial class EnumControl : BaseControl
|
||||
|
||||
Reference in New Issue
Block a user