From 8a34ae3ece1a0c30a4755e3ebb3eda0901f33973 Mon Sep 17 00:00:00 2001 From: MineBill Date: Sun, 1 Oct 2023 18:41:32 +0300 Subject: [PATCH] Handle double clicking to eliminate perceived lag. --- Source/Engine/UI/GUI/Common/Button.cs | 22 ++++++++++++++++++++++ Source/Engine/UI/GUI/Common/CheckBox.cs | 21 +++++++++++++++++++++ Source/Engine/UI/GUI/Common/Dropdown.cs | 24 ++++++++++++++++++++++++ Source/Engine/UI/GUI/Panels/DropPanel.cs | 23 +++++++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/Source/Engine/UI/GUI/Common/Button.cs b/Source/Engine/UI/GUI/Common/Button.cs index b50f3dd46..02337411b 100644 --- a/Source/Engine/UI/GUI/Common/Button.cs +++ b/Source/Engine/UI/GUI/Common/Button.cs @@ -314,6 +314,28 @@ namespace FlaxEngine.GUI return false; } + /// + public override bool OnMouseDoubleClick(Float2 location, MouseButton button) + { + if (base.OnMouseDoubleClick(location, button)) + return true; + + if (button == MouseButton.Left && _isPressed) + { + OnPressEnd(); + OnClick(); + return true; + } + + if (button == MouseButton.Left && !_isPressed) + { + OnPressBegin(); + return true; + } + + return false; + } + /// public override bool OnTouchDown(Float2 location, int pointerId) { diff --git a/Source/Engine/UI/GUI/Common/CheckBox.cs b/Source/Engine/UI/GUI/Common/CheckBox.cs index 2f1ff42a9..2128c0311 100644 --- a/Source/Engine/UI/GUI/Common/CheckBox.cs +++ b/Source/Engine/UI/GUI/Common/CheckBox.cs @@ -277,6 +277,27 @@ namespace FlaxEngine.GUI return base.OnMouseDown(location, button); } + /// + public override bool OnMouseDoubleClick(Float2 location, MouseButton button) + { + if (button == MouseButton.Left && !_isPressed) + { + OnPressBegin(); + return true; + } + + if (button == MouseButton.Left && _isPressed) + { + OnPressEnd(); + if (_box.Contains(ref location)) + { + OnClick(); + return true; + } + } + return base.OnMouseDoubleClick(location, button); + } + /// public override bool OnMouseUp(Float2 location, MouseButton button) { diff --git a/Source/Engine/UI/GUI/Common/Dropdown.cs b/Source/Engine/UI/GUI/Common/Dropdown.cs index 6ad962d6d..aea4e173a 100644 --- a/Source/Engine/UI/GUI/Common/Dropdown.cs +++ b/Source/Engine/UI/GUI/Common/Dropdown.cs @@ -666,6 +666,30 @@ namespace FlaxEngine.GUI return false; } + /// + public override bool OnMouseDoubleClick(Float2 location, MouseButton button) + { + if (base.OnMouseDoubleClick(location, button)) + return true; + + if (_touchDown && button == MouseButton.Left) + { + _touchDown = false; + ShowPopup(); + return true; + } + + if (button == MouseButton.Left) + { + _touchDown = true; + if (!IsPopupOpened) + Focus(); + return true; + } + + return false; + } + /// public override bool OnTouchDown(Float2 location, int pointerId) { diff --git a/Source/Engine/UI/GUI/Panels/DropPanel.cs b/Source/Engine/UI/GUI/Panels/DropPanel.cs index d650d6205..66e7413eb 100644 --- a/Source/Engine/UI/GUI/Panels/DropPanel.cs +++ b/Source/Engine/UI/GUI/Panels/DropPanel.cs @@ -501,6 +501,29 @@ namespace FlaxEngine.GUI return false; } + /// + public override bool OnMouseDoubleClick(Float2 location, MouseButton button) + { + if (base.OnMouseDoubleClick(location, button)) + return true; + + _mouseOverHeader = HeaderRectangle.Contains(location); + if (button == MouseButton.Left && _mouseOverHeader) + { + _mouseButtonLeftDown = true; + return true; + } + + if (button == MouseButton.Left && _mouseButtonLeftDown) + { + _mouseButtonLeftDown = false; + if (_mouseOverHeader) + Toggle(); + return true; + } + return false; + } + /// public override void OnMouseLeave() {