diff --git a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs
index b19d7a9f1..9c268c033 100644
--- a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs
+++ b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs
@@ -40,6 +40,7 @@ namespace FlaxEditor.GUI.Dialogs
private bool _disableEvents;
private bool _useDynamicEditing;
private bool _activeEyedropper;
+ private bool _canPassLastChangeEvent = true;
private ColorValueBox.ColorPickerEvent _onChanged;
private ColorValueBox.ColorPickerClosedEvent _onClosed;
@@ -380,7 +381,7 @@ namespace FlaxEditor.GUI.Dialogs
{
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));
Render2D.FillRectangle(rect, Color.Gray);
@@ -395,7 +396,7 @@ namespace FlaxEditor.GUI.Dialogs
{
// Auto cancel on lost focus
#if !PLATFORM_LINUX
- ((WindowRootControl)Root).Window.LostFocus += OnCancel;
+ ((WindowRootControl)Root).Window.LostFocus += OnWindowLostFocus;
#endif
base.OnShow();
@@ -504,7 +505,7 @@ namespace FlaxEditor.GUI.Dialogs
BackgroundColorHighlighted = savedColor,
BackgroundColorSelected = savedColor.RGBMultiplied(0.8f),
};
- savedColorButton.ButtonClicked += (b) => OnSavedColorButtonClicked(b);
+ savedColorButton.ButtonClicked += OnSavedColorButtonClicked;
_savedColorButtons.Add(savedColorButton);
}
if (_savedColors.Count < 8)
@@ -516,11 +517,24 @@ namespace FlaxEditor.GUI.Dialogs
TooltipText = "Save Color.",
Tag = null,
};
- savedColorButton.ButtonClicked += (b) => OnSavedColorButtonClicked(b);
+ savedColorButton.ButtonClicked += OnSavedColorButtonClicked;
_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();
+ }
+
///
public override void OnSubmit()
{
@@ -545,8 +559,9 @@ namespace FlaxEditor.GUI.Dialogs
_disableEvents = true;
// Restore color if modified
- if (_useDynamicEditing && _initialValue != _value)
+ if (_useDynamicEditing && _initialValue != _value && _canPassLastChangeEvent)
{
+ _canPassLastChangeEvent = false;
_onChanged?.Invoke(_initialValue, false);
}
diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs
index 360d1a7ed..7dec0f5cc 100644
--- a/Source/Editor/Options/InterfaceOptions.cs
+++ b/Source/Editor/Options/InterfaceOptions.cs
@@ -189,6 +189,13 @@ namespace FlaxEditor.Options
[EditorDisplay("Interface"), EditorOrder(280), Tooltip("Editor content window orientation.")]
public FlaxEngine.GUI.Orientation ContentWindowOrientation { get; set; } = FlaxEngine.GUI.Orientation.Horizontal;
+ ///
+ /// If checked, color pickers will always modify the color unless 'Cancel' if pressed, otherwise color won't change unless 'Ok' is pressed.
+ ///
+ [DefaultValue(true)]
+ [EditorDisplay("Interface"), EditorOrder(290)]
+ public bool AutoAcceptColorPickerChange { get; set; } = true;
+
///
/// Gets or sets the formatting option for numeric values in the editor.
///