Open nikki93 opened 6 years ago
Hello @nikki93,
Thanks for your report. A fully contained C++ repro would be appreciated, because it takes non trivial amount of time figuring one out.
What I see from your code it that doesn't use Splitter as initially designed: you are ignoring the second part of the Size component size2
(and likewise I am ignoring it in my repro), to the total size become variable. I realize this sort of usage is convenient and has many potential uses so I'd like to support it. Maybe we should be using a cursor/mouse delta in that sort of situation, instead of locating the target position from the absolute cursor/mouse position. There are merit to both approaches in different situations. I'll have to think about it.
Here's a repro for now:
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui_internal.h"
bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f)
{
using namespace ImGui;
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetID("##Splitter");
ImRect bb;
bb.Min = window->DC.CursorPos + (split_vertically ? ImVec2(*size1, 0.0f) : ImVec2(0.0f, *size1));
bb.Max = bb.Min + CalcItemSize(split_vertically ? ImVec2(thickness, splitter_long_axis_size) : ImVec2(splitter_long_axis_size, thickness), 0.0f, 0.0f);
return SplitterBehavior(id, bb, split_vertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, min_size1, min_size2, 0.0f);
}
ImGui::Begin("Issue #1720");
static float size1 = 300;
static float size2 = 300;
Splitter(false, 4.0f, &size1, &size2, 10.0f, 10.0f);
ImGui::BeginChild("top", ImVec2(-1, size1), true, ImGuiWindowFlags_NoScrollWithMouse);
ImGui::Text("Hello from top");
ImGui::EndChild();
ImGui::BeginChild("bottom", ImVec2(-1, 300), true, ImGuiWindowFlags_NoScrollWithMouse);
ImGui::Text("Hello from bottom");
ImGui::EndChild();
ImGui::End();
That’s fair, will do a cpp repro! And yeah that’s a good point I could work around by actually using size2 as zero and adding a dummy container at the end of the containing scroll that is size2 size, until you release, at which point we delete it. That way the dummy expands to prevent scrolling backwards.
I'm using
SplitterBehavior(...)
to have resizable child windows inside a scrolling region in a containing window. This works pretty well, except for one snag: when you resize down and the scrollbar is at the bottom of the container window, the content size of the container reduces and so everything moves down, causing more resizing, eventually causing the resizable child to feedback to the minimum size. The main way around this I can think of is to add dummy space at the bottom of the content view equal to the lost height while resizing, and once done the dummy is removed to reset the layout. Wondering if that is the best approach / if you have any tips.Here's a video of this behavior: https://www.youtube.com/watch?v=rK4km7dERWc
For reference, here's the wrapper around
SplitterBehavior(...)
as suggested in https://github.com/ocornut/imgui/issues/319#issuecomment-345795629:I create a utility
ui.beginChildResizable(...)
in Lua as follows (.beginChild(...)
,.endChild()
,.spacing()
are properly wrapped already):Which is used, for example, as: