Add short delay before auto-selecting editor tab on drag over header

#1934
This commit is contained in:
2023-11-20 11:03:49 +01:00
parent 5573f5bb4a
commit e9a1be481f
+23 -14
View File
@@ -13,6 +13,7 @@ namespace FlaxEditor.GUI.Docking
public class DockPanelProxy : ContainerControl
{
private DockPanel _panel;
private double _dragEnterTime = -1;
/// <summary>
/// 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);
}
/// <inheritdoc />
@@ -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;
/// <inheritdoc />
public override void OnDragLeave()
{
_dragEnterTime = -1;
return DragDropEffect.None;
base.OnDragLeave();
}
/// <inheritdoc />
@@ -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)