From e9a1be481fb0c550a139400443192a0d45a7c398 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 20 Nov 2023 11:03:49 +0100 Subject: [PATCH] Add short delay before auto-selecting editor tab on drag over header #1934 --- Source/Editor/GUI/Docking/DockPanelProxy.cs | 37 +++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/Source/Editor/GUI/Docking/DockPanelProxy.cs b/Source/Editor/GUI/Docking/DockPanelProxy.cs index 15ff2cad0..e6e57de8e 100644 --- a/Source/Editor/GUI/Docking/DockPanelProxy.cs +++ b/Source/Editor/GUI/Docking/DockPanelProxy.cs @@ -13,6 +13,7 @@ namespace FlaxEditor.GUI.Docking public class DockPanelProxy : ContainerControl { private DockPanel _panel; + private double _dragEnterTime = -1; /// /// The is mouse down flag (left button). @@ -256,8 +257,8 @@ namespace FlaxEditor.GUI.Docking else { tabColor = style.BackgroundHighlighted; - Render2D.DrawLine(tabRect.BottomLeft - new Float2(0 , 1), tabRect.UpperLeft, tabColor); - Render2D.DrawLine(tabRect.BottomRight - new Float2(0 , 1), tabRect.UpperRight, tabColor); + Render2D.DrawLine(tabRect.BottomLeft - new Float2(0, 1), tabRect.UpperLeft, tabColor); + Render2D.DrawLine(tabRect.BottomRight - new Float2(0, 1), tabRect.UpperRight, tabColor); } if (tab.Icon.IsValid) @@ -477,11 +478,7 @@ namespace FlaxEditor.GUI.Docking var result = base.OnDragEnter(ref location, data); if (result != DragDropEffect.None) return result; - - if (TrySelectTabUnderLocation(ref location)) - return DragDropEffect.Move; - - return DragDropEffect.None; + return TrySelectTabUnderLocation(ref location); } /// @@ -490,11 +487,15 @@ namespace FlaxEditor.GUI.Docking var result = base.OnDragMove(ref location, data); if (result != DragDropEffect.None) return result; + return TrySelectTabUnderLocation(ref location); + } - if (TrySelectTabUnderLocation(ref location)) - return DragDropEffect.Move; + /// + public override void OnDragLeave() + { + _dragEnterTime = -1; - return DragDropEffect.None; + base.OnDragLeave(); } /// @@ -503,17 +504,25 @@ namespace FlaxEditor.GUI.Docking rect = new Rectangle(0, DockPanel.DefaultHeaderHeight, Width, Height - DockPanel.DefaultHeaderHeight); } - private bool TrySelectTabUnderLocation(ref Float2 location) + private DragDropEffect TrySelectTabUnderLocation(ref Float2 location) { var tab = GetTabAtPos(location, out _); if (tab != null) { + // Auto-select tab only if drag takes some time + var time = Platform.TimeSeconds; + if (_dragEnterTime < 0) + _dragEnterTime = time; + if (time - _dragEnterTime < 0.3f) + return DragDropEffect.Link; + _dragEnterTime = -1; + _panel.SelectTab(tab); Update(0); // Fake update - return true; + return DragDropEffect.Move; } - - return false; + _dragEnterTime = -1; + return DragDropEffect.None; } private void ShowContextMenu(DockWindow tab, ref Float2 location)