From 5196bd15e90b56ccfaabe1ce44fd352a2e05bd51 Mon Sep 17 00:00:00 2001 From: thedemons Date: Tue, 11 Oct 2022 22:45:27 +0700 Subject: [PATCH 1/6] Docs: Update outdated code sample (#5766) --- docs/FONTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/FONTS.md b/docs/FONTS.md index 8426e54f8..49a555bc5 100644 --- a/docs/FONTS.md +++ b/docs/FONTS.md @@ -277,8 +277,8 @@ io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height); for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++) { - int rect_id = rects_ids[rect_n]; - if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) + int rect_id = rect_ids[rect_n]; + if (const ImFontAtlasCustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) { // Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!) for (int y = 0; y < rect->Height; y++) From 3e8d198133296642a99c98e1bdb7156a56f86142 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 12 Oct 2022 23:07:15 +0200 Subject: [PATCH 2/6] Removed runtime patching of obsolete/invalid "%f"/"%.0f" types of format strings for DragInt()/SliderInt(). --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 1 + imgui.h | 2 +- imgui_widgets.cpp | 31 ------------------------------- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6b97dcdf1..394928b36 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -65,6 +65,8 @@ Breaking changes: semantic, but the additional indirection and copy added complexity and got in the way of other incoming work. User's code (other than backends) should not be affected, unless you have custom widgets intercepting navigation events via the named enums (in which case you can upgrade your code). + - Removed runtime patching of invalid "%f"/"%.0f" types of format strings for DragInt()/SliderInt(). + This was obsoleted in 1.61 (May 2018). See 1.61 changelog for details. - Changed signature of ImageButton() function: (#5533, #4471, #2464, #1390) - Added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter. - Old signature: bool ImageButton(ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), int frame_padding = -1, ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1)); diff --git a/imgui.cpp b/imgui.cpp index 1c6568125..d2c96e90e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -384,6 +384,7 @@ CODE When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2022/10/12 (1.89) - removed runtime patching of invalid "%f"/"%0.f" format strings for DragInt()/SliderInt(). This was obsoleted in 1.61 (May 2018). See 1.61 changelog for details. - 2022/09/26 (1.89) - renamed and merged keyboard modifiers key enums and flags into a same set. Kept inline redirection enums (will obsolete). - ImGuiKey_ModCtrl and ImGuiModFlags_Ctrl -> ImGuiMod_Ctrl - ImGuiKey_ModShift and ImGuiModFlags_Shift -> ImGuiMod_Shift diff --git a/imgui.h b/imgui.h index 917e208c4..7c53d7a38 100644 --- a/imgui.h +++ b/imgui.h @@ -23,7 +23,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') #define IMGUI_VERSION "1.89 WIP" -#define IMGUI_VERSION_NUM 18829 +#define IMGUI_VERSION_NUM 18830 #define IMGUI_HAS_TABLE /* diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 8c34e61f3..f72ea4ced 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1895,7 +1895,6 @@ bool ImGui::Combo(const char* label, int* current_item, const char* items_separa //------------------------------------------------------------------------- // [SECTION] Data Type and Data Formatting Helpers [Internal] //------------------------------------------------------------------------- -// - PatchFormatStringFloatToInt() // - DataTypeGetInfo() // - DataTypeFormatString() // - DataTypeApplyOp() @@ -1926,30 +1925,6 @@ static const ImGuiDataTypeInfo GDataTypeInfo[] = }; IM_STATIC_ASSERT(IM_ARRAYSIZE(GDataTypeInfo) == ImGuiDataType_COUNT); -// FIXME-LEGACY: Prior to 1.61 our DragInt() function internally used floats and because of this the compile-time default value for format was "%.0f". -// Even though we changed the compile-time default, we expect users to have carried %f around, which would break the display of DragInt() calls. -// To honor backward compatibility we are rewriting the format string, unless IMGUI_DISABLE_OBSOLETE_FUNCTIONS is enabled. What could possibly go wrong?! -static const char* PatchFormatStringFloatToInt(const char* fmt) -{ - if (fmt[0] == '%' && fmt[1] == '.' && fmt[2] == '0' && fmt[3] == 'f' && fmt[4] == 0) // Fast legacy path for "%.0f" which is expected to be the most common case. - return "%d"; - const char* fmt_start = ImParseFormatFindStart(fmt); // Find % (if any, and ignore %%) - const char* fmt_end = ImParseFormatFindEnd(fmt_start); // Find end of format specifier, which itself is an exercise of confidence/recklessness (because snprintf is dependent on libc or user). - if (fmt_end > fmt_start && fmt_end[-1] == 'f') - { -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - if (fmt_start == fmt && fmt_end[0] == 0) - return "%d"; - const char* tmp_format; - ImFormatStringToTempBuffer(&tmp_format, NULL, "%.*s%%d%s", (int)(fmt_start - fmt), fmt, fmt_end); // Honor leading and trailing decorations, but lose alignment/precision. - return tmp_format; -#else - IM_ASSERT(0 && "DragInt(): Invalid format string!"); // Old versions used a default parameter of "%.0f", please replace with e.g. "%d" -#endif - } - return fmt; -} - const ImGuiDataTypeInfo* ImGui::DataTypeGetInfo(ImGuiDataType data_type) { IM_ASSERT(data_type >= 0 && data_type < ImGuiDataType_COUNT); @@ -2363,8 +2338,6 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, // Default format string when passing NULL if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt; - else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) - format = PatchFormatStringFloatToInt(format); const bool hovered = ItemHoverable(frame_bb, id); bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); @@ -2956,8 +2929,6 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat // Default format string when passing NULL if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt; - else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) - format = PatchFormatStringFloatToInt(format); const bool hovered = ItemHoverable(frame_bb, id); bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); @@ -3123,8 +3094,6 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d // Default format string when passing NULL if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt; - else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) - format = PatchFormatStringFloatToInt(format); const bool hovered = ItemHoverable(frame_bb, id); if ((hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || g.NavActivateInputId == id) From b15347cb7d0fb3ba9a98420d17ea056e8415e63f Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 13 Oct 2022 15:15:42 +0200 Subject: [PATCH 3/6] Tables: activating an ID (e.g. clicking button inside) column doesn't prevent columns output flags from having ImGuiTableColumnFlags_IsHovered set. (#2957) --- docs/CHANGELOG.txt | 2 ++ imgui.h | 2 +- imgui_tables.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 394928b36..460d7747f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -124,6 +124,8 @@ Other Changes: io.HoverDelayNormal (default to 0.30f) and io.HoverDelayFast (default to 0.10f). (#1485) - IsItemHovered: Added ImGuiHoveredFlags_NoSharedDelay to disable sharing delays between itemm, so moving from one item to a nearby one will requires delay to elapse again. (#1485) +- Tables: activating an ID (e.g. clicking button inside) column doesn't prevent columns + output flags from having ImGuiTableColumnFlags_IsHovered set. (#2957) - Tables,Columns: fixed a layout issue where SameLine() prior to a row change would set the next row in such state where subsequent SameLine() would move back to previous row. - Tabs: Fixed a crash when closing multiple windows (possible with docking only) with an diff --git a/imgui.h b/imgui.h index 7c53d7a38..7af79200d 100644 --- a/imgui.h +++ b/imgui.h @@ -23,7 +23,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') #define IMGUI_VERSION "1.89 WIP" -#define IMGUI_VERSION_NUM 18830 +#define IMGUI_VERSION_NUM 18831 #define IMGUI_HAS_TABLE /* diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 3692c248f..64fc7ecbe 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -936,11 +936,19 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) width_remaining_for_stretched_columns -= 1.0f; } + // Determine if table is hovered which will be used to flag columns as hovered. + // - In principle we'd like to use the equivalent of IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem), + // but because our item is partially submitted at this point we use ItemHoverable() and a workaround (temporarily + // clear ActiveId, which is equivalent to the change provided by _AllowWhenBLockedByActiveItem). + // - This allows columns to be marked as hovered when e.g. clicking a button inside the column, or using drag and drop. ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); table->HoveredColumnBody = -1; table->HoveredColumnBorder = -1; const ImRect mouse_hit_rect(table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.Max.x, ImMax(table->OuterRect.Max.y, table->OuterRect.Min.y + table_instance->LastOuterHeight)); + const ImGuiID backup_active_id = g.ActiveId; + g.ActiveId = 0; const bool is_hovering_table = ItemHoverable(mouse_hit_rect, 0); + g.ActiveId = backup_active_id; // [Part 6] Setup final position, offset, skip/clip states and clipping rectangles, detect hovered column // Process columns in their visible orders as we are comparing the visible order and adjusting host_clip_rect while looping. From 3920b1c764ef0f9d336eb4f2f8a62fb78a3453ad Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 12 Oct 2022 23:35:53 +0200 Subject: [PATCH 4/6] Removed commented out old flags from when Tables was a branch. ImGuiTableFlags_ColumnsWidthFixed, ImGuiTableFlags_ColumnsWidthStretch, ImGuiTableFlags_SizingPolicyFixed, ImGuiTableFlags_SizingPolicyStretch ImGuiTableColumnFlags_WidthAuto --- imgui.h | 11 ----------- imgui_draw.cpp | 1 + 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/imgui.h b/imgui.h index 7af79200d..5d8b7c52b 100644 --- a/imgui.h +++ b/imgui.h @@ -1186,12 +1186,6 @@ enum ImGuiTableFlags_ // [Internal] Combinations and masks ImGuiTableFlags_SizingMask_ = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_SizingStretchSame, - - // Obsolete names (will be removed soon) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - //, ImGuiTableFlags_ColumnsWidthFixed = ImGuiTableFlags_SizingFixedFit, ImGuiTableFlags_ColumnsWidthStretch = ImGuiTableFlags_SizingStretchSame // WIP Tables 2020/12 - //, ImGuiTableFlags_SizingPolicyFixed = ImGuiTableFlags_SizingFixedFit, ImGuiTableFlags_SizingPolicyStretch = ImGuiTableFlags_SizingStretchSame // WIP Tables 2021/01 -#endif }; // Flags for ImGui::TableSetupColumn() @@ -1229,11 +1223,6 @@ enum ImGuiTableColumnFlags_ ImGuiTableColumnFlags_IndentMask_ = ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_IndentDisable, ImGuiTableColumnFlags_StatusMask_ = ImGuiTableColumnFlags_IsEnabled | ImGuiTableColumnFlags_IsVisible | ImGuiTableColumnFlags_IsSorted | ImGuiTableColumnFlags_IsHovered, ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30, // [Internal] Disable user resizing this column directly (it may however we resized indirectly from its left edge) - - // Obsolete names (will be removed soon) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - //ImGuiTableColumnFlags_WidthAuto = ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize, // Column will not stretch and keep resizing based on submitted contents. -#endif }; // Flags for ImGui::TableNextRow() diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a0b94974a..7a8f229eb 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1312,6 +1312,7 @@ IM_STATIC_ASSERT(ImDrawFlags_RoundCornersTopLeft == (1 << 4)); static inline ImDrawFlags FixRectCornerFlags(ImDrawFlags flags) { #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + // Obsoleted in 1.82 (from February 2021) // Legacy Support for hard coded ~0 (used to be a suggested equivalent to ImDrawCornerFlags_All) // ~0 --> ImDrawFlags_RoundCornersAll or 0 if (flags == ~0) From 81176737f83a7e21cda5022c758e7c36fbdd0d1e Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 14 Oct 2022 17:39:04 +0200 Subject: [PATCH 5/6] Menus: Fixed using IsItemHovered()/IsItemClicked() on BeginMenu(). (#5775) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 2 +- imgui.h | 2 +- imgui_widgets.cpp | 10 +++++++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 460d7747f..fdb8d646c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -144,6 +144,7 @@ Other Changes: towards a sub-menu. (#2517, #5614). [@rokups] - Menus: Fixed gaps in closing logic which would make child-menu erroneously close when crossing the gap between a menu item inside a window and a child-menu in a secondary viewport. (#5614) +- Menus: Fixed using IsItemHovered()/IsItemClicked() on BeginMenu(). (#5775) - Menus, Nav: Fixed keyboard/gamepad navigation occasionally erroneously landing on menu-item in parent window when the parent is not a popup. (#5730) - Menus, Nav: Fixed not being able to close a menu with Left arrow when parent is not a popup. (#5730) diff --git a/imgui.cpp b/imgui.cpp index d2c96e90e..21d017b47 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3640,7 +3640,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) // Test if interactions on this window are blocked by an active popup or modal. // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here. - if (!IsWindowContentHoverable(window, flags)) + if (!IsWindowContentHoverable(window, flags) && !(g.LastItemData.InFlags & ImGuiItemFlags_NoWindowHoverableCheck)) return false; // Test if the item is disabled diff --git a/imgui.h b/imgui.h index 5d8b7c52b..de8deff8d 100644 --- a/imgui.h +++ b/imgui.h @@ -23,7 +23,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') #define IMGUI_VERSION "1.89 WIP" -#define IMGUI_VERSION_NUM 18831 +#define IMGUI_VERSION_NUM 18832 #define IMGUI_HAS_TABLE /* diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f72ea4ced..cf5eebb06 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7125,11 +7125,19 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) if (menu_is_open) { - // FIXME: This technically breaks functions relying on LastItemData, somehow nobody complained yet. Should backup/restore LastItemData. + ImGuiLastItemData last_item_in_parent = g.LastItemData; SetNextWindowPos(popup_pos, ImGuiCond_Always); // Note: misleading: the value will serve as reference for FindBestWindowPosForPopup(), not actual pos. PushStyleVar(ImGuiStyleVar_ChildRounding, style.PopupRounding); // First level will use _PopupRounding, subsequent will use _ChildRounding menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) PopStyleVar(); + if (menu_is_open) + { + // Restore LastItemData so IsItemXXXX functions can work after BeginMenu()/EndMenu() + // (This fixes using IsItemClicked() and IsItemHovered(), but IsItemHovered() also relies on its support for ImGuiItemFlags_NoWindowHoverableCheck) + g.LastItemData = last_item_in_parent; + if (g.HoveredWindow == window) + g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow; + } } else { From 08752b372e5ebeb39adec59387590dac9d9e68f7 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 14 Oct 2022 18:43:04 +0200 Subject: [PATCH 6/6] Menus, Popups: Experimental fix for issue where clicking on an open BeginMenu() item called from a window which is neither a popup neither a menu used to incorrectly close and reopen the menu. (#5775) This works by moving the ClosePopupsOverWindow() in FocusWindow() in the if() block which luckily solves our problem. In our test suite I couldn't find situation where this had side-effect others than BeginMenu() using the 'menuset_is_open' trick. It's difficult to tell if other side-effects are possible: a window being already focused should mean it doesn't have popups overit. Effectively this means that clicking e.g. on the BeginMenu() item to close a menu in a menu-bar now relies on BeginMenu() logic for the closure rather than FocusWindow() triggerd by button behavior. --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index fdb8d646c..8fc86d998 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -145,6 +145,9 @@ Other Changes: - Menus: Fixed gaps in closing logic which would make child-menu erroneously close when crossing the gap between a menu item inside a window and a child-menu in a secondary viewport. (#5614) - Menus: Fixed using IsItemHovered()/IsItemClicked() on BeginMenu(). (#5775) +- Menus, Popups: Experimental fix for issue where clicking on an open BeginMenu() item called from + a window which is neither a popup neither a menu used to incorrectly close and reopen the menu. + (the fix may have side-effect so labelld as experimental as we may need to revert) (#5775) - Menus, Nav: Fixed keyboard/gamepad navigation occasionally erroneously landing on menu-item in parent window when the parent is not a popup. (#5730) - Menus, Nav: Fixed not being able to close a menu with Left arrow when parent is not a popup. (#5730) diff --git a/imgui.cpp b/imgui.cpp index 21d017b47..6760553e3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7025,10 +7025,10 @@ void ImGui::FocusWindow(ImGuiWindow* window) g.NavLayer = ImGuiNavLayer_Main; g.NavFocusScopeId = 0; g.NavIdIsAlive = false; - } - // Close popups if any - ClosePopupsOverWindow(window, false); + // Close popups if any + ClosePopupsOverWindow(window, false); + } // Move the root window to the top of the pile IM_ASSERT(window == NULL || window->RootWindow != NULL);