I'm working on simplifying Stack Layout and to relay more on ImGui own ImGuiLayoutType_Horizontal.
I stumbled on an issue where tables do honor window LayoutType effectively allowing widgets in cells flip direction.
With this patch table do switch LayoutType to ImGuiLayoutType_Vertical in BeginTableEx() and restore previous one in EndTable().
This does fix tables placed in horizontal layouts, stack layouts do work with those more frequently than ImGui own widgets.
| Before | After |
|---|---|
When ScrollY is used, table do create child window which does have ImGuiLayoutType_Vertical set, so there is no issue here.
Repro (requires imgui_internal.h):
ImGui::Begin("Tables in a horizontal layout");
ImGuiWindow* window = ImGui::GetCurrentWindow();
window->DC.LayoutType = ImGuiLayoutType_Horizontal; // As BeginMenuBar() and BeginComboPreview() do
for (int n = 0; n < 2; n++)
{
ImGui::Text(n == 0 ? "Default:" : "ScrollY:");
if (ImGui::BeginTable(n == 0 ? "table1" : "table2", 2, ImGuiTableFlags_Borders | (n == 1 ? ImGuiTableFlags_ScrollY : 0), ImVec2(120.0f, 60.0f)))
{
ImGui::TableNextColumn(); ImGui::Text("A1"); ImGui::Text("A2");
ImGui::TableNextColumn(); ImGui::Text("B1"); ImGui::Text("B2");
ImGui::EndTable();
}
}
window->DC.LayoutType = ImGuiLayoutType_Vertical;
ImGui::End();Only users or ImGuiLayoutType_Horizontal in ImGui (afaik) is menu bar and combo preview.
Menu Bar
Menu Bar looks 'wrong' on first sight, because widgets in table do stack vertically. I think it is correct behavior anyway and clipping is just an artifacts of menu bar having a fixed height.
| Before | After |
|---|---|
Repro:
ImGui::Begin("Table in a menu bar", NULL, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginTable("table", 2, ImGuiTableFlags_Borders))
{
ImGui::TableNextColumn(); ImGui::Text("A1"); ImGui::Text("A2");
ImGui::TableNextColumn(); ImGui::Text("B1"); ImGui::Text("B2");
ImGui::EndTable();
}
ImGui::EndMenuBar();
}
ImGui::End();Note, that Text("A1\nA2") in menu bar also clip A2. So behavior seem to be consistent.
Combo Preview
Combo preview also use ImGuiLayoutType_Horizontal. Have same story as menu bar, also do clipping.
| Before | After |
|---|---|
Repro:
ImGui::Begin("Table in a combo preview");
if (ImGui::BeginCombo("Combo", NULL))
{
ImGui::Selectable("Item");
ImGui::EndCombo();
}
if (ImGui::BeginComboPreview())
{
if (ImGui::BeginTable("table", 2, ImGuiTableFlags_Borders))
{
ImGui::TableNextColumn(); ImGui::Text("A1"); ImGui::Text("A2");
ImGui::TableNextColumn(); ImGui::Text("B1"); ImGui::Text("B2");
ImGui::EndTable();
}
ImGui::EndComboPreview();
}
ImGui::End();