From f96c5443b1bfd052b42b0efe5623c0eb06e2cfd4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 12 Oct 2023 19:47:37 +0200 Subject: [PATCH 01/12] Tables: fixed angled headers with frozen columns. --- imgui_demo.cpp | 4 +++- imgui_tables.cpp | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 8f754db2..29a58f90 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -5201,12 +5201,14 @@ static void ShowDemoWindowTables() static ImGuiTableFlags table_flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_Hideable | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_HighlightHoveredColumn; static bool bools[columns_count * rows_count] = {}; // Dummy storage selection storage + static int frozen_cols = 1; static int frozen_rows = 2; ImGui::CheckboxFlags("_ScrollX", &table_flags, ImGuiTableFlags_ScrollX); ImGui::CheckboxFlags("_ScrollY", &table_flags, ImGuiTableFlags_ScrollY); ImGui::CheckboxFlags("_NoBordersInBody", &table_flags, ImGuiTableFlags_NoBordersInBody); ImGui::CheckboxFlags("_HighlightHoveredColumn", &table_flags, ImGuiTableFlags_HighlightHoveredColumn); ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); + ImGui::SliderInt("Frozen columns", &frozen_cols, 0, 2); ImGui::SliderInt("Frozen rows", &frozen_rows, 0, 2); if (ImGui::BeginTable("table_angled_headers", columns_count, table_flags, ImVec2(0.0f, TEXT_BASE_HEIGHT * 12))) @@ -5214,7 +5216,7 @@ static void ShowDemoWindowTables() ImGui::TableSetupColumn(column_names[0], ImGuiTableColumnFlags_NoHide | ImGuiTableColumnFlags_NoReorder); for (int n = 1; n < columns_count; n++) ImGui::TableSetupColumn(column_names[n], ImGuiTableColumnFlags_AngledHeader | ImGuiTableColumnFlags_WidthFixed); - ImGui::TableSetupScrollFreeze(0, frozen_rows); + ImGui::TableSetupScrollFreeze(frozen_cols, frozen_rows); ImGui::TableAngledHeadersRow(); // Draw angled headers for all columns with the ImGuiTableColumnFlags_AngledHeader flag. ImGui::TableHeadersRow(); // Draw remaining headers and allow access to context-menu and other functions. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 1063fa79..e028376d 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -3166,9 +3166,13 @@ void ImGui::TableAngledHeadersRowEx(float angle, float max_label_width) TableNextRow(ImGuiTableRowFlags_Headers, row_height); TableNextColumn(); table->DrawSplitter->SetCurrentChannel(draw_list, TABLE_DRAW_CHANNEL_BG0); - PushClipRect(table->BgClipRect.Min, table->BgClipRect.Max, false); // Span all columns + float clip_rect_min_x = table->BgClipRect.Min.x; + if (table->FreezeColumnsCount > 0) + clip_rect_min_x = ImMax(clip_rect_min_x, table->Columns[table->FreezeColumnsCount - 1].MaxX); TableSetBgColor(ImGuiTableBgTarget_RowBg0, 0); // Cancel + PushClipRect(table->BgClipRect.Min, table->BgClipRect.Max, false); // Span all columns draw_list->AddRectFilled(table->BgClipRect.Min, table->BgClipRect.Max, GetColorU32(ImGuiCol_TableHeaderBg, 0.25f)); // FIXME-STYLE: Change row background with an arbitrary color. + PushClipRect(ImVec2(clip_rect_min_x, table->BgClipRect.Min.y), table->BgClipRect.Max, true); // Span all columns const ImRect row_r(table->WorkRect.Min.x, table->BgClipRect.Min.y, table->WorkRect.Max.x, window->DC.CursorPos.y + row_height); const ImGuiID row_id = GetID("##AngledHeaders"); @@ -3230,6 +3234,7 @@ void ImGui::TableAngledHeadersRowEx(float angle, float max_label_width) } } PopClipRect(); + PopClipRect(); table->TempData->AngledheadersExtraWidth = ImMax(0.0f, max_x - table->Columns[table->RightMostEnabledColumn].MaxX); } From 12a3c77c2f4671813c2a09197234d5672f8ab5f3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 12 Oct 2023 20:00:34 +0200 Subject: [PATCH 02/12] Demo: Minor tweak to angled headers demo. --- imgui_demo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 29a58f90..b386d8a6 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -5209,6 +5209,7 @@ static void ShowDemoWindowTables() ImGui::CheckboxFlags("_HighlightHoveredColumn", &table_flags, ImGuiTableFlags_HighlightHoveredColumn); ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); ImGui::SliderInt("Frozen columns", &frozen_cols, 0, 2); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); ImGui::SliderInt("Frozen rows", &frozen_rows, 0, 2); if (ImGui::BeginTable("table_angled_headers", columns_count, table_flags, ImVec2(0.0f, TEXT_BASE_HEIGHT * 12))) From 0b8c6b9bcefd420ec0e59f0596f0190f6551fc10 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 13 Oct 2023 14:52:08 +0200 Subject: [PATCH 03/12] Internals: removed seemingly unused AutoFitChildAxises. The clamp was done on BeginChild(). Amend 2545d75c --- imgui.cpp | 20 +++++--------------- imgui_internal.h | 1 - 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 63d7d141..a07faf05 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5445,7 +5445,6 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b ImGuiWindow* child_window = g.CurrentWindow; child_window->ChildId = id; - child_window->AutoFitChildAxises = (ImS8)auto_fit_axises; // Set the cursor to handle case where the user called SetNextWindowPos()+BeginChild() manually. // While this is not really documented/defined, it seems that the expected thing to do. @@ -5488,22 +5487,13 @@ void ImGui::EndChild() IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() calls g.WithinEndChild = true; - if (window->BeginCount > 1) - { - End(); - } - else + ImVec2 child_size = window->Size; + End(); + if (window->BeginCount == 1) { - ImVec2 sz = window->Size; - if (window->AutoFitChildAxises & (1 << ImGuiAxis_X)) // Arbitrary minimum zero-ish child size of 4.0f causes less trouble than a 0.0f - sz.x = ImMax(4.0f, sz.x); - if (window->AutoFitChildAxises & (1 << ImGuiAxis_Y)) - sz.y = ImMax(4.0f, sz.y); - End(); - ImGuiWindow* parent_window = g.CurrentWindow; - ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz); - ItemSize(sz); + ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + child_size); + ItemSize(child_size); if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavWindowHasScrollY) && !(window->Flags & ImGuiWindowFlags_NavFlattened)) { ItemAdd(bb, window->ChildId); diff --git a/imgui_internal.h b/imgui_internal.h index f090670b..520d89f0 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2436,7 +2436,6 @@ struct IMGUI_API ImGuiWindow short FocusOrder; // Order within WindowsFocusOrder[], altered when windows are focused. ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling) ImS8 AutoFitFramesX, AutoFitFramesY; - ImS8 AutoFitChildAxises; bool AutoFitOnlyGrows; ImGuiDir AutoPosLastDirection; ImS8 HiddenFramesCanSkipItems; // Hide the window for N frames From 947255c3dab858f46d512eb541048ec8cc0a1383 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 16 Oct 2023 11:56:03 +0200 Subject: [PATCH 04/12] Tooltips: made it possible to use ImGuiHoveredFlags_ForTooltip + a ImGuiHoveredFlags_DelayXXXX override. (#1485) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2ef5e5ef..d8060aba 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -70,6 +70,8 @@ Other changes: - Tooltips: made using SetItemTooltip()/IsItemHovered(ImGuiHoveredFlags_ForTooltip) defaults to activate tooltips on disabled items. This is done by adding ImGuiHoveredFlags_AllowWhenDisabled to the default value of style.HoverFlagsForTooltipMouse/HoverFlagsForTooltipNav. (#1485) +- Tooltips: made is possible to combine ImGuiHoveredFlags_ForTooltip with a ImGuiHoveredFlags_DelayXXX + override. (#1485) - Nav: Tabbing always enable nav highlight when ImGuiConfigFlags_NavEnableKeyboard is set. Previously was inconsistent and only enabled when stepping through a non-input item. (#6802, #3092, #5759, #787) diff --git a/imgui.cpp b/imgui.cpp index a07faf05..e25c78c1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4001,13 +4001,21 @@ bool ImGui::IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFlags flag static inline float CalcDelayFromHoveredFlags(ImGuiHoveredFlags flags) { ImGuiContext& g = *GImGui; - if (flags & ImGuiHoveredFlags_DelayShort) - return g.Style.HoverDelayShort; if (flags & ImGuiHoveredFlags_DelayNormal) return g.Style.HoverDelayNormal; + if (flags & ImGuiHoveredFlags_DelayShort) + return g.Style.HoverDelayShort; return 0.0f; } +static ImGuiHoveredFlags ApplyHoverFlagsForTooltip(ImGuiHoveredFlags user_flags, ImGuiHoveredFlags shared_flags) +{ + // Allow instance flags to override shared flags + if (user_flags & (ImGuiHoveredFlags_DelayNone | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_DelayNormal)) + shared_flags &= ~(ImGuiHoveredFlags_DelayNone | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_DelayNormal); + return user_flags | shared_flags; +} + // This is roughly matching the behavior of internal-facing ItemHoverable() // - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered() // - this should work even for non-interactive items that have no ID, so we cannot use LastItemId @@ -4025,7 +4033,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) return false; if (flags & ImGuiHoveredFlags_ForTooltip) - flags |= g.Style.HoverFlagsForTooltipNav; + flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipNav); } else { @@ -4035,7 +4043,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) return false; if (flags & ImGuiHoveredFlags_ForTooltip) - flags |= g.Style.HoverFlagsForTooltipMouse; + flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipMouse); IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function @@ -5423,7 +5431,6 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b // Size const ImVec2 content_avail = GetContentRegionAvail(); ImVec2 size = ImTrunc(size_arg); - const int auto_fit_axises = ((size.x == 0.0f) ? (1 << ImGuiAxis_X) : 0x00) | ((size.y == 0.0f) ? (1 << ImGuiAxis_Y) : 0x00); if (size.x <= 0.0f) size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too many issues) if (size.y <= 0.0f) @@ -7371,7 +7378,7 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags) // for different windows of the hierarchy. Possibly need a Hash(Current+Flags) ==> (Timer) cache. // We can implement this for _Stationary because the data is linked to HoveredWindow rather than CurrentWindow. if (flags & ImGuiHoveredFlags_ForTooltip) - flags |= g.Style.HoverFlagsForTooltipMouse; + flags = ApplyHoverFlagsForTooltip(flags, g.Style.HoverFlagsForTooltipMouse); if ((flags & ImGuiHoveredFlags_Stationary) != 0 && g.HoverWindowUnlockedStationaryId != ref_window->ID) return false; From 8db02ef8df45381117f5b7271e68aee43e17e414 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 16 Oct 2023 21:33:51 +0200 Subject: [PATCH 05/12] Tables: Fixed an issue with ScrollX enabled where an extraneous draw command would be created. Randomly found while deep-diving into #6765. ContentMaxXHeadersUsed has been set to max since the dawn of tables, which contradict the intent of passing zero-width to ItemSize(). The ItemSize code allowed SameLine() to operate, but this mistake setting ContentMaxXHeadersUsed would make right-most visible column in a ScrollX set incorrectly use a draw command due to header claiming whole column width. --- docs/CHANGELOG.txt | 3 ++- imgui_tables.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d8060aba..2f8ef3d0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -109,7 +109,8 @@ Other changes: - Fixed bottom-most and right-most outer border offset by one. (#6765, #3752) [@v-ein] - Fixed top-most outer border being drawn with both TableBorderLight and TableBorderStrong in some situations, causing the earlier to be visible underneath when alpha is not 1.0f. - - fixed right-clicking right-most section (past right-most column) from highlighting a column. + - Fixed right-clicking right-most section (past right-most column) from highlighting a column. + - Fixed an issue with ScrollX enabled where an extraneous draw command would be created. - TabBar: Fixed position of unsaved document marker (ImGuiTabItemFlags_UnsavedDocument) which was accidentally offset in 1.89.9. (#6862) [@alektron] - Fonts: 'float size_pixels' passed to AddFontXXX() functions is now rounded to lowest integer. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index e028376d..fac9b05f 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -3015,11 +3015,14 @@ void ImGui::TableHeader(const char* label) // Calculate ideal size for sort order arrow float w_arrow = 0.0f; float w_sort_text = 0.0f; + bool sort_arrow = false; char sort_order_suf[4] = ""; const float ARROW_SCALE = 0.65f; if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort)) { w_arrow = ImTrunc(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x); + if (column->SortOrder != -1) + sort_arrow = true; if (column->SortOrder > 0) { ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf), "%d", column->SortOrder + 1); @@ -3027,9 +3030,9 @@ void ImGui::TableHeader(const char* label) } } - // We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considering for merging. + // We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considered for merging. float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow; - column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, column->WorkMaxX); + column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, sort_arrow ? cell_r.Max.x : ImMin(max_pos_x, cell_r.Max.x)); column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x); // Keep header highlighted when context menu is open. From a8bdbfddf95ee1a16e89677e3fd29fe93863242c Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 16 Oct 2023 21:41:36 +0200 Subject: [PATCH 06/12] Tables: Fixed top-most and left-most outer border overlapping inner clip-rect when scrolling. (#6765) --- docs/CHANGELOG.txt | 1 + imgui_tables.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2f8ef3d0..17bfd97e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -107,6 +107,7 @@ Other changes: so a scrolling table can contribute to initial window size. (#6510) - Fixed subtle drawing overlap between borders in some situations. - Fixed bottom-most and right-most outer border offset by one. (#6765, #3752) [@v-ein] + - Fixed top-most and left-most outer border overlapping inner clip-rect when scrolling. (#6765) - Fixed top-most outer border being drawn with both TableBorderLight and TableBorderStrong in some situations, causing the earlier to be visible underneath when alpha is not 1.0f. - Fixed right-clicking right-most section (past right-most column) from highlighting a column. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index fac9b05f..3d8d3cff 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -445,6 +445,18 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG temp_data->HostBackupItemWidthStackSize = outer_window->DC.ItemWidthStack.Size; inner_window->DC.PrevLineSize = inner_window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); + // Make left and top borders not overlap our contents by offsetting HostClipRect (#6765) + // (we normally shouldn't alter HostClipRect as we rely on TableMergeDrawChannels() expanding non-clipped column toward the + // limits of that rectangle, in order for ImDrawListSplitter::Merge() to merge the draw commands. However since the overlap + // problem only affect scrolling tables in this case we can get away with doing it without extra cost). + if (inner_window != outer_window) + { + if (flags & ImGuiTableFlags_BordersOuterV) + table->HostClipRect.Min.x = ImMin(table->HostClipRect.Min.x + TABLE_BORDER_SIZE, table->HostClipRect.Max.x); + if (flags & ImGuiTableFlags_BordersOuterH) + table->HostClipRect.Min.y = ImMin(table->HostClipRect.Min.y + TABLE_BORDER_SIZE, table->HostClipRect.Max.y); + } + // Padding and Spacing // - None ........Content..... Pad .....Content........ // - PadOuter | Pad ..Content..... Pad .....Content.. Pad | @@ -1149,7 +1161,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) table->InnerClipRect.Max.x = ImMin(table->InnerClipRect.Max.x, unused_x1); } table->InnerWindow->ParentWorkRect = table->WorkRect; - table->BorderX1 = table->InnerClipRect.Min.x + ((table->Flags & ImGuiTableFlags_BordersOuterV) ? 1.0f : 0.0f); + table->BorderX1 = table->InnerClipRect.Min.x; table->BorderX2 = table->InnerClipRect.Max.x; // Setup window's WorkRect.Max.y for GetContentRegionAvail(). Other values will be updated in each TableBeginCell() call. From 99913b505156dbe480047ea14f90235118eac7c6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 16 Oct 2023 22:21:29 +0200 Subject: [PATCH 07/12] Internals: added IsKeyChordPressed() for consistency. --- imgui.cpp | 25 +++++++++++++++---------- imgui_internal.h | 4 ++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e25c78c1..b142fbe3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9141,16 +9141,10 @@ void ImGui::SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags) } } -bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags) +// This is equivalent to comparing KeyMods + doing a IsKeyPressed() +bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags) { ImGuiContext& g = *GImGui; - - // When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any. - if ((flags & ImGuiInputFlags_RouteMask_) == 0) - flags |= ImGuiInputFlags_RouteFocused; - if (!SetShortcutRouting(key_chord, owner_id, flags)) - return false; - if (key_chord & ImGuiMod_Shortcut) key_chord = ConvertShortcutMod(key_chord); ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_); @@ -9161,11 +9155,22 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_); if (key == ImGuiKey_None) key = ConvertSingleModFlagToKey(&g, mods); - if (!IsKeyPressed(key, owner_id, (flags & (ImGuiInputFlags_Repeat | (ImGuiInputFlags)ImGuiInputFlags_RepeatRateMask_)))) return false; - IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function! + return true; +} +bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags) +{ + // When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any. + if ((flags & ImGuiInputFlags_RouteMask_) == 0) + flags |= ImGuiInputFlags_RouteFocused; + if (!SetShortcutRouting(key_chord, owner_id, flags)) + return false; + + if (!IsKeyChordPressed(key_chord, owner_id, flags)) + return false; + IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function! return true; } diff --git a/imgui_internal.h b/imgui_internal.h index 520d89f0..d387bfbe 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3131,6 +3131,10 @@ namespace ImGui // - Route is granted to a single owner. When multiple requests are made we have policies to select the winning route. // - Multiple read sites may use the same owner id and will all get the granted route. // - For routing: when owner_id is 0 we use the current Focus Scope ID as a default owner in order to identify our location. + // - TL;DR; + // - IsKeyChordPressed() compares mods + call IsKeyPressed() -> function has no side-effect. + // - Shortcut() submits a route then if currently can be routed calls IsKeyChordPressed() -> function has (desirable) side-effects. + IMGUI_API bool IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags = 0); IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0); IMGUI_API bool SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0); IMGUI_API bool TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id); From d6d00b4fcf03a489147decbbf07f9d744ce183d4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Oct 2023 13:44:23 +0200 Subject: [PATCH 08/12] Moved BeginChild() above BeginChildEx() as it is more readable. Misc shallow tidying up. Should be a no-op. --- imgui.cpp | 43 ++++++++++++++++++------------------------- imgui.h | 13 ++++++------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b142fbe3..b562590c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2479,11 +2479,9 @@ void ImGuiStorage::SetInt(ImGuiID key, int val) { ImGuiStoragePair* it = LowerBound(Data, key); if (it == Data.end() || it->key != key) - { Data.insert(it, ImGuiStoragePair(key, val)); - return; - } - it->val_i = val; + else + it->val_i = val; } void ImGuiStorage::SetBool(ImGuiID key, bool val) @@ -2495,22 +2493,18 @@ void ImGuiStorage::SetFloat(ImGuiID key, float val) { ImGuiStoragePair* it = LowerBound(Data, key); if (it == Data.end() || it->key != key) - { Data.insert(it, ImGuiStoragePair(key, val)); - return; - } - it->val_f = val; + else + it->val_f = val; } void ImGuiStorage::SetVoidPtr(ImGuiID key, void* val) { ImGuiStoragePair* it = LowerBound(Data, key); if (it == Data.end() || it->key != key) - { Data.insert(it, ImGuiStoragePair(key, val)); - return; - } - it->val_p = val; + else + it->val_p = val; } void ImGuiStorage::SetAllInt(int v) @@ -5420,11 +5414,22 @@ ImVec2 ImGui::GetItemRectSize() return g.LastItemData.Rect.GetSize(); } +bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) +{ + ImGuiWindow* window = GetCurrentWindow(); + return BeginChildEx(str_id, window->GetID(str_id), size_arg, border, extra_flags); +} + +bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) +{ + IM_ASSERT(id != 0); + return BeginChildEx(NULL, id, size_arg, border, extra_flags); +} + bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags) { ImGuiContext& g = *GImGui; ImGuiWindow* parent_window = g.CurrentWindow; - flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow; flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag @@ -5473,18 +5478,6 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b return ret; } -bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) -{ - ImGuiWindow* window = GetCurrentWindow(); - return BeginChildEx(str_id, window->GetID(str_id), size_arg, border, extra_flags); -} - -bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) -{ - IM_ASSERT(id != 0); - return BeginChildEx(NULL, id, size_arg, border, extra_flags); -} - void ImGui::EndChild() { ImGuiContext& g = *GImGui; diff --git a/imgui.h b/imgui.h index 164401cd..008e665e 100644 --- a/imgui.h +++ b/imgui.h @@ -2346,9 +2346,9 @@ struct ImGuiStorage { ImGuiID key; union { int val_i; float val_f; void* val_p; }; - ImGuiStoragePair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; } - ImGuiStoragePair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; } - ImGuiStoragePair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; } + ImGuiStoragePair(ImGuiID _key, int _val) { key = _key; val_i = _val; } + ImGuiStoragePair(ImGuiID _key, float _val) { key = _key; val_f = _val; } + ImGuiStoragePair(ImGuiID _key, void* _val) { key = _key; val_p = _val; } }; ImVector Data; @@ -2375,11 +2375,10 @@ struct ImGuiStorage IMGUI_API float* GetFloatRef(ImGuiID key, float default_val = 0.0f); IMGUI_API void** GetVoidPtrRef(ImGuiID key, void* default_val = NULL); - // Use on your own storage if you know only integer are being stored (open/close all tree nodes) - IMGUI_API void SetAllInt(int val); - - // For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once. + // Advanced: for quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once. IMGUI_API void BuildSortByKey(); + // Obsolete: use on your own storage if you know only integer are being stored (open/close all tree nodes) + IMGUI_API void SetAllInt(int val); }; // Helper: Manually clip large list of items. From 9a5da23553bccaa138651f0410bcc8c5c05cc255 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Oct 2023 14:18:48 +0200 Subject: [PATCH 09/12] Changelog formatting --- docs/CHANGELOG.txt | 60 +++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 17bfd97e..aa00b69e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -67,17 +67,16 @@ Breaking changes: Other changes: -- Tooltips: made using SetItemTooltip()/IsItemHovered(ImGuiHoveredFlags_ForTooltip) defaults to - activate tooltips on disabled items. This is done by adding ImGuiHoveredFlags_AllowWhenDisabled - to the default value of style.HoverFlagsForTooltipMouse/HoverFlagsForTooltipNav. (#1485) -- Tooltips: made is possible to combine ImGuiHoveredFlags_ForTooltip with a ImGuiHoveredFlags_DelayXXX - override. (#1485) - Nav: Tabbing always enable nav highlight when ImGuiConfigFlags_NavEnableKeyboard is set. Previously was inconsistent and only enabled when stepping through a non-input item. (#6802, #3092, #5759, #787) -- Separator(): Altered end-points to use more standard boundaries. (#205, #4787, #1643) - - Left position is always current cursor X position. - - Right position is always work-rect rightmost edge. +- Windows: + - Popups: clarified meaning of 'p_open != NULL' in BeginPopupModal() + set back user value + to false when popup is closed in ways other than clicking the close button. (#6900) +- Separators: + - Altered end-points to use more standard boundaries. (#205, #4787, #1643) + Left position is always current cursor X position. + Right position is always work-rect rightmost edge. - Effectively means that: - A separator in the root of a window will end up a little more distant from edges than previously (essentially following WindowPadding instead of clipping edges). @@ -89,13 +88,17 @@ Other changes: - Mostly legacy behavior when used inside old Columns(), as we favored that idiom back then, only different is left position follows indentation level, to match calling a Separator() inside or outside Columns(). -- Popups: clarified meaning of 'p_open != NULL' in BeginPopupModal() + set back user value - to false when popup is closed in ways other than clicking the close button. (#6900) -- Drag and Drop: Rework drop target highlight: reduce rectangle to its visible portion, and - then expand slightly. A full rectangle is always visible and it may protrude slightly. (#4281, #3272) -- Drag and Drop: Fixed submitting a tooltip from drop target location when using AcceptDragDropPayload() - with ImGuiDragDropFlags_AcceptNoPreviewTooltip and submitting a tooltip manually. -- TreeNode: Added ImGuiTreeNodeFlags_SpanAllColumns for use in tables. (#3151, #3565, #2451, #2438) +- Tooltips: + - Made using SetItemTooltip()/IsItemHovered(ImGuiHoveredFlags_ForTooltip) defaults to + activate tooltips on disabled items. This is done by adding ImGuiHoveredFlags_AllowWhenDisabled + to the default value of style.HoverFlagsForTooltipMouse/HoverFlagsForTooltipNav. (#1485) + - Made is possible to combine ImGuiHoveredFlags_ForTooltip with a ImGuiHoveredFlags_DelayXXX + override. (#1485) +- Drag and Drop: + - Reworked drop target highlight: reduce rectangle to its visible portion, and + then expand slightly. A full rectangle is always visible and it may protrude slightly. (#4281, #3272) + - Fixed submitting a tooltip from drop target location when using AcceptDragDropPayload() + with ImGuiDragDropFlags_AcceptNoPreviewTooltip and submitting a tooltip manually. - Tables: - Added angled headers support. You need to set ImGuiTableColumnFlags_AngledHeader on selected columns and call TableAngledHeadersRow(). Added style.TableAngledHeadersAngle style option. @@ -112,15 +115,15 @@ Other changes: in some situations, causing the earlier to be visible underneath when alpha is not 1.0f. - Fixed right-clicking right-most section (past right-most column) from highlighting a column. - Fixed an issue with ScrollX enabled where an extraneous draw command would be created. +- Menus: + - Menus: Fixed a bug where activating an item in a child-menu and dragging mouse over the + parent-menu would erroneously close the child-menu. (Regression from 1.88). (#6869) + - MenuBar: Fixed an issue where layouting an item in the menu-bar would erroneously + register contents size in a way that would affect the scrolling layer. + Was most often noticable when using an horizontal scrollbar. (#6789) +- TreeNode: Added ImGuiTreeNodeFlags_SpanAllColumns for use in tables. (#3151, #3565, #2451, #2438) - TabBar: Fixed position of unsaved document marker (ImGuiTabItemFlags_UnsavedDocument) which was accidentally offset in 1.89.9. (#6862) [@alektron] -- Fonts: 'float size_pixels' passed to AddFontXXX() functions is now rounded to lowest integer. - This is because our layout/font system currently doesn't fully support non-integer sizes. Until - it does, this has been a common pitfall leading to more or less subtle issues. (#3164, #3309, #6800) -- Fonts: Better assert during load when passing truncated font data or wrong data size. (#6822) -- Fonts: Ensure calling AddFontXXX function doesn't invalidates ImFont's ConfigData pointers - prior to building again. (#6825) -- Fonts, imgui_freetype: Fixed a warning and leak in IMGUI_ENABLE_FREETYPE_LUNASVG support. (#6842, #6591) - InputTextMultiline: Fixed a crash pressing Down on last empty line of a multiline buffer. (regression from 1.89.2, only happened in some states). (#6783, #6000) - InputTextMultiline: Fixed Tabbing cycle leading to a situation where Enter key wouldn't @@ -129,11 +132,14 @@ Other changes: to SameLine() followed by manual cursor manipulation. - BeginCombo(): Added ImGuiComboFlags_WidthFitPreview flag. (#6881) [@mpv-enjoyer] - BeginListBox(): Fixed not consuming SetNextWindowXXX data when returning false. -- Menus: Fixed a bug where activating an item in a child-menu and dragging mouse over the - parent-menu would erroneously close the child-menu. (Regression from 1.88). (#6869) -- MenuBar: Fixed an issue where layouting an item in the menu-bar would erroneously - register contents size in a way that would affect the scrolling layer. - Was most often noticable when using an horizontal scrollbar. (#6789) +- Fonts: + - Arument 'float size_pixels' passed to AddFontXXX() functions is now rounded to lowest integer. + This is because our layout/font system currently doesn't fully support non-integer sizes. Until + it does, this has been a common pitfall leading to more or less subtle issues. (#3164, #3309, #6800) + - Better assert during load when passing truncated font data or wrong data size. (#6822) + - Ensure calling AddFontXXX function doesn't invalidates ImFont's ConfigData pointers + prior to building again. (#6825) + - imgui_freetype: Fixed a warning and leak in IMGUI_ENABLE_FREETYPE_LUNASVG support. (#6842, #6591) - Misc: Most text functions also treat "%.*s" (along with "%s") specially to avoid formatting. (#3466, #6846) - IO: Add extra keys to ImGuiKey enum: ImGuiKey_F13 to ImGuiKey_F24. (#6891, #4921) - IO: Add extra keys to ImGuiKey enum: ImGuiKey_AppBack, ImGuiKey_AppForward. (#4921) From 56f7e853beda2e54b1289223a372f3fc67ba3486 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 17 Oct 2023 17:39:50 +0200 Subject: [PATCH 10/12] Demo: expose more Combo flags + misc tidying up. --- imgui.cpp | 30 ++++++++++++++++-------------- imgui_demo.cpp | 14 +++++++++++++- imgui_internal.h | 6 +++--- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b562590c..df3bf112 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5452,7 +5452,9 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b const float backup_border_size = g.Style.ChildBorderSize; if (!border) g.Style.ChildBorderSize = 0.0f; - bool ret = Begin(temp_window_name, NULL, flags); + + // Begin into window + const bool ret = Begin(temp_window_name, NULL, flags); g.Style.ChildBorderSize = backup_border_size; ImGuiWindow* child_window = g.CurrentWindow; @@ -5464,7 +5466,7 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b parent_window->DC.CursorPos = child_window->Pos; // Process navigation-in immediately so NavInit can run on first frame - // Can enter a child if (A) it has navigatable items or (B) it can be scrolled. + // Can enter a child if (A) it has navigable items or (B) it can be scrolled. const ImGuiID temp_id_for_activation = ImHashStr("##Child", 0, id); if (g.ActiveId == temp_id_for_activation) ClearActiveID(); @@ -5481,26 +5483,26 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b void ImGui::EndChild() { ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; + ImGuiWindow* child_window = g.CurrentWindow; IM_ASSERT(g.WithinEndChild == false); - IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() calls + IM_ASSERT(child_window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() calls g.WithinEndChild = true; - ImVec2 child_size = window->Size; + ImVec2 child_size = child_window->Size; End(); - if (window->BeginCount == 1) + if (child_window->BeginCount == 1) { ImGuiWindow* parent_window = g.CurrentWindow; ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + child_size); ItemSize(child_size); - if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavWindowHasScrollY) && !(window->Flags & ImGuiWindowFlags_NavFlattened)) + if ((child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavWindowHasScrollY) && !(child_window->Flags & ImGuiWindowFlags_NavFlattened)) { - ItemAdd(bb, window->ChildId); - RenderNavHighlight(bb, window->ChildId); + ItemAdd(bb, child_window->ChildId); + RenderNavHighlight(bb, child_window->ChildId); // When browsing a window that has no activable items (scroll only) we keep a highlight on the child (pass g.NavId to trick into always displaying) - if (window->DC.NavLayersActiveMask == 0 && window == g.NavWindow) + if (child_window->DC.NavLayersActiveMask == 0 && child_window == g.NavWindow) RenderNavHighlight(ImRect(bb.Min - ImVec2(2, 2), bb.Max + ImVec2(2, 2)), g.NavId, ImGuiNavHighlightFlags_TypeThin); } else @@ -5509,10 +5511,10 @@ void ImGui::EndChild() ItemAdd(bb, 0); // But when flattened we directly reach items, adjust active layer mask accordingly - if (window->Flags & ImGuiWindowFlags_NavFlattened) - parent_window->DC.NavLayersActiveMaskNext |= window->DC.NavLayersActiveMaskNext; + if (child_window->Flags & ImGuiWindowFlags_NavFlattened) + parent_window->DC.NavLayersActiveMaskNext |= child_window->DC.NavLayersActiveMaskNext; } - if (g.HoveredWindow == window) + if (g.HoveredWindow == child_window) g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow; } g.WithinEndChild = false; @@ -6314,7 +6316,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->IDStack.push_back(window->ID); // Add to stack - // We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow() g.CurrentWindow = window; ImGuiWindowStackData window_stack_data; window_stack_data.Window = window; @@ -6332,6 +6333,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) } // Add to focus scope stack + // We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow() PushFocusScope(window->ID); window->NavRootFocusScopeId = g.CurrentFocusScopeId; g.CurrentWindow = NULL; diff --git a/imgui_demo.cpp b/imgui_demo.cpp index b386d8a6..c213c43e 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1197,6 +1197,14 @@ static void ShowDemoWindowWidgets() if (ImGui::CheckboxFlags("ImGuiComboFlags_WidthFitPreview", &flags, ImGuiComboFlags_WidthFitPreview)) flags &= ~ImGuiComboFlags_NoPreview; + // Override default popup height + if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightSmall", &flags, ImGuiComboFlags_HeightSmall)) + flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightSmall); + if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightRegular", &flags, ImGuiComboFlags_HeightRegular)) + flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightRegular); + if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightLargest", &flags, ImGuiComboFlags_HeightLargest)) + flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightLargest); + // Using the generic BeginCombo() API, you have full control over how to display the combo contents. // (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively // stored in the object itself, etc.) @@ -1218,6 +1226,10 @@ static void ShowDemoWindowWidgets() ImGui::EndCombo(); } + ImGui::Spacing(); + ImGui::SeparatorText("One-liner variants"); + HelpMarker("Flags above don't apply to this section."); + // Simplified one-liner Combo() API, using values packed in a single constant string // This is a convenience for when the selection set is small and known at compile-time. static int item_current_2 = 0; @@ -6564,7 +6576,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) "Right-click to open edit options menu."); ImGui::BeginChild("##colors", ImVec2(0, 0), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar | ImGuiWindowFlags_NavFlattened); - ImGui::PushItemWidth(-160); + ImGui::PushItemWidth(ImGui::GetFontSize() * -12); for (int i = 0; i < ImGuiCol_COUNT; i++) { const char* name = ImGui::GetStyleColorName(i); diff --git a/imgui_internal.h b/imgui_internal.h index d387bfbe..fcd41508 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1254,9 +1254,9 @@ struct IMGUI_API ImGuiStackSizes // Data saved for each window pushed into the stack struct ImGuiWindowStackData { - ImGuiWindow* Window; - ImGuiLastItemData ParentLastItemDataBackup; - ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting + ImGuiWindow* Window; + ImGuiLastItemData ParentLastItemDataBackup; + ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting }; struct ImGuiShrinkWidthItem From f8dc03d7022a00156cef3e4d228774289d9178df Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 18 Oct 2023 16:36:35 +0200 Subject: [PATCH 11/12] Windows: Can also auto-resize by double-clicking lower-left resize grip (not only lower-right one). --- 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 aa00b69e..b63338bf 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -73,6 +73,7 @@ Other changes: - Windows: - Popups: clarified meaning of 'p_open != NULL' in BeginPopupModal() + set back user value to false when popup is closed in ways other than clicking the close button. (#6900) + - Can also auto-resize by double-clicking lower-left resize grip (not only lower-right one). - Separators: - Altered end-points to use more standard boundaries. (#205, #4787, #1643) Left position is always current cursor X position. diff --git a/imgui.cpp b/imgui.cpp index df3bf112..998f53b4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5884,7 +5884,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s if (hovered || held) g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; - if (held && g.IO.MouseClickedCount[0] == 2 && resize_grip_n == 0) + if (held && g.IO.MouseClickedCount[0] == 2) { // Manual auto-fit when double-clicking size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit); From 1b9cb52d7ba498aa17fa4d7c45dc9746378180d0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 18 Oct 2023 18:39:20 +0200 Subject: [PATCH 12/12] BeginChild(): rename parameters to reduce diff of upcoming patches. Should be a no-op. --- imgui.cpp | 20 ++++++++++---------- imgui.h | 4 ++-- imgui_internal.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 998f53b4..b753b61d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5414,24 +5414,24 @@ ImVec2 ImGui::GetItemRectSize() return g.LastItemData.Rect.GetSize(); } -bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) +bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags window_flags) { - ImGuiWindow* window = GetCurrentWindow(); - return BeginChildEx(str_id, window->GetID(str_id), size_arg, border, extra_flags); + ImGuiID id = GetCurrentWindow()->GetID(str_id); + return BeginChildEx(str_id, id, size_arg, border, window_flags); } -bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) +bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags window_flags) { IM_ASSERT(id != 0); - return BeginChildEx(NULL, id, size_arg, border, extra_flags); + return BeginChildEx(NULL, id, size_arg, border, window_flags); } -bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags) +bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags window_flags) { ImGuiContext& g = *GImGui; ImGuiWindow* parent_window = g.CurrentWindow; - flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow; - flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag + window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow; + window_flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag // Size const ImVec2 content_avail = GetContentRegionAvail(); @@ -5454,7 +5454,7 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b g.Style.ChildBorderSize = 0.0f; // Begin into window - const bool ret = Begin(temp_window_name, NULL, flags); + const bool ret = Begin(temp_window_name, NULL, window_flags); g.Style.ChildBorderSize = backup_border_size; ImGuiWindow* child_window = g.CurrentWindow; @@ -5470,7 +5470,7 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b const ImGuiID temp_id_for_activation = ImHashStr("##Child", 0, id); if (g.ActiveId == temp_id_for_activation) ClearActiveID(); - if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavWindowHasScrollY)) + if (g.NavActivateId == id && !(window_flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavWindowHasScrollY)) { FocusWindow(child_window); NavInitWindow(child_window, false); diff --git a/imgui.h b/imgui.h index 008e665e..be5283c0 100644 --- a/imgui.h +++ b/imgui.h @@ -343,8 +343,8 @@ namespace ImGui // [Important: due to legacy reason, this is inconsistent with most other functions such as BeginMenu/EndMenu, // BeginPopup/EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function // returned true. Begin and BeginChild are the only odd ones out. Will be fixed in a future update.] - IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0, 0), bool border = false, ImGuiWindowFlags flags = 0); - IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0, 0), bool border = false, ImGuiWindowFlags flags = 0); + IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0, 0), bool border = false, ImGuiWindowFlags window_flags = 0); + IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0, 0), bool border = false, ImGuiWindowFlags window_flags = 0); IMGUI_API void EndChild(); // Windows Utilities diff --git a/imgui_internal.h b/imgui_internal.h index fcd41508..16532fb4 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3007,7 +3007,7 @@ namespace ImGui IMGUI_API void LogSetNextTextDecoration(const char* prefix, const char* suffix); // Popups, Modals, Tooltips - IMGUI_API bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags); + IMGUI_API bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags window_flags); IMGUI_API void OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags = ImGuiPopupFlags_None); IMGUI_API void ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup); IMGUI_API void ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup);