Nesting a Begin() inside a BeginTable() reports wrong GetContentRegionAvail().y
Closed this issue · 4 comments
Version/Branch of Dear ImGui:
Version 1.92, Branch: master
Back-ends:
imgui_impl_glfw.cpp + imgui_impl_opengl.cpp
Compiler, OS:
Fedora 42 + clang
Full config/build information:
No response
Details:
Attached video shows the problem, attached code produces the two windows shown in the video.
In the attached code, contents in the function contents I want to display in a regular window, and in a window inside a table. In my original code where I came across this issue the problem showed up as the child window taking up all (wrongly) available space instead of showing a scrollbar, I have left this out of the MVCE, and instead show the problem by looking at GetContentRegionAvail().y.
Displaying contents does not do what I expect in the case where the Begin and contents gets called inside a table.
In the video pay attention to the second GetContentRegionAvail().y.
At the start I show the broken setup, with all the checkboxes enabled for all the needed components for the wrong values to show up. After that I go through all the combinations and even just disabling one part fixes it.
Am I doing something that is not allowed? I expect the contents to work exactly the same in both setups.
Screenshots/Video:
out.mp4
Minimal, Complete and Verifiable Example code:
void contents() {
ImGui::Text("GetContentRegionAvail().x: %f", ImGui::GetContentRegionAvail().x);
ImGui::Text("GetContentRegionAvail().y: %f", ImGui::GetContentRegionAvail().y);
static bool table = true;
ImGui::Checkbox("Table", &table);
if (table) {
if (ImGui::BeginTable("Table", 1)) {
ImGui::TableNextColumn();
ImGui::Text("Table Contents");
}
ImGui::EndTable();
}
ImGui::Text("GetContentRegionAvail().x: %f", ImGui::GetContentRegionAvail().x);
ImGui::Text("GetContentRegionAvail().y: %f", ImGui::GetContentRegionAvail().y);
static bool child = true;
ImGui::Checkbox("Child", &child);
if (child) {
ImGui::BeginChild("Child Window");
ImGui::Text("Child Contents");
ImGui::EndChild();
}
}
void contentsInWindow() {
if (ImGui::Begin("Window")) {
contents();
}
ImGui::End();
}
// execute this in ImGui loop
void runBroken() {
static bool modalTable = true;
ImGui::Checkbox("contensInWindow() inside a table", &modalTable);
if (modalTable) {
if (ImGui::BeginTable("Begin Table", 1)) {
ImGui::TableNextColumn();
contentsInWindow();
ImGui::EndTable();
}
}
else {
contentsInWindow();
}
}Ok I realised this has not actually anything to do with PopupModal I will edit the issue, instead it is an issue with the specific setup of, table -> window -> table -> look at height -> child issue updated
Thank you for the report and useful repro.
I'm currently investigating but I can easily state this is a bug because contentsInWindow() calls ImGui::Begin("Window") and this window in theory should not "inherit" any property from whatever is already in the stack, so the mere fact that this creates a side-effect is itself a bug to investigate.
Confirmed it also fixed the issue in my original code thanks for the very quick fix.