mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-30 18:29:04 +08:00
Tables: fixed matching width of synchronized tables when only some (not all) instances have a vertical scrollbar. (#5920)
This commit is contained in:
parent
0949acb6e6
commit
317b33d647
@ -53,6 +53,8 @@ Other changes:
|
||||
which should later lead us toward more flexible uses of menu/status bars. (#5143, #3692)
|
||||
- Tables, Nav: frozen columns are not part of menu layer and can be crossed over. (#5143, #3692)
|
||||
- Tables, Columns: fixed cases where empty columns may lead to empty ImDrawCmd. (#4857, #5937)
|
||||
- Tables: fixed matching width of synchronized tables (multiple tables with same id) when only
|
||||
some instances have a vertical scrollbar and not all. (#5920)
|
||||
- Inputs, IO: reworked ImGuiMod_Shortcut to redirect to Ctrl/Super at runtime instead of
|
||||
compile-time, being consistent with our support for io.ConfigMacOSXBehaviors and making it
|
||||
easier for bindings generators to process that value. (#5923, #456)
|
||||
|
@ -5043,18 +5043,23 @@ static void ShowDemoWindowTables()
|
||||
if (ImGui::TreeNode("Synced instances"))
|
||||
{
|
||||
HelpMarker("Multiple tables with the same identifier will share their settings, width, visibility, order etc.");
|
||||
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoSavedSettings;
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_ScrollY", &flags, ImGuiTableFlags_ScrollY);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_SizingFixedFit", &flags, ImGuiTableFlags_SizingFixedFit);
|
||||
for (int n = 0; n < 3; n++)
|
||||
{
|
||||
char buf[32];
|
||||
sprintf(buf, "Synced Table %d", n);
|
||||
bool open = ImGui::CollapsingHeader(buf, ImGuiTreeNodeFlags_DefaultOpen);
|
||||
if (open && ImGui::BeginTable("Table", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoSavedSettings))
|
||||
if (open && ImGui::BeginTable("Table", 3, flags, ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 5)))
|
||||
{
|
||||
ImGui::TableSetupColumn("One");
|
||||
ImGui::TableSetupColumn("Two");
|
||||
ImGui::TableSetupColumn("Three");
|
||||
ImGui::TableHeadersRow();
|
||||
for (int cell = 0; cell < 9; cell++)
|
||||
const int cell_count = (n == 1) ? 27 : 9; // Make second table have a scrollbar to verify that additional decoration is not affecting column positions.
|
||||
for (int cell = 0; cell < cell_count; cell++)
|
||||
{
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("this cell %d", cell);
|
||||
|
@ -2507,7 +2507,7 @@ struct ImGuiTableInstanceData
|
||||
ImGuiTableInstanceData() { LastOuterHeight = LastFirstRowHeight = LastFrozenHeight = 0.0f; }
|
||||
};
|
||||
|
||||
// FIXME-TABLE: more transient data could be stored in a per-stacked table structure: DrawSplitter, SortSpecs, incoming RowData
|
||||
// FIXME-TABLE: more transient data could be stored in a stacked ImGuiTableTempData: e.g. SortSpecs, incoming RowData
|
||||
struct IMGUI_API ImGuiTable
|
||||
{
|
||||
ImGuiID ID;
|
||||
@ -2612,6 +2612,8 @@ struct IMGUI_API ImGuiTable
|
||||
bool IsResetDisplayOrderRequest;
|
||||
bool IsUnfrozenRows; // Set when we got past the frozen row.
|
||||
bool IsDefaultSizingPolicy; // Set if user didn't explicitly set a sizing policy in BeginTable()
|
||||
bool HasScrollbarYCurr; // Whether ANY instance of this table had a vertical scrollbar during the current frame.
|
||||
bool HasScrollbarYPrev; // Whether ANY instance of this table had a vertical scrollbar during the previous.
|
||||
bool MemoryCompacted;
|
||||
bool HostSkipItems; // Backup of InnerWindow->SkipItem at the end of BeginTable(), because we will overwrite InnerWindow->SkipItem on a per-column basis
|
||||
|
||||
|
@ -395,6 +395,14 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
|
||||
table->OuterRect = table->InnerWindow->Rect();
|
||||
table->InnerRect = table->InnerWindow->InnerRect;
|
||||
IM_ASSERT(table->InnerWindow->WindowPadding.x == 0.0f && table->InnerWindow->WindowPadding.y == 0.0f && table->InnerWindow->WindowBorderSize == 0.0f);
|
||||
|
||||
// When using multiple instances, ensure they have the same amount of horizontal decorations (aka vertical scrollbar) so stretched columns can be aligned)
|
||||
if (instance_no == 0)
|
||||
{
|
||||
table->HasScrollbarYPrev = table->HasScrollbarYCurr;
|
||||
table->HasScrollbarYCurr = false;
|
||||
}
|
||||
table->HasScrollbarYCurr |= (table->InnerWindow->ScrollMax.y > 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -893,7 +901,8 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
|
||||
// [Part 4] Apply final widths based on requested widths
|
||||
const ImRect work_rect = table->WorkRect;
|
||||
const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1);
|
||||
const float width_avail = ((table->Flags & ImGuiTableFlags_ScrollX) && table->InnerWidth == 0.0f) ? table->InnerClipRect.GetWidth() : work_rect.GetWidth();
|
||||
const float width_removed = (table->HasScrollbarYPrev && !table->InnerWindow->ScrollbarY) ? g.Style.ScrollbarSize : 0.0f; // To synchronize decoration width of synched tables with mismatching scrollbar state (#5920)
|
||||
const float width_avail = ImMax(1.0f, (((table->Flags & ImGuiTableFlags_ScrollX) && table->InnerWidth == 0.0f) ? table->InnerClipRect.GetWidth() : work_rect.GetWidth()) - width_removed);
|
||||
const float width_avail_for_stretched_columns = width_avail - width_spacings - sum_width_requests;
|
||||
float width_remaining_for_stretched_columns = width_avail_for_stretched_columns;
|
||||
table->ColumnsGivenWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount;
|
||||
|
Loading…
Reference in New Issue
Block a user