From 6ce26ef11d52d57845d0f06d84dcbfbc0f8d006b Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Sep 2024 12:25:21 +0200 Subject: [PATCH 1/7] AddFont: added assert to better detect uninitialized struct. (#7993) --- imgui_draw.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a681059bb..79270f1a1 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2499,13 +2499,14 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg) { IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!"); IM_ASSERT(font_cfg->FontData != NULL && font_cfg->FontDataSize > 0); - IM_ASSERT(font_cfg->SizePixels > 0.0f); + IM_ASSERT(font_cfg->SizePixels > 0.0f && "Is ImFontConfig struct correctly initialized?"); + IM_ASSERT(font_cfg->OversampleH > 0 && font_cfg->OversampleV > 0 && "Is ImFontConfig struct correctly initialized?"); // Create new font if (!font_cfg->MergeMode) Fonts.push_back(IM_NEW(ImFont)); else - IM_ASSERT(!Fonts.empty() && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font. + IM_ASSERT(Fonts.Size > 0 && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font. ConfigData.push_back(*font_cfg); ImFontConfig& new_font_cfg = ConfigData.back(); From 11fba027e506beca7a2a726b73577b5e8938d64d Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Sep 2024 16:35:55 +0200 Subject: [PATCH 2/7] Tables: using table->InnerClipRect more consistently. Fixes an assertion with tables with borders when clipped by parent. (#6765, #3752, #7428) --- docs/CHANGELOG.txt | 1 + imgui_tables.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 95df895c4..8d640533c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -70,6 +70,7 @@ Other changes: (e.g. in our testing, handling of a 1 MB text buffer is now 3 times faster in VS2022 Debug build). This is the first step toward more refactoring. (#7925) [@alektron, @ocornut] - InputText: added CJK double-width punctuation to list of separators considered for CTRL+Arrow. +- Tables: fixes an assertion with tables with borders when clipped by parent. (#6765, #3752, #7428) - Misc: Made it accepted to call SetMouseCursor() with any out-of-bound value, as a way to allow hacking in custom cursors if desirable. - Fonts: fixed ellipsis "..." rendering width miscalculation bug introduced in 1.91.0. (#7976) [@DDeimos] diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 9a6e06a2d..e82e8777f 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -1261,7 +1261,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) if (table->Flags & ImGuiTableFlags_NoClip) table->DrawSplitter->SetCurrentChannel(inner_window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP); else - inner_window->DrawList->PushClipRect(inner_window->InnerClipRect.Min, inner_window->InnerClipRect.Max, false); + inner_window->DrawList->PushClipRect(inner_window->InnerClipRect.Min, inner_window->InnerClipRect.Max, false); // FIXME: use table->InnerClipRect? } // Process hit-testing on resizing borders. Actual size change will be applied in EndTable() @@ -2011,7 +2011,7 @@ void ImGui::TableEndRow(ImGuiTable* table) { for (int column_n = 0; column_n < table->ColumnsCount; column_n++) table->Columns[column_n].NavLayerCurrent = ImGuiNavLayer_Main; - const float y0 = ImMax(table->RowPosY2 + 1, window->InnerClipRect.Min.y); + const float y0 = ImMax(table->RowPosY2 + 1, table->InnerClipRect.Min.y); table_instance->LastFrozenHeight = y0 - table->OuterRect.Min.y; if (unfreeze_rows_actual) @@ -2020,8 +2020,8 @@ void ImGui::TableEndRow(ImGuiTable* table) table->IsUnfrozenRows = true; // BgClipRect starts as table->InnerClipRect, reduce it now and make BgClipRectForDrawCmd == BgClipRect - table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, window->InnerClipRect.Max.y); - table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = window->InnerClipRect.Max.y; + table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, table->InnerClipRect.Max.y); + table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = table->InnerClipRect.Max.y; table->Bg2DrawChannelCurrent = table->Bg2DrawChannelUnfrozen; IM_ASSERT(table->Bg2ClipRectForDrawCmd.Min.y <= table->Bg2ClipRectForDrawCmd.Max.y); From 71714eab5367d2fa119e36be30148278e0d5974f Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Sep 2024 18:09:02 +0200 Subject: [PATCH 3/7] Tables: fixed assertion related to inconsistent outer clipping when sizes are not rounded. (#7957) --- docs/CHANGELOG.txt | 3 ++- imgui.h | 2 +- imgui_tables.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8d640533c..566e42608 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -70,7 +70,8 @@ Other changes: (e.g. in our testing, handling of a 1 MB text buffer is now 3 times faster in VS2022 Debug build). This is the first step toward more refactoring. (#7925) [@alektron, @ocornut] - InputText: added CJK double-width punctuation to list of separators considered for CTRL+Arrow. -- Tables: fixes an assertion with tables with borders when clipped by parent. (#6765, #3752, #7428) +- Tables: fixed assertion related to inconsistent outer clipping when sizes are not rounded. (#7957) [@eclbtownsend] +- Tables: fixed assertion with tables with borders when clipped by parent. (#6765, #3752, #7428) - Misc: Made it accepted to call SetMouseCursor() with any out-of-bound value, as a way to allow hacking in custom cursors if desirable. - Fonts: fixed ellipsis "..." rendering width miscalculation bug introduced in 1.91.0. (#7976) [@DDeimos] diff --git a/imgui.h b/imgui.h index 095c25002..854d210e1 100644 --- a/imgui.h +++ b/imgui.h @@ -29,7 +29,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') #define IMGUI_VERSION "1.91.2 WIP" -#define IMGUI_VERSION_NUM 19114 +#define IMGUI_VERSION_NUM 19115 #define IMGUI_HAS_TABLE /* diff --git a/imgui_tables.cpp b/imgui_tables.cpp index e82e8777f..d9844586b 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -328,7 +328,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG // - always performing the GetOrAddByKey() O(log N) query in g.Tables.Map[]. const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0; const ImVec2 avail_size = GetContentRegionAvail(); - const ImVec2 actual_outer_size = CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f); + const ImVec2 actual_outer_size = ImTrunc(CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f)); const ImRect outer_rect(outer_window->DC.CursorPos, outer_window->DC.CursorPos + actual_outer_size); const bool outer_window_is_measuring_size = (outer_window->AutoFitFramesX > 0) || (outer_window->AutoFitFramesY > 0); // Doesn't apply to AlwaysAutoResize windows! if (use_child_window && IsClippedEx(outer_rect, 0) && !outer_window_is_measuring_size) From dad9f45e3ed9968b7873f3ed4a41ac0339befafa Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Sep 2024 18:27:31 +0200 Subject: [PATCH 4/7] Windows: fixed an issue where double-click to collapse could be triggered even while another item is active. (#7841, #7369) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 566e42608..9e31a1011 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -72,6 +72,8 @@ Other changes: - InputText: added CJK double-width punctuation to list of separators considered for CTRL+Arrow. - Tables: fixed assertion related to inconsistent outer clipping when sizes are not rounded. (#7957) [@eclbtownsend] - Tables: fixed assertion with tables with borders when clipped by parent. (#6765, #3752, #7428) +- Windows: fixed an issue where double-click to collapse could be triggered even while another + item is active, if the item didn't use the left mouse button. (#7841) - Misc: Made it accepted to call SetMouseCursor() with any out-of-bound value, as a way to allow hacking in custom cursors if desirable. - Fonts: fixed ellipsis "..." rendering width miscalculation bug introduced in 1.91.0. (#7976) [@DDeimos] diff --git a/imgui.cpp b/imgui.cpp index bdeda3fe7..369e582d7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6948,9 +6948,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse)) { - // We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), so verify that we don't have items over the title bar. + // We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), + // so verify that we don't have items over the title bar. ImRect title_bar_rect = window->TitleBarRect(); - if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max)) + if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && g.ActiveId == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max)) if (g.IO.MouseClickedCount[0] == 2 && GetKeyOwner(ImGuiKey_MouseLeft) == ImGuiKeyOwner_NoOwner) window->WantCollapseToggle = true; if (window->WantCollapseToggle) From 6aade6912a107204d15ebe7171434ee21a91c629 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Sep 2024 18:52:12 +0200 Subject: [PATCH 5/7] Inputs: SetNextItemShortcut() with ImGuiInputFlags_Tooltip doesn't show tooltip when item is active. --- docs/CHANGELOG.txt | 1 + imgui.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9e31a1011..475daa596 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -65,6 +65,7 @@ Other changes: - Nav: pressing any keyboard key while holding Alt disable toggling nav layer on Alt release. (#4439) - MultiSelect+Tables: fixed an issue where box-select would skip items while drag-scrolling in a table with outer borders. (#7970, #7821). +- Inputs: SetNextItemShortcut() with ImGuiInputFlags_Tooltip doesn't show tooltip when item is active. - InputText: internal refactoring to simplify and optimize the code. The ImWchar buffer has been removed. Simplifications allowed to implement new optimizations for handling very large text buffers (e.g. in our testing, handling of a 1 MB text buffer is now 3 times faster in VS2022 Debug build). diff --git a/imgui.cpp b/imgui.cpp index 369e582d7..9dddb55c2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4343,7 +4343,7 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id, ImGuiItemFlags item_flag // Display shortcut (only works with mouse) // (ImGuiItemStatusFlags_HasShortcut in LastItemData denotes we want a tooltip) - if (id == g.LastItemData.ID && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasShortcut)) + if (id == g.LastItemData.ID && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasShortcut) && g.ActiveId != id) if (IsItemHovered(ImGuiHoveredFlags_ForTooltip | ImGuiHoveredFlags_DelayNormal)) SetTooltip("%s", GetKeyChordName(g.LastItemData.Shortcut)); } From e648dbb59d24c29a2e2ac964777822e96befd808 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Sep 2024 20:34:54 +0200 Subject: [PATCH 6/7] Tables: fixed auto-width columns when using synced-instances of same table. (#7218) Amend d3c3514a5 --- docs/CHANGELOG.txt | 2 ++ imgui_tables.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 475daa596..de022c1ae 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -71,6 +71,8 @@ Other changes: (e.g. in our testing, handling of a 1 MB text buffer is now 3 times faster in VS2022 Debug build). This is the first step toward more refactoring. (#7925) [@alektron, @ocornut] - InputText: added CJK double-width punctuation to list of separators considered for CTRL+Arrow. +- Tables: fixed auto-width columns when using synced-instances of same table. The previous fix + done in v1.90.5 was incomplete. (#7218) - Tables: fixed assertion related to inconsistent outer clipping when sizes are not rounded. (#7957) [@eclbtownsend] - Tables: fixed assertion with tables with borders when clipped by parent. (#6765, #3752, #7428) - Windows: fixed an issue where double-click to collapse could be triggered even while another diff --git a/imgui_tables.cpp b/imgui_tables.cpp index d9844586b..c3fb531ef 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -866,7 +866,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) // Calculate ideal/auto column width (that's the width required for all contents to be visible without clipping) // Combine width from regular rows + width from headers unless requested not to. - if (!column->IsPreserveWidthAuto) + if (!column->IsPreserveWidthAuto && table->InstanceCurrent == 0) column->WidthAuto = TableGetColumnWidthAuto(table, column); // Non-resizable columns keep their requested width (apply user value regardless of IsPreserveWidthAuto) From f7ba6453980824aa4a7d096841576285efa7f6ec Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Sep 2024 21:07:15 +0200 Subject: [PATCH 7/7] InputText: fixed not filling callback's SelectionEnd. (#7925) Broken by abd07f6 --- imgui_widgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 4156ce8af..27610228d 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4977,7 +4977,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ const int utf8_cursor_pos = callback_data.CursorPos = state->Stb->cursor; const int utf8_selection_start = callback_data.SelectionStart = state->Stb->select_start; - const int utf8_selection_end = state->Stb->select_end; + const int utf8_selection_end = callback_data.SelectionEnd = state->Stb->select_end; // Call user code callback(&callback_data);