Skip to content

Commit 0e0a783

Browse files
committed
Docking: fix undocking from tab-bar by moving mouse horizontally, broken by d705192.
1 parent 5991851 commit 0e0a783

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

imgui_widgets.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -7920,17 +7920,20 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
79207920
else if (held && !tab_appearing && IsMouseDragging(0))
79217921
{
79227922
// Drag and drop: re-order tabs
7923+
int drag_dir = 0;
79237924
float drag_distance_from_edge_x = 0.0f;
79247925
if (!g.DragDropActive && ((tab_bar->Flags & ImGuiTabBarFlags_Reorderable) || (docked_window != NULL)))
79257926
{
79267927
// While moving a tab it will jump on the other side of the mouse, so we also test for MouseDelta.x
79277928
if (g.IO.MouseDelta.x < 0.0f && g.IO.MousePos.x < bb.Min.x)
79287929
{
7930+
drag_dir = -1;
79297931
drag_distance_from_edge_x = bb.Min.x - g.IO.MousePos.x;
79307932
TabBarQueueReorderFromMousePos(tab_bar, tab, g.IO.MousePos);
79317933
}
79327934
else if (g.IO.MouseDelta.x > 0.0f && g.IO.MousePos.x > bb.Max.x)
79337935
{
7936+
drag_dir = +1;
79347937
drag_distance_from_edge_x = g.IO.MousePos.x - bb.Max.x;
79357938
TabBarQueueReorderFromMousePos(tab_bar, tab, g.IO.MousePos);
79367939
}
@@ -7941,20 +7944,18 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
79417944
{
79427945
// We use a variable threshold to distinguish dragging tabs within a tab bar and extracting them out of the tab bar
79437946
bool undocking_tab = (g.DragDropActive && g.DragDropPayload.SourceId == id);
7944-
79457947
if (!undocking_tab) //&& (!g.IO.ConfigDockingWithShift || g.IO.KeyShift)
79467948
{
79477949
float threshold_base = g.FontSize;
7948-
//float threshold_base = g.IO.ConfigDockingWithShift ? g.FontSize * 0.5f : g.FontSize;
79497950
float threshold_x = (threshold_base * 2.2f);
79507951
float threshold_y = (threshold_base * 1.5f) + ImClamp((ImFabs(g.IO.MouseDragMaxDistanceAbs[0].x) - threshold_base * 2.0f) * 0.20f, 0.0f, threshold_base * 4.0f);
79517952
//GetForegroundDrawList()->AddRect(ImVec2(bb.Min.x - threshold_x, bb.Min.y - threshold_y), ImVec2(bb.Max.x + threshold_x, bb.Max.y + threshold_y), IM_COL32_WHITE); // [DEBUG]
79527953

79537954
float distance_from_edge_y = ImMax(bb.Min.y - g.IO.MousePos.y, g.IO.MousePos.y - bb.Max.y);
79547955
if (distance_from_edge_y >= threshold_y)
79557956
undocking_tab = true;
7956-
else if (drag_distance_from_edge_x > threshold_x)
7957-
if ((tab_bar->ReorderRequestOffset < 0 && tab_bar->GetTabOrder(tab) == 0) || (tab_bar->ReorderRequestOffset > 0 && tab_bar->GetTabOrder(tab) == tab_bar->Tabs.Size - 1))
7957+
if (drag_distance_from_edge_x > threshold_x)
7958+
if ((drag_dir < 0 && tab_bar->GetTabOrder(tab) == 0) || (drag_dir > 0 && tab_bar->GetTabOrder(tab) == tab_bar->Tabs.Size - 1))
79587959
undocking_tab = true;
79597960
}
79607961

0 commit comments

Comments
 (0)