From 49beb2c7bab76d75a993249182d9380d257c35ed Mon Sep 17 00:00:00 2001 From: nothingTVatYT <34131388+nothingTVatYT@users.noreply.github.com> Date: Tue, 30 Jan 2024 08:52:27 +0100 Subject: [PATCH] add toggle formatting --- .../CustomEditors/Editors/DoubleEditor.cs | 14 +++++++++++ .../CustomEditors/Editors/FloatEditor.cs | 15 ++++++++++++ .../CustomEditors/Editors/Vector3Editor.cs | 24 +++++++++++++++++++ Source/Editor/GUI/Input/FloatValueBox.cs | 10 +++++--- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/DoubleEditor.cs b/Source/Editor/CustomEditors/Editors/DoubleEditor.cs index a428fd448..97c0d4782 100644 --- a/Source/Editor/CustomEditors/Editors/DoubleEditor.cs +++ b/Source/Editor/CustomEditors/Editors/DoubleEditor.cs @@ -40,6 +40,13 @@ namespace FlaxEditor.CustomEditors.Editors doubleValue.ValueBox.ValueChanged += OnValueChanged; doubleValue.ValueBox.SlidingEnd += ClearToken; _element = doubleValue; + LinkedLabel.SetupContextMenu += (label, menu, editor) => + { + menu.AddSeparator(); + var mb = menu.AddButton("Show formatted", bt => { doubleValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None);}); + mb.AutoCheck = true; + mb.Checked = doubleValue.ValueBox.Category != Utils.ValueCategory.None; + }; return; } } @@ -50,6 +57,13 @@ namespace FlaxEditor.CustomEditors.Editors doubleValue.SetCategory(valueCategory); doubleValue.ValueBox.ValueChanged += OnValueChanged; doubleValue.ValueBox.SlidingEnd += ClearToken; + LinkedLabel.SetupContextMenu += (label, menu, editor) => + { + menu.AddSeparator(); + var mb = menu.AddButton("Show formatted", bt => { doubleValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None);}); + mb.AutoCheck = true; + mb.Checked = doubleValue.ValueBox.Category != Utils.ValueCategory.None; + }; _element = doubleValue; } } diff --git a/Source/Editor/CustomEditors/Editors/FloatEditor.cs b/Source/Editor/CustomEditors/Editors/FloatEditor.cs index c739269ab..88777474b 100644 --- a/Source/Editor/CustomEditors/Editors/FloatEditor.cs +++ b/Source/Editor/CustomEditors/Editors/FloatEditor.cs @@ -3,6 +3,7 @@ using System; using System.Linq; using FlaxEditor.CustomEditors.Elements; +using FlaxEditor.GUI.ContextMenu; using FlaxEngine; using Utils = FlaxEngine.Utils; @@ -56,6 +57,13 @@ namespace FlaxEditor.CustomEditors.Editors floatValue.ValueBox.ValueChanged += OnValueChanged; floatValue.ValueBox.SlidingEnd += ClearToken; _element = floatValue; + LinkedLabel.SetupContextMenu += (label, menu, editor) => + { + menu.AddSeparator(); + var mb = menu.AddButton("Show formatted", bt => { floatValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None);}); + mb.AutoCheck = true; + mb.Checked = floatValue.ValueBox.Category != Utils.ValueCategory.None; + }; return; } } @@ -67,6 +75,13 @@ namespace FlaxEditor.CustomEditors.Editors floatValue.ValueBox.ValueChanged += OnValueChanged; floatValue.ValueBox.SlidingEnd += ClearToken; _element = floatValue; + LinkedLabel.SetupContextMenu += (label, menu, editor) => + { + menu.AddSeparator(); + var mb = menu.AddButton("Show formatted", bt => { floatValue.SetCategory(bt.Checked ? valueCategory : Utils.ValueCategory.None);}); + mb.AutoCheck = true; + mb.Checked = floatValue.ValueBox.Category != Utils.ValueCategory.None; + }; } } diff --git a/Source/Editor/CustomEditors/Editors/Vector3Editor.cs b/Source/Editor/CustomEditors/Editors/Vector3Editor.cs index fe3ff2b74..c01a841c2 100644 --- a/Source/Editor/CustomEditors/Editors/Vector3Editor.cs +++ b/Source/Editor/CustomEditors/Editors/Vector3Editor.cs @@ -97,6 +97,18 @@ namespace FlaxEditor.CustomEditors.Editors ZElement.SetCategory(category); ZElement.ValueBox.ValueChanged += OnZValueChanged; ZElement.ValueBox.SlidingEnd += ClearToken; + LinkedLabel.SetupContextMenu += (label, menu, editor) => + { + menu.AddSeparator(); + var mb = menu.AddButton("Show formatted", bt => + { + XElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None); + YElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None); + ZElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None); + }); + mb.AutoCheck = true; + mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None; + }; } private void OnXValueChanged() @@ -283,6 +295,18 @@ namespace FlaxEditor.CustomEditors.Editors ZElement.SetCategory(category); ZElement.ValueBox.ValueChanged += OnValueChanged; ZElement.ValueBox.SlidingEnd += ClearToken; + LinkedLabel.SetupContextMenu += (label, menu, editor) => + { + menu.AddSeparator(); + var mb = menu.AddButton("Show formatted", bt => + { + XElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None); + YElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None); + ZElement.SetCategory(bt.Checked ? category : Utils.ValueCategory.None); + }); + mb.AutoCheck = true; + mb.Checked = XElement.ValueBox.Category != Utils.ValueCategory.None; + }; } private void OnValueChanged() diff --git a/Source/Editor/GUI/Input/FloatValueBox.cs b/Source/Editor/GUI/Input/FloatValueBox.cs index 2fccba8e8..5495fe534 100644 --- a/Source/Editor/GUI/Input/FloatValueBox.cs +++ b/Source/Editor/GUI/Input/FloatValueBox.cs @@ -1,7 +1,6 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; -using System.Globalization; using FlaxEditor.Utilities; using FlaxEngine; using Utils = FlaxEngine.Utils; @@ -138,10 +137,15 @@ namespace FlaxEditor.GUI.Input Value = Value; } + private Utils.ValueCategory _category = Utils.ValueCategory.None; + /// - /// Get or set the category of the value. This can either be none for just a number, a distance or an angle. + /// Get or set the category of the value. This can be none for just a number or a more specific one like a distance. /// - public Utils.ValueCategory Category = Utils.ValueCategory.None; + public Utils.ValueCategory Category { + get => _category; + set { _category = value; UpdateText(); } + } /// protected sealed override void UpdateText()