How do I get the *actual* content height. (Trying to make a footer)

I’m trying to make a window with a fixed header/footer, but the none of the “get content size” functions give me the right numbers. Width is correct per the demo example, but height is off by a bit. I assume there’s a number I should be subtracting but I don’t know what it would be. I also tried zeroing the window padding but that also didn’t work. Here’s my code:

    ImGui::SetNextWindowSize(ImVec2(400,600)); //Arbitrary size
    ImGui::Begin("HeaderFooterWindow",nullptr);
    ImVec2 cr = ImGui::GetWindowContentRegionMax(); //I tried every nearby function too.
    
    ImGui::BeginChild("TopBar", ImVec2(cr.x,100), false, 0);
    ImGui::Text("Header");
    ImGui::EndChild();

    ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(255, 0, 0, 100)); //For visibility
    ImGui::BeginChild("Content", ImVec2(cr.x,cr.y-200), false, 0);
    ImGui::Text("Content");
    ImGui::EndChild();
    ImGui::PopStyleColor();

    ImGui::BeginChild("BottomBar", ImVec2(cr.x,100), false, 0);
    ImGui::Text("Footer");
    ImGui::EndChild();
    ImGui::End();

If you are not sure what a function does, use a ImGui::Text() statement to display its value!

You probably want to use GetContentRegionAvail(), however you can simply use the sizing facility of BeginChild() more simply:

Something like

    ImGui::BeginChild("TopBar", ImVec2(0, 100), false, 0); // Use avail width, use 100 for height
    ImGui::Text("Header");
    ImGui::EndChild();

    ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(255, 0, 0, 100)); //For visibility
    ImGui::BeginChild("Content", ImVec2(0, -(100 + style.ItemSpacing.y)), false, 0); // Leave ~100
    ImGui::Text("Content");
    ImGui::EndChild();
    ImGui::PopStyleColor();

    ImGui::BeginChild("BottomBar", ImVec2(0,0), false, 0); // Use avail width/height
    ImGui::Text("Footer");
    ImGui::EndChild();
    ImGui::End();

You may also look at Splitter · Issue #319 · ocornut/imgui · GitHub
Or simply the docking branch which is heading toward making this easier.

Thanks. It was the item spacing was what was throwing off the calculation. Zeroing the padding didn’t fix it because it’s inside the width/height.

I reread the ImGuiStyle definition and it’s not clear how all the paddings and spacings stack. I looked for the imgui version the CSS Box Model diagram but I couldn’t find one.

The docking/splitter branch looks cool!

I agree it’s not all obvious, but again, the easiest way for anything within ImGui ecosystem is to live interact with this by opening the style editor and tweaking the values.