ocornut / imgui

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

Double-click to move splitter to middle #6097

Open Grieverheart opened 1 year ago

Grieverheart commented 1 year ago

Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp Compiler: Apple clang version 12.0.5 (clang-1205.0.22.11) Operating System: MacOS

My Issue/Question:

I would like to be able to double click the dock splitter to move it to the middle. I tried implementing it in SplitterBehavior, but I am a bit confused; I added ImGuiButtonFlags_PressedOnDoubleClick to the flags in ButtonBehavior so that it reacts to double clicks, but then when calculating the mouse delta in the code:

ImVec2 mouse_delta_2d = g.IO.MousePos - g.ActiveIdClickOffset - bb_interact.Min;

on the next frame it becomes large since bb_interact.Min was modified, but the g.IO.MousePos is the same, while following the pressed result from ButtonBehavior, we receive a held event. I also tried disabling resizing by dragging altogether, but somehow, if I condition on pressed, the splitter moves for one frame to the correct position, and then goes back, so this needs to be done over 2 frames?

Anyway, if you could either add this behavior or give me some hints on how to implement it myself, I would be grateful.

Grieverheart commented 1 year ago

I was finally able to implement a solution by modifying DockNodeTreeUpdateSplitter and SplitterBehavior slightly. Let me know if you think it's useful to make a pull request.