Skip to content

Commit 0146f4b

Browse files
committed
Internals: BeginChildEx tweaks.
1 parent 7b2662d commit 0146f4b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

imgui.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,8 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* ini
891891

892892
namespace ImGui
893893
{
894+
static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags);
895+
894896
static void NavUpdate();
895897
static void NavUpdateWindowing();
896898
static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id);
@@ -5465,45 +5467,47 @@ bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
54655467
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
54665468
}
54675469

5468-
static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
5470+
static bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags)
54695471
{
54705472
ImGuiContext& g = *GImGui;
5471-
ImGuiWindow* parent_window = ImGui::GetCurrentWindow();
5472-
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
5473+
ImGuiWindow* parent_window = g.CurrentWindow;
5474+
5475+
flags |= ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
54735476
flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag
54745477

5475-
const ImVec2 content_avail = ImGui::GetContentRegionAvail();
5478+
// Size
5479+
const ImVec2 content_avail = GetContentRegionAvail();
54765480
ImVec2 size = ImFloor(size_arg);
54775481
const int auto_fit_axises = ((size.x == 0.0f) ? (1 << ImGuiAxis_X) : 0x00) | ((size.y == 0.0f) ? (1 << ImGuiAxis_Y) : 0x00);
54785482
if (size.x <= 0.0f)
54795483
size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too much issues)
54805484
if (size.y <= 0.0f)
54815485
size.y = ImMax(content_avail.y + size.y, 4.0f);
5486+
SetNextWindowSize(size);
54825487

5483-
const float backup_border_size = g.Style.ChildBorderSize;
5484-
if (!border)
5485-
g.Style.ChildBorderSize = 0.0f;
5486-
flags |= extra_flags;
5487-
5488+
// Name
54885489
char title[256];
54895490
if (name)
54905491
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s", parent_window->Name, name);
54915492
else
54925493
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", parent_window->Name, id);
54935494

5494-
ImGui::SetNextWindowSize(size);
5495-
bool ret = ImGui::Begin(title, NULL, flags);
5496-
ImGuiWindow* child_window = ImGui::GetCurrentWindow();
5495+
const float backup_border_size = g.Style.ChildBorderSize;
5496+
if (!border)
5497+
g.Style.ChildBorderSize = 0.0f;
5498+
bool ret = Begin(title, NULL, flags);
5499+
g.Style.ChildBorderSize = backup_border_size;
5500+
5501+
ImGuiWindow* child_window = g.CurrentWindow;
54975502
child_window->ChildId = id;
54985503
child_window->AutoFitChildAxises = auto_fit_axises;
5499-
g.Style.ChildBorderSize = backup_border_size;
55005504

55015505
// Process navigation-in immediately so NavInit can run on first frame
5502-
if (!(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayerActiveMask != 0 || child_window->DC.NavHasScroll) && g.NavActivateId == id)
5506+
if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayerActiveMask != 0 || child_window->DC.NavHasScroll))
55035507
{
5504-
ImGui::FocusWindow(child_window);
5505-
ImGui::NavInitWindow(child_window, false);
5506-
ImGui::SetActiveID(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
5508+
FocusWindow(child_window);
5509+
NavInitWindow(child_window, false);
5510+
SetActiveID(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
55075511
g.ActiveIdSource = ImGuiInputSource_Nav;
55085512
}
55095513

0 commit comments

Comments
 (0)