Skip to content

Commit 56f7e85

Browse files
committed
Demo: expose more Combo flags + misc tidying up.
1 parent 9a5da23 commit 56f7e85

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

imgui.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5452,7 +5452,9 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
54525452
const float backup_border_size = g.Style.ChildBorderSize;
54535453
if (!border)
54545454
g.Style.ChildBorderSize = 0.0f;
5455-
bool ret = Begin(temp_window_name, NULL, flags);
5455+
5456+
// Begin into window
5457+
const bool ret = Begin(temp_window_name, NULL, flags);
54565458
g.Style.ChildBorderSize = backup_border_size;
54575459

54585460
ImGuiWindow* child_window = g.CurrentWindow;
@@ -5464,7 +5466,7 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
54645466
parent_window->DC.CursorPos = child_window->Pos;
54655467

54665468
// Process navigation-in immediately so NavInit can run on first frame
5467-
// Can enter a child if (A) it has navigatable items or (B) it can be scrolled.
5469+
// Can enter a child if (A) it has navigable items or (B) it can be scrolled.
54685470
const ImGuiID temp_id_for_activation = ImHashStr("##Child", 0, id);
54695471
if (g.ActiveId == temp_id_for_activation)
54705472
ClearActiveID();
@@ -5481,26 +5483,26 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
54815483
void ImGui::EndChild()
54825484
{
54835485
ImGuiContext& g = *GImGui;
5484-
ImGuiWindow* window = g.CurrentWindow;
5486+
ImGuiWindow* child_window = g.CurrentWindow;
54855487

54865488
IM_ASSERT(g.WithinEndChild == false);
5487-
IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() calls
5489+
IM_ASSERT(child_window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() calls
54885490

54895491
g.WithinEndChild = true;
5490-
ImVec2 child_size = window->Size;
5492+
ImVec2 child_size = child_window->Size;
54915493
End();
5492-
if (window->BeginCount == 1)
5494+
if (child_window->BeginCount == 1)
54935495
{
54945496
ImGuiWindow* parent_window = g.CurrentWindow;
54955497
ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + child_size);
54965498
ItemSize(child_size);
5497-
if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavWindowHasScrollY) && !(window->Flags & ImGuiWindowFlags_NavFlattened))
5499+
if ((child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavWindowHasScrollY) && !(child_window->Flags & ImGuiWindowFlags_NavFlattened))
54985500
{
5499-
ItemAdd(bb, window->ChildId);
5500-
RenderNavHighlight(bb, window->ChildId);
5501+
ItemAdd(bb, child_window->ChildId);
5502+
RenderNavHighlight(bb, child_window->ChildId);
55015503

55025504
// 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)
5503-
if (window->DC.NavLayersActiveMask == 0 && window == g.NavWindow)
5505+
if (child_window->DC.NavLayersActiveMask == 0 && child_window == g.NavWindow)
55045506
RenderNavHighlight(ImRect(bb.Min - ImVec2(2, 2), bb.Max + ImVec2(2, 2)), g.NavId, ImGuiNavHighlightFlags_TypeThin);
55055507
}
55065508
else
@@ -5509,10 +5511,10 @@ void ImGui::EndChild()
55095511
ItemAdd(bb, 0);
55105512

55115513
// But when flattened we directly reach items, adjust active layer mask accordingly
5512-
if (window->Flags & ImGuiWindowFlags_NavFlattened)
5513-
parent_window->DC.NavLayersActiveMaskNext |= window->DC.NavLayersActiveMaskNext;
5514+
if (child_window->Flags & ImGuiWindowFlags_NavFlattened)
5515+
parent_window->DC.NavLayersActiveMaskNext |= child_window->DC.NavLayersActiveMaskNext;
55145516
}
5515-
if (g.HoveredWindow == window)
5517+
if (g.HoveredWindow == child_window)
55165518
g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow;
55175519
}
55185520
g.WithinEndChild = false;
@@ -6314,7 +6316,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
63146316
window->IDStack.push_back(window->ID);
63156317

63166318
// Add to stack
6317-
// We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow()
63186319
g.CurrentWindow = window;
63196320
ImGuiWindowStackData window_stack_data;
63206321
window_stack_data.Window = window;
@@ -6332,6 +6333,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
63326333
}
63336334

63346335
// Add to focus scope stack
6336+
// We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow()
63356337
PushFocusScope(window->ID);
63366338
window->NavRootFocusScopeId = g.CurrentFocusScopeId;
63376339
g.CurrentWindow = NULL;

imgui_demo.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,14 @@ static void ShowDemoWindowWidgets()
11971197
if (ImGui::CheckboxFlags("ImGuiComboFlags_WidthFitPreview", &flags, ImGuiComboFlags_WidthFitPreview))
11981198
flags &= ~ImGuiComboFlags_NoPreview;
11991199

1200+
// Override default popup height
1201+
if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightSmall", &flags, ImGuiComboFlags_HeightSmall))
1202+
flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightSmall);
1203+
if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightRegular", &flags, ImGuiComboFlags_HeightRegular))
1204+
flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightRegular);
1205+
if (ImGui::CheckboxFlags("ImGuiComboFlags_HeightLargest", &flags, ImGuiComboFlags_HeightLargest))
1206+
flags &= ~(ImGuiComboFlags_HeightMask_ & ~ImGuiComboFlags_HeightLargest);
1207+
12001208
// Using the generic BeginCombo() API, you have full control over how to display the combo contents.
12011209
// (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
12021210
// stored in the object itself, etc.)
@@ -1218,6 +1226,10 @@ static void ShowDemoWindowWidgets()
12181226
ImGui::EndCombo();
12191227
}
12201228

1229+
ImGui::Spacing();
1230+
ImGui::SeparatorText("One-liner variants");
1231+
HelpMarker("Flags above don't apply to this section.");
1232+
12211233
// Simplified one-liner Combo() API, using values packed in a single constant string
12221234
// This is a convenience for when the selection set is small and known at compile-time.
12231235
static int item_current_2 = 0;
@@ -6564,7 +6576,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
65646576
"Right-click to open edit options menu.");
65656577

65666578
ImGui::BeginChild("##colors", ImVec2(0, 0), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar | ImGuiWindowFlags_NavFlattened);
6567-
ImGui::PushItemWidth(-160);
6579+
ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
65686580
for (int i = 0; i < ImGuiCol_COUNT; i++)
65696581
{
65706582
const char* name = ImGui::GetStyleColorName(i);

imgui_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,9 @@ struct IMGUI_API ImGuiStackSizes
12541254
// Data saved for each window pushed into the stack
12551255
struct ImGuiWindowStackData
12561256
{
1257-
ImGuiWindow* Window;
1258-
ImGuiLastItemData ParentLastItemDataBackup;
1259-
ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting
1257+
ImGuiWindow* Window;
1258+
ImGuiLastItemData ParentLastItemDataBackup;
1259+
ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting
12601260
};
12611261

12621262
struct ImGuiShrinkWidthItem

0 commit comments

Comments
 (0)