Skip to content

Commit 34a0bc4

Browse files
committed
BeginChild: Added ImGuiChildFlags_AlwaysUseWindowPadding, obsoleted ImGuiWindowFlags_AlwaysUseWindowPadding. (ocornut#462, (toward ocornut#1666, ocornut#1496, ocornut#1395, ocornut#1710)
(bonus: will also eventually free a window flag)
1 parent 7713c29 commit 34a0bc4

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

docs/CHANGELOG.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ Breaking changes:
5151
After: BeginChild("Name", size, ImGuiChildFlags_Border)
5252
Before: BeginChild("Name", size, false)
5353
After: BeginChild("Name", size) or BeginChild("Name", 0) or BeginChild("Name", size, ImGuiChildFlags_None)
54-
Kept inline redirection function with strongly typed bool versions (will obsolete).
54+
Kept inline redirection function (will obsolete later) so existing code will work.
55+
- BeginChild(): Added child-flag ImGuiChildFlags_AlwaysUseWindowPadding as a replacement for
56+
the window-flag ImGuiWindowFlags_AlwaysUseWindowPadding: the feature only ever made sense
57+
for use with BeginChild() anyhow, passing it to Begin() had no effect. Now that we accept
58+
child-flags we are moving it there. (#462)
59+
Before: BeginChild("Name", size, 0, ImGuiWindowFlags_AlwaysUseWindowPadding);
60+
After: BeginChild("Name", size, ImGuiChildFlags_AlwaysUseWindowPadding, 0);
61+
Kept inline redirection enum (will obsolete later) so existing code will work.
5562
- Debug Tools: Renamed ShowStackToolWindow() ("Stack Tool") to ShowIDStackToolWindow() ("ID Stack Tool"),
5663
as earlier name was misleading. Kept inline redirection function. (#4631)
5764
- IO: Removed io.MetricsActiveAllocations introduced in 1.63, was displayed in Metrics and unlikely to

imgui.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ CODE
429429
- new: BeginChild("Name", size, ImGuiChildFlags_Border)
430430
- old: BeginChild("Name", size, false)
431431
- new: BeginChild("Name", size) or BeginChild("Name", 0) or BeginChild("Name", size, ImGuiChildFlags_None)
432+
- 2023/11/02 (1.90.0) - BeginChild: added child-flag ImGuiChildFlags_AlwaysUseWindowPadding as a replacement for the window-flag ImGuiWindowFlags_AlwaysUseWindowPadding: the feature only ever made sense for BeginChild() anyhow.
433+
- old: BeginChild("Name", size, 0, ImGuiWindowFlags_AlwaysUseWindowPadding);
434+
- new: BeginChild("Name", size, ImGuiChildFlags_AlwaysUseWindowPadding, 0);
432435
- 2023/09/27 (1.90.0) - io: removed io.MetricsActiveAllocations introduced in 1.63. Same as 'g.DebugMemAllocCount - g.DebugMemFreeCount' (still displayed in Metrics, unlikely to be accessed by end-user).
433436
- 2023/09/26 (1.90.0) - debug tools: Renamed ShowStackToolWindow() ("Stack Tool") to ShowIDStackToolWindow() ("ID Stack Tool"), as earlier name was misleading. Kept inline redirection function. (#4631)
434437
- 2023/09/15 (1.90.0) - ListBox, Combo: changed signature of "name getter" callback in old one-liner ListBox()/Combo() apis. kept inline redirection function (will obsolete).
@@ -5419,6 +5422,8 @@ ImVec2 ImGui::GetItemRectSize()
54195422
return g.LastItemData.Rect.GetSize();
54205423
}
54215424

5425+
// Prior to v1.90 2023/10/16, the BeginChild() function took a 'bool border = false' parameter instead of 'ImGuiChildFlags child_flags = 0'.
5426+
// ImGuiChildFlags_Border is defined as always == 1 in order to allow old code passing 'true'.
54225427
bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, ImGuiChildFlags child_flags, ImGuiWindowFlags window_flags)
54235428
{
54245429
ImGuiID id = GetCurrentWindow()->GetID(str_id);
@@ -5436,10 +5441,23 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, I
54365441
ImGuiWindow* parent_window = g.CurrentWindow;
54375442
IM_ASSERT(id != 0);
54385443

5439-
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow;
5440-
window_flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag
5444+
// Sanity check as it is likely that some user will accidentally pass ImGuiWindowFlags into the ImGuiChildFlags argument.
5445+
const ImGuiChildFlags ImGuiChildFlags_SupportedMask_ = ImGuiChildFlags_Border | ImGuiChildFlags_AlwaysUseWindowPadding;
5446+
IM_UNUSED(ImGuiChildFlags_SupportedMask_);
5447+
IM_ASSERT((child_flags & ~ImGuiChildFlags_SupportedMask_) == 0 && "Illegal ImGuiChildFlags value. Did you pass ImGuiWindowFlags values instead of ImGuiChildFlags?");
5448+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
5449+
if (window_flags & ImGuiWindowFlags_AlwaysUseWindowPadding)
5450+
child_flags |= ImGuiChildFlags_AlwaysUseWindowPadding;
5451+
#endif
5452+
5453+
window_flags |= ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings;
5454+
window_flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag
5455+
5456+
// Forward child flags
5457+
g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasChildFlags;
5458+
g.NextWindowData.ChildFlags = child_flags;
54415459

5442-
// Size
5460+
// Forward size
54435461
const ImVec2 content_avail = GetContentRegionAvail();
54445462
ImVec2 size = ImTrunc(size_arg);
54455463
if (size.x <= 0.0f)
@@ -5538,7 +5556,7 @@ bool ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags ext
55385556
PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding);
55395557
PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize);
55405558
PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding);
5541-
bool ret = BeginChild(id, size, ImGuiChildFlags_Border, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags);
5559+
bool ret = BeginChild(id, size, ImGuiChildFlags_Border | ImGuiChildFlags_AlwaysUseWindowPadding, ImGuiWindowFlags_NoMove | extra_flags);
55425560
PopStyleVar(3);
55435561
PopStyleColor();
55445562
return ret;
@@ -6328,6 +6346,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
63286346
{
63296347
UpdateWindowInFocusOrderList(window, window_just_created, flags);
63306348
window->Flags = (ImGuiWindowFlags)flags;
6349+
window->ChildFlags = (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasChildFlags) ? g.NextWindowData.ChildFlags : 0;
63316350
window->LastFrameActive = current_frame;
63326351
window->LastTimeActive = (float)g.Time;
63336352
window->BeginOrderWithinParent = 0;
@@ -6503,7 +6522,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
65036522
else
65046523
window->WindowBorderSize = ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupBorderSize : style.WindowBorderSize;
65056524
window->WindowPadding = style.WindowPadding;
6506-
if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f)
6525+
if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !(window->ChildFlags & ImGuiChildFlags_AlwaysUseWindowPadding) && window->WindowBorderSize == 0.0f)
65076526
window->WindowPadding = ImVec2(0.0f, (flags & ImGuiWindowFlags_MenuBar) ? style.WindowPadding.y : 0.0f);
65086527

65096528
// Lock menu offset so size calculation can use it as menu-bar windows need a minimum size.

imgui.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,6 @@ enum ImGuiWindowFlags_
994994
ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, // Disable bringing window to front when taking focus (e.g. clicking on it or programmatically giving it focus)
995995
ImGuiWindowFlags_AlwaysVerticalScrollbar= 1 << 14, // Always show vertical scrollbar (even if ContentSize.y < Size.y)
996996
ImGuiWindowFlags_AlwaysHorizontalScrollbar=1<< 15, // Always show horizontal scrollbar (even if ContentSize.x < Size.x)
997-
ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 16, // Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient)
998997
ImGuiWindowFlags_NoNavInputs = 1 << 18, // No gamepad/keyboard navigation within the window
999998
ImGuiWindowFlags_NoNavFocus = 1 << 19, // No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB)
1000999
ImGuiWindowFlags_UnsavedDocument = 1 << 20, // Display a dot next to the title. When used in a tab/docking context, tab is selected when clicking the X + closure is not assumed (will wait for user to stop submitting the tab). Otherwise closure is assumed when pressing the X, so if you keep submitting the tab may reappear at end of tab bar.
@@ -1009,6 +1008,11 @@ enum ImGuiWindowFlags_
10091008
ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup()
10101009
ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal()
10111010
ImGuiWindowFlags_ChildMenu = 1 << 28, // Don't use! For internal use by BeginMenu()
1011+
1012+
// Obsolete names
1013+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
1014+
ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 30, // Obsoleted in 1.90: Use ImGuiChildFlags_AlwaysUseWindowPadding in BeginChild() call.
1015+
#endif
10121016
};
10131017

10141018
// Flags for ImGui::BeginChild()
@@ -1017,6 +1021,7 @@ enum ImGuiChildFlags_
10171021
{
10181022
ImGuiChildFlags_None = 0,
10191023
ImGuiChildFlags_Border = 1 << 0, // Show an outer border and enable WindowPadding. (Important: this is always == 1 for legacy reason)
1024+
ImGuiChildFlags_AlwaysUseWindowPadding = 1 << 1, // Pad with style.WindowPadding even if no border are drawn (no padding by default for non-bordered child windows because it makes more sense)
10201025
};
10211026

10221027
// Flags for ImGui::InputText()

imgui_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ enum ImGuiNextWindowDataFlags_
11611161
ImGuiNextWindowDataFlags_HasFocus = 1 << 5,
11621162
ImGuiNextWindowDataFlags_HasBgAlpha = 1 << 6,
11631163
ImGuiNextWindowDataFlags_HasScroll = 1 << 7,
1164+
ImGuiNextWindowDataFlags_HasChildFlags = 1 << 8,
11641165
};
11651166

11661167
// Storage for SetNexWindow** functions
@@ -1175,6 +1176,7 @@ struct ImGuiNextWindowData
11751176
ImVec2 SizeVal;
11761177
ImVec2 ContentSizeVal;
11771178
ImVec2 ScrollVal;
1179+
ImGuiChildFlags ChildFlags;
11781180
bool CollapsedVal;
11791181
ImRect SizeConstraintRect;
11801182
ImGuiSizeCallback SizeCallback;
@@ -2394,6 +2396,7 @@ struct IMGUI_API ImGuiWindow
23942396
char* Name; // Window name, owned by the window.
23952397
ImGuiID ID; // == ImHashStr(Name)
23962398
ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_
2399+
ImGuiChildFlags ChildFlags; // Set when window is a child window. See enum ImGuiChildFlags_
23972400
ImGuiViewportP* Viewport; // Always set in Begin(). Inactive windows may have a NULL value here if their viewport was discarded.
23982401
ImVec2 Pos; // Position (always rounded-up to nearest pixel)
23992402
ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)

0 commit comments

Comments
 (0)