Skip to content

Commit

Permalink
Docking: Fix window menu button. Broken by 3f16a52 (#4043)
Browse files Browse the repository at this point in the history
Worked on single-frame click.
  • Loading branch information
ocornut committed Apr 14, 2021
1 parent 3f16a52 commit e5efa01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11638,6 +11638,7 @@ static void ImGui::UpdateViewportsNewFrame()
// - when releasing a moving window we will revert to aiming behind (at viewport_hovered)
// - when we are between viewports, our dragged preview will tend to show in the last viewport _even_ if we don't have tooltips in their viewports (when lacking monitor info)
// - consider the case of holding on a menu item to browse child menus: even thou a mouse button is held, there's no active id because menu items only react on mouse release.
// FIXME-VIEWPORT: This is essentially broken, when ImGuiBackendFlags_HasMouseHoveredViewport is set we want to trust when viewport_hovered==NULL and use that.
const bool is_mouse_dragging_with_an_expected_destination = g.DragDropActive;
if (is_mouse_dragging_with_an_expected_destination && viewport_hovered == NULL)
viewport_hovered = g.MouseLastHoveredViewport;
Expand Down Expand Up @@ -12970,7 +12971,6 @@ bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode*
ImGuiDockNode::ImGuiDockNode(ImGuiID id)
{
ID = id;
WindowMenuButtonId = ImHashStr("#COLLAPSE", 0, ID);
SharedFlags = LocalFlags = ImGuiDockNodeFlags_None;
ParentNode = ChildNodes[0] = ChildNodes[1] = NULL;
TabBar = NULL;
Expand Down Expand Up @@ -13823,8 +13823,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
// Docking/Collapse button
if (has_window_menu_button)
{
IMGUI_TEST_ENGINE_ID_INFO(node->WindowMenuButtonId, ImGuiDataType_String, "#COLLAPSE");
if (CollapseButton(node->WindowMenuButtonId, window_menu_button_pos, node))
if (CollapseButton(host_window->GetID("#COLLAPSE"), window_menu_button_pos, node)) // == DockNodeGetWindowMenuButtonId(node)
OpenPopup("#WindowMenu");
if (IsItemActive())
focus_tab_id = tab_bar->SelectedTabId;
Expand Down
8 changes: 4 additions & 4 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,6 @@ enum ImGuiDockNodeState
struct IMGUI_API ImGuiDockNode
{
ImGuiID ID;
ImGuiID WindowMenuButtonId; // == ImHashStr("#COLLAPSE", ID)
ImGuiDockNodeFlags SharedFlags; // Flags shared by all nodes of a same dockspace hierarchy (inherited from the root node)
ImGuiDockNodeFlags LocalFlags; // Flags specific to this node
ImGuiDockNodeState State;
Expand Down Expand Up @@ -2592,9 +2591,10 @@ namespace ImGui
IMGUI_API bool DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos);
IMGUI_API bool DockNodeBeginAmendTabBar(ImGuiDockNode* node);
IMGUI_API void DockNodeEndAmendTabBar();
inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; }
inline int DockNodeGetDepth(const ImGuiDockNode* node) { int depth = 0; while (node->ParentNode) { node = node->ParentNode; depth++; } return depth; }
inline ImGuiDockNode* GetWindowDockNode() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DockNode; }
inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; }
inline int DockNodeGetDepth(const ImGuiDockNode* node) { int depth = 0; while (node->ParentNode) { node = node->ParentNode; depth++; } return depth; }
inline ImGuiID DockNodeGetWindowMenuButtonId(const ImGuiDockNode* node) { return ImHashStr("#COLLAPSE", 0, node->ID); }
inline ImGuiDockNode* GetWindowDockNode() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DockNode; }
IMGUI_API bool GetWindowAlwaysWantOwnTabBar(ImGuiWindow* window);
IMGUI_API void BeginDocked(ImGuiWindow* window, bool* p_open);
IMGUI_API void BeginDockableDragDropSource(ImGuiWindow* window);
Expand Down

0 comments on commit e5efa01

Please sign in to comment.