mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-18 05:17:53 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
65 lines
1.2 KiB
C#
65 lines
1.2 KiB
C#
namespace Sandbox.UI;
|
|
|
|
public partial class TextEntry
|
|
{
|
|
/// <summary>
|
|
/// The <see cref="UI.IconPanel"/> that displays <see cref="Icon"/>
|
|
/// </summary>
|
|
public IconPanel IconPanel { get; protected set; }
|
|
|
|
/// <summary>
|
|
/// If set, will display a <a href="https://fonts.google.com/icons">material icon</a> at the end of the text entry.
|
|
/// </summary>
|
|
[Property]
|
|
public string Icon
|
|
{
|
|
get => IconPanel?.Text;
|
|
set
|
|
{
|
|
if ( string.IsNullOrEmpty( value ) )
|
|
{
|
|
IconPanel?.Delete( true );
|
|
IconPanel = default;
|
|
}
|
|
else
|
|
{
|
|
IconPanel ??= AddChild<IconPanel>( value );
|
|
IconPanel.Text = value;
|
|
}
|
|
|
|
SetClass( "has-icon", IconPanel.IsValid() );
|
|
}
|
|
}
|
|
|
|
bool _hasClearButton;
|
|
|
|
/// <summary>
|
|
/// If true then Icon/IconPanel will be set to a clear button that clears the text when clicked.
|
|
/// </summary>
|
|
public bool HasClearButton
|
|
{
|
|
get => _hasClearButton;
|
|
|
|
set
|
|
{
|
|
if ( _hasClearButton == value ) return;
|
|
_hasClearButton = value;
|
|
|
|
if ( _hasClearButton )
|
|
{
|
|
Icon = "cancel";
|
|
IconPanel.AddClass( "clearbutton" );
|
|
IconPanel.AddEventListener( "onclick", () =>
|
|
{
|
|
Text = string.Empty;
|
|
OnValueChanged();
|
|
} );
|
|
}
|
|
else
|
|
{
|
|
Icon = null;
|
|
}
|
|
}
|
|
}
|
|
}
|