Skip to content

Commit

Permalink
Docking: comments, clairfy why we store style override on dragged win…
Browse files Browse the repository at this point in the history
…dows. Clarify why we don't need to store alpha. (#7535, #2771)

Amend ebbb98d
  • Loading branch information
ocornut committed Apr 30, 2024
1 parent 5717f0a commit 9d6818d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19031,6 +19031,13 @@ static ImGuiDockNode* ImGui::DockContextBindNodeToWindow(ImGuiContext* ctx, ImGu
return node;
}

static void StoreDockStyleForWindow(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++)
window->DockStyle.Colors[color_n] = ImGui::ColorConvertFloat4ToU32(g.Style.Colors[GWindowDockStyleColors[color_n]]);
}

void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
{
ImGuiContext& g = *GImGui;
Expand Down Expand Up @@ -19094,8 +19101,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
}

// Store style overrides
for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++)
window->DockStyle.Colors[color_n] = ColorConvertFloat4ToU32(g.Style.Colors[GWindowDockStyleColors[color_n]]);
StoreDockStyleForWindow(window);

// Fast path return. It is common for windows to hold on a persistent DockId but be the only visible window,
// and never create neither a host window neither a tab bar.
Expand Down Expand Up @@ -19185,10 +19191,7 @@ void ImGui::BeginDockableDragDropSource(ImGuiWindow* window)
{
SetDragDropPayload(IMGUI_PAYLOAD_TYPE_WINDOW, &window, sizeof(window));
EndDragDropSource();

// Store style overrides
for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++)
window->DockStyle.Colors[color_n] = ColorConvertFloat4ToU32(g.Style.Colors[GWindowDockStyleColors[color_n]]);
StoreDockStyleForWindow(window); // Store style overrides while dragging (even when not docked) because docking preview may need it.
}
}

Expand Down
2 changes: 2 additions & 0 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ struct ImGuiTableColumnsSettings; // Storage for a column .ini settings
struct ImGuiTypingSelectState; // Storage for GetTypingSelectRequest()
struct ImGuiTypingSelectRequest; // Storage for GetTypingSelectRequest() (aimed to be public)
struct ImGuiWindow; // Storage for one window
struct ImGuiWindowDockStyle; // Storage for window-style data which needs to be stored for docking purpose
struct ImGuiWindowTempData; // Temporary storage for one window (that's the data which in theory we could ditch at the end of the frame, in practice we currently keep it for each window)
struct ImGuiWindowSettings; // Storage for a window .ini settings (we keep one of those even if the actual window wasn't instanced during this session)

Expand Down Expand Up @@ -1872,6 +1873,7 @@ enum ImGuiWindowDockStyleCol
ImGuiWindowDockStyleCol_COUNT
};

// We don't store style.Alpha: dock_node->LastBgColor embeds it and otherwise it would only affect the docking tab, which intuitively I would say we don't want to.
struct ImGuiWindowDockStyle
{
ImU32 Colors[ImGuiWindowDockStyleCol_COUNT];
Expand Down

0 comments on commit 9d6818d

Please sign in to comment.