mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Internals: BeginChildEx tweaks.
This commit is contained in:
parent
7b2662d245
commit
0146f4b456
40
imgui.cpp
40
imgui.cpp
@ -891,6 +891,8 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* ini
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags);
|
||||
|
||||
static void NavUpdate();
|
||||
static void NavUpdateWindowing();
|
||||
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)
|
||||
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
||||
}
|
||||
|
||||
static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
|
||||
static bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* parent_window = ImGui::GetCurrentWindow();
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
|
||||
ImGuiWindow* parent_window = g.CurrentWindow;
|
||||
|
||||
flags |= ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
|
||||
flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag
|
||||
|
||||
const ImVec2 content_avail = ImGui::GetContentRegionAvail();
|
||||
// Size
|
||||
const ImVec2 content_avail = GetContentRegionAvail();
|
||||
ImVec2 size = ImFloor(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 much issues)
|
||||
if (size.y <= 0.0f)
|
||||
size.y = ImMax(content_avail.y + size.y, 4.0f);
|
||||
SetNextWindowSize(size);
|
||||
|
||||
const float backup_border_size = g.Style.ChildBorderSize;
|
||||
if (!border)
|
||||
g.Style.ChildBorderSize = 0.0f;
|
||||
flags |= extra_flags;
|
||||
|
||||
// Name
|
||||
char title[256];
|
||||
if (name)
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s", parent_window->Name, name);
|
||||
else
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", parent_window->Name, id);
|
||||
|
||||
ImGui::SetNextWindowSize(size);
|
||||
bool ret = ImGui::Begin(title, NULL, flags);
|
||||
ImGuiWindow* child_window = ImGui::GetCurrentWindow();
|
||||
child_window->ChildId = id;
|
||||
child_window->AutoFitChildAxises = auto_fit_axises;
|
||||
const float backup_border_size = g.Style.ChildBorderSize;
|
||||
if (!border)
|
||||
g.Style.ChildBorderSize = 0.0f;
|
||||
bool ret = Begin(title, NULL, flags);
|
||||
g.Style.ChildBorderSize = backup_border_size;
|
||||
|
||||
ImGuiWindow* child_window = g.CurrentWindow;
|
||||
child_window->ChildId = id;
|
||||
child_window->AutoFitChildAxises = auto_fit_axises;
|
||||
|
||||
// Process navigation-in immediately so NavInit can run on first frame
|
||||
if (!(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayerActiveMask != 0 || child_window->DC.NavHasScroll) && g.NavActivateId == id)
|
||||
if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayerActiveMask != 0 || child_window->DC.NavHasScroll))
|
||||
{
|
||||
ImGui::FocusWindow(child_window);
|
||||
ImGui::NavInitWindow(child_window, false);
|
||||
ImGui::SetActiveID(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
|
||||
FocusWindow(child_window);
|
||||
NavInitWindow(child_window, false);
|
||||
SetActiveID(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
|
||||
g.ActiveIdSource = ImGuiInputSource_Nav;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user