ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.47k stars 10.14k forks source link

How can I check if an windows is inside the dock? #6274

Closed Ikamyshev closed 1 year ago

Ikamyshev commented 1 year ago

I need different behavior for docked and separated windows.

ocornut commented 1 year ago

Why ?

Ikamyshev commented 1 year ago

I create primitive WYSIWYG-editor. Editor containing widget panel and designer panel. For all elements i use dragndrop functions and it works well. But I want to be able to create frames by docking windows. When I click the frame button in the widget panel, a window is created which I drag onto the designer window. I want to remove a draggable window if it happens to be outside the designer. I hope I wrote clearly.

Ikamyshev commented 1 year ago

ImGui::Begin(); if (_isNew) { ImGuiContext& g = GImGui; ImGuiWindow window = g.CurrentWindow; ImGuiDockNode* dock_node = window->DockNode; if (ImGui::BeginPopupContextItem()) // <-- This is using IsItemHovered() { ImGui::EndPopup(); } if (ImGui::IsItemHovered()) { if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { ImGui::StartMouseMovingWindowOrNode(window, dock_node, true); } if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { std::cout << "parent window: " << window->ParentWindow << std::endl; _isNew = false; } } } ImGui::End();

Ikamyshev commented 1 year ago

if you check the value of the parent window, then it is always equal to zero.

Ikamyshev commented 1 year ago

I figured out the problem. When an item is docked, it moves out of the mouse cursor and therefore IsItemHovered did not fire. I apologize for the inconvenience.