From 1fb26d18c42cf90d4fb3f99da453912cccb6c3d3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 16 Dec 2020 15:27:17 +0100 Subject: [PATCH] Tables: fixed seemingly unnecessarily copy of ImGuiTableColumnFlags_NoDirectResize_ which broken resizing from W3| in a F1 W3 F2 setup. Header only allow overlap on hover, not when active (amend f2df804f) Otherwise TableUpdateBorders() tends to override mouse cursor. --- imgui_tables.cpp | 30 +++++++++++------------------- imgui_widgets.cpp | 2 +- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 261ebf0a..7a9668f2 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -815,23 +815,12 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) continue; ImGuiTableColumn* column = &table->Columns[column_n]; - // Allocate width for stretched/weighted columns - if (column->Flags & ImGuiTableColumnFlags_WidthStretch) + // Allocate width for stretched/weighted columns (StretchWeight gets converted into WidthRequest) + if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) && !mixed_same_widths) { - // StretchWeight gets converted into WidthRequest - if (!mixed_same_widths) - { - float weight_ratio = column->StretchWeight / sum_weights_stretched; - column->WidthRequest = IM_FLOOR(ImMax(width_avail_for_stretched_columns * weight_ratio, min_column_width) + 0.01f); - width_remaining_for_stretched_columns -= column->WidthRequest; - } - - // [Resize Rule 2] Resizing from right-side of a stretch column preceding a fixed column - // needs to forward resizing to left-side of fixed column. We also need to copy the NoResize flag.. - if (column->NextEnabledColumn != -1) - if (ImGuiTableColumn* next_column = &table->Columns[column->NextEnabledColumn]) - if (next_column->Flags & ImGuiTableColumnFlags_WidthFixed) - column->Flags |= (next_column->Flags & ImGuiTableColumnFlags_NoDirectResize_); + float weight_ratio = column->StretchWeight / sum_weights_stretched; + column->WidthRequest = IM_FLOOR(ImMax(width_avail_for_stretched_columns * weight_ratio, min_column_width) + 0.01f); + width_remaining_for_stretched_columns -= column->WidthRequest; } // [Resize Rule 1] The right-most Visible column is not resizable if there is at least one Stretch column @@ -1876,15 +1865,17 @@ void ImGui::TableSetColumnWidth(int column_n, float width) // - F1 F2 F3 resize from F3| --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered. // - F1 F2 W3 resize from F1| or F2| --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered, but it doesn't make much sense as the Stretch column will always be minimal size. // - F1 F2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1) - // - W1 W2 W3 resize from W1| or W2| --> FIXME + // - W1 W2 W3 resize from W1| or W2| --> ok // - W1 W2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1) // - W1 F2 F3 resize from F3| --> ok: no-op (disabled by Resize Rule 1) // - W1 F2 resize from F2| --> ok: no-op (disabled by Resize Rule 1) // - W1 W2 F3 resize from W1| or W2| --> ok // - W1 F2 W3 resize from W1| or F2| --> FIXME // - F1 W2 F3 resize from W2| --> ok + // - F1 W3 F2 resize from W3| --> ok // - W1 F2 F3 resize from W1| --> ok: equivalent to resizing |F2. F3 will not move. (forwarded by Resize Rule 2) - // - W1 F2 F3 resize from F2| --> FIXME should resize F2, F3 and not have effect on W1 (Stretch columns are _before_ the Fixed column). + // - W1 F2 F3 resize from F2| --> ok + // All resizes from a Wx columns are locking other columns. // Rules: // - [Resize Rule 1] Can't resize from right of right-most visible column if there is any Stretch column. Implemented in TableUpdateLayout(). @@ -2679,7 +2670,8 @@ void ImGui::TableHeader(const char* label) // Using AllowItemOverlap mode because we cover the whole cell, and we want user to be able to submit subsequent items. bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, ImGuiButtonFlags_AllowItemOverlap); - SetItemAllowOverlap(); + if (g.ActiveId != id) + SetItemAllowOverlap(); if (hovered || selected) { const ImU32 col = GetColorU32(held ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 8b67f0ef..da08b6ee 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7664,7 +7664,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, hovered |= (g.HoveredId == id); // Allow the close button to overlap unless we are dragging (in which case we don't want any overlapping tabs to be hovered) - if (!held) + if (g.ActiveId != id) SetItemAllowOverlap(); // Drag and drop: re-order tabs