Merge branch 'colorPickerAlwaysChangesColor' of https://github.com/Arcnor/FlaxEngine into Arcnor-colorPickerAlwaysChangesColor

# Conflicts:
#	Source/Editor/Options/InterfaceOptions.cs
This commit is contained in:
Wojtek Figat
2024-07-25 10:06:05 +02:00
2 changed files with 27 additions and 5 deletions

View File

@@ -40,6 +40,7 @@ namespace FlaxEditor.GUI.Dialogs
private bool _disableEvents; private bool _disableEvents;
private bool _useDynamicEditing; private bool _useDynamicEditing;
private bool _activeEyedropper; private bool _activeEyedropper;
private bool _canPassLastChangeEvent = true;
private ColorValueBox.ColorPickerEvent _onChanged; private ColorValueBox.ColorPickerEvent _onChanged;
private ColorValueBox.ColorPickerClosedEvent _onClosed; private ColorValueBox.ColorPickerClosedEvent _onClosed;
@@ -380,7 +381,7 @@ namespace FlaxEditor.GUI.Dialogs
{ {
for (int j = 0; j < numVer; j++) for (int j = 0; j < numVer; j++)
{ {
if ((i + j) % 2 == 0 ) if ((i + j) % 2 == 0)
{ {
var rect = new Rectangle(newRect.X + smallRectSize * i, newRect.Y + smallRectSize * j, new Float2(smallRectSize)); var rect = new Rectangle(newRect.X + smallRectSize * i, newRect.Y + smallRectSize * j, new Float2(smallRectSize));
Render2D.FillRectangle(rect, Color.Gray); Render2D.FillRectangle(rect, Color.Gray);
@@ -395,7 +396,7 @@ namespace FlaxEditor.GUI.Dialogs
{ {
// Auto cancel on lost focus // Auto cancel on lost focus
#if !PLATFORM_LINUX #if !PLATFORM_LINUX
((WindowRootControl)Root).Window.LostFocus += OnCancel; ((WindowRootControl)Root).Window.LostFocus += OnWindowLostFocus;
#endif #endif
base.OnShow(); base.OnShow();
@@ -504,7 +505,7 @@ namespace FlaxEditor.GUI.Dialogs
BackgroundColorHighlighted = savedColor, BackgroundColorHighlighted = savedColor,
BackgroundColorSelected = savedColor.RGBMultiplied(0.8f), BackgroundColorSelected = savedColor.RGBMultiplied(0.8f),
}; };
savedColorButton.ButtonClicked += (b) => OnSavedColorButtonClicked(b); savedColorButton.ButtonClicked += OnSavedColorButtonClicked;
_savedColorButtons.Add(savedColorButton); _savedColorButtons.Add(savedColorButton);
} }
if (_savedColors.Count < 8) if (_savedColors.Count < 8)
@@ -516,11 +517,24 @@ namespace FlaxEditor.GUI.Dialogs
TooltipText = "Save Color.", TooltipText = "Save Color.",
Tag = null, Tag = null,
}; };
savedColorButton.ButtonClicked += (b) => OnSavedColorButtonClicked(b); savedColorButton.ButtonClicked += OnSavedColorButtonClicked;
_savedColorButtons.Add(savedColorButton); _savedColorButtons.Add(savedColorButton);
} }
} }
private void OnWindowLostFocus()
{
// Auto apply color on defocus
var autoAcceptColorPickerChange = Editor.Instance.Options.Options.Interface.AutoAcceptColorPickerChange;
if (_useDynamicEditing && _initialValue != _value && _canPassLastChangeEvent && autoAcceptColorPickerChange)
{
_canPassLastChangeEvent = false;
_onChanged?.Invoke(_value, false);
}
OnCancel();
}
/// <inheritdoc /> /// <inheritdoc />
public override void OnSubmit() public override void OnSubmit()
{ {
@@ -545,8 +559,9 @@ namespace FlaxEditor.GUI.Dialogs
_disableEvents = true; _disableEvents = true;
// Restore color if modified // Restore color if modified
if (_useDynamicEditing && _initialValue != _value) if (_useDynamicEditing && _initialValue != _value && _canPassLastChangeEvent)
{ {
_canPassLastChangeEvent = false;
_onChanged?.Invoke(_initialValue, false); _onChanged?.Invoke(_initialValue, false);
} }

View File

@@ -189,6 +189,13 @@ namespace FlaxEditor.Options
[EditorDisplay("Interface"), EditorOrder(280), Tooltip("Editor content window orientation.")] [EditorDisplay("Interface"), EditorOrder(280), Tooltip("Editor content window orientation.")]
public FlaxEngine.GUI.Orientation ContentWindowOrientation { get; set; } = FlaxEngine.GUI.Orientation.Horizontal; public FlaxEngine.GUI.Orientation ContentWindowOrientation { get; set; } = FlaxEngine.GUI.Orientation.Horizontal;
/// <summary>
/// If checked, color pickers will always modify the color unless 'Cancel' if pressed, otherwise color won't change unless 'Ok' is pressed.
/// </summary>
[DefaultValue(true)]
[EditorDisplay("Interface"), EditorOrder(290)]
public bool AutoAcceptColorPickerChange { get; set; } = true;
/// <summary> /// <summary>
/// Gets or sets the formatting option for numeric values in the editor. /// Gets or sets the formatting option for numeric values in the editor.
/// </summary> /// </summary>