From 791ad9b82db44ada9fedb3e26b2d900974ac0959 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 13 Jan 2026 16:15:48 +0100 Subject: [PATCH] InvisibleButton: allow calling with size (0,0) to fit to available content size. (#9166, #7623) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index cd9315352..76d922194 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -163,6 +163,8 @@ Other Changes: nav cursor is visible and `io.ConfigNavMoveSetMousePos` is enabled. - Scrollbar: fixed a codepath leading to a divide-by-zero (which would not be noticeable by user but detected by sanitizers). (#9089) [@judicaelclair] +- InvisibleButton: allow calling with size (0,0) to fit to available content + size. (#9166, #7623) - Added GetItemFlags() in public API for consistency and to expose generic flags of last submitted item. (#9127) - Shortcuts: diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 88d3b7ca4..4244c0be3 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -836,11 +836,10 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg, ImGuiBut if (window->SkipItems) return false; - // Cannot use zero-size for InvisibleButton(). Unlike Button() there is not way to fallback using the label size. - IM_ASSERT(size_arg.x != 0.0f && size_arg.y != 0.0f); + // Ensure zero-size fits to contents + ImVec2 size = CalcItemSize(ImVec2(size_arg.x != 0.0f ? size_arg.x : -FLT_MIN, size_arg.y != 0.0f ? size_arg.y : -FLT_MIN), 0.0f, 0.0f); const ImGuiID id = window->GetID(str_id); - ImVec2 size = CalcItemSize(size_arg, 0.0f, 0.0f); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); ItemSize(size); if (!ItemAdd(bb, id, NULL, (flags & ImGuiButtonFlags_EnableNav) ? ImGuiItemFlags_None : ImGuiItemFlags_NoNav))