mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 05:48:07 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
68 lines
1.2 KiB
C#
68 lines
1.2 KiB
C#
using System;
|
|
|
|
namespace Editor.NodeEditor;
|
|
|
|
public static class MenuExtensions
|
|
{
|
|
public static LineEdit AddLineEdit( this Menu menu, string label,
|
|
string value = null, string placeholder = null, bool autoFocus = false,
|
|
Action<string> onChange = null, Action<string> onSubmit = null )
|
|
{
|
|
var w = new Widget( menu );
|
|
w.Layout = Layout.Row();
|
|
w.Layout.Margin = 6;
|
|
w.Layout.Spacing = 4;
|
|
|
|
var lineEdit = new MenuLineEdit( w );
|
|
|
|
lineEdit.PlaceholderText = placeholder ?? $"Enter {label}..";
|
|
lineEdit.Text = value ?? "";
|
|
|
|
if ( onChange is not null )
|
|
{
|
|
lineEdit.TextChanged += onChange;
|
|
}
|
|
|
|
if ( onSubmit is not null )
|
|
{
|
|
var firstTime = true;
|
|
|
|
lineEdit.ReturnPressed += () =>
|
|
{
|
|
if ( !firstTime ) return;
|
|
firstTime = false;
|
|
|
|
onSubmit( lineEdit.Value );
|
|
menu.RootMenu.Close();
|
|
};
|
|
}
|
|
|
|
w.Layout.Add( new Label( $"{label}:", w ) );
|
|
w.Layout.Add( lineEdit );
|
|
|
|
menu.AddWidget( w );
|
|
|
|
if ( autoFocus )
|
|
{
|
|
lineEdit.Focus();
|
|
}
|
|
|
|
return lineEdit;
|
|
}
|
|
}
|
|
|
|
file class MenuLineEdit : LineEdit
|
|
{
|
|
public MenuLineEdit( Widget parent ) : base( parent )
|
|
{
|
|
}
|
|
|
|
// Stops the context menu from closing!!
|
|
protected override void OnMouseReleased( MouseEvent e )
|
|
{
|
|
base.OnMouseReleased( e );
|
|
|
|
e.Accepted = true;
|
|
}
|
|
}
|