0
0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-18 17:11:23 +01:00

InvisibleButton: allow calling with size (0,0) to fit to available content size. (#9166, #7623)

This commit is contained in:
ocornut
2026-01-13 16:15:48 +01:00
parent f64c7c37ef
commit 791ad9b82d
2 changed files with 4 additions and 3 deletions

View File

@@ -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:

View File

@@ -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))