diff --git a/Source/Editor/CustomEditors/Editors/StringEditor.cs b/Source/Editor/CustomEditors/Editors/StringEditor.cs index 9e38fd0ac..9f6b4ce32 100644 --- a/Source/Editor/CustomEditors/Editors/StringEditor.cs +++ b/Source/Editor/CustomEditors/Editors/StringEditor.cs @@ -13,6 +13,9 @@ namespace FlaxEditor.CustomEditors.Editors public sealed class StringEditor : CustomEditor { private TextBoxElement _element; + private string _watermarkText; + private Color _watermarkColor; + private Color _defaultWatermarkColor; /// public override DisplayStyle Style => DisplayStyle.Inline; @@ -21,15 +24,26 @@ namespace FlaxEditor.CustomEditors.Editors public override void Initialize(LayoutElementsContainer layout) { bool isMultiLine = false; + _watermarkText = string.Empty; var attributes = Values.GetAttributes(); var multiLine = attributes?.FirstOrDefault(x => x is MultilineTextAttribute); + var watermarkAttribute = attributes?.FirstOrDefault(x => x is WatermarkAttribute); if (multiLine != null) { isMultiLine = true; } _element = layout.TextBox(isMultiLine); + _defaultWatermarkColor = _element.TextBox.WatermarkTextColor; + if (watermarkAttribute is WatermarkAttribute watermark) + { + _watermarkText = watermark.WatermarkText; + var watermarkColor = watermark.WatermarkColor > 0 ? Color.FromRGBA(watermark.WatermarkColor) : FlaxEngine.GUI.Style.Current.ForegroundDisabled; + _watermarkColor = watermarkColor; + _element.TextBox.WatermarkText = watermark.WatermarkText; + _element.TextBox.WatermarkTextColor = watermarkColor; + } _element.TextBox.EditEnd += () => SetValue(_element.Text); } @@ -41,12 +55,14 @@ namespace FlaxEditor.CustomEditors.Editors if (HasDifferentValues) { _element.TextBox.Text = string.Empty; + _element.TextBox.WatermarkTextColor = _defaultWatermarkColor; _element.TextBox.WatermarkText = "Different values"; } else { _element.TextBox.Text = (string)Values[0]; - _element.TextBox.WatermarkText = string.Empty; + _element.TextBox.WatermarkTextColor = _watermarkColor; + _element.TextBox.WatermarkText = _watermarkText; } } } diff --git a/Source/Engine/Scripting/Attributes/Editor/WatermarkAttribute.cs b/Source/Engine/Scripting/Attributes/Editor/WatermarkAttribute.cs new file mode 100644 index 000000000..73814d11c --- /dev/null +++ b/Source/Engine/Scripting/Attributes/Editor/WatermarkAttribute.cs @@ -0,0 +1,42 @@ +using System; + +namespace FlaxEngine; + +/// +/// Used to add a watermark to a string textbox in the editor field +/// +[Serializable] +[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] +public class WatermarkAttribute : Attribute +{ + /// + /// The watermark text. + /// + public string WatermarkText; + + /// + /// The watermark color. + /// + public uint WatermarkColor; + + /// + /// Initializes a new instance of the class. + /// + /// The watermark text. + public WatermarkAttribute(string text) + { + WatermarkText = text; + WatermarkColor = 0; // default color of watermark in textbox + } + + /// + /// Initializes a new instance of the class. + /// + /// The watermark text. + /// The watermark color. 0 to use default. + public WatermarkAttribute(string text, uint color) + { + WatermarkText = text; + WatermarkColor = color; + } +} diff --git a/Source/Engine/UI/GUI/Common/TextBox.cs b/Source/Engine/UI/GUI/Common/TextBox.cs index 2553dc439..70ef77d68 100644 --- a/Source/Engine/UI/GUI/Common/TextBox.cs +++ b/Source/Engine/UI/GUI/Common/TextBox.cs @@ -213,7 +213,7 @@ namespace FlaxEngine.GUI color *= 0.6f; Render2D.DrawText(font, _text, color, ref _layout, TextMaterial); } - else if (!string.IsNullOrEmpty(_watermarkText) && !IsFocused) + else if (!string.IsNullOrEmpty(_watermarkText)) { Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial); }