Files
sbox-public/game/addons/base/code/UI/Controls/TextEntry.Icon.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

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;
}
}
}
}