mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17: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
|
namespace ImGui
|
||||||
{
|
{
|
||||||
|
static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags);
|
||||||
|
|
||||||
static void NavUpdate();
|
static void NavUpdate();
|
||||||
static void NavUpdateWindowing();
|
static void NavUpdateWindowing();
|
||||||
static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id);
|
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);
|
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;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiWindow* parent_window = ImGui::GetCurrentWindow();
|
ImGuiWindow* parent_window = g.CurrentWindow;
|
||||||
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
|
|
||||||
|
flags |= ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
|
||||||
flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag
|
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);
|
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);
|
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)
|
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)
|
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)
|
if (size.y <= 0.0f)
|
||||||
size.y = ImMax(content_avail.y + size.y, 4.0f);
|
size.y = ImMax(content_avail.y + size.y, 4.0f);
|
||||||
|
SetNextWindowSize(size);
|
||||||
|
|
||||||
const float backup_border_size = g.Style.ChildBorderSize;
|
// Name
|
||||||
if (!border)
|
|
||||||
g.Style.ChildBorderSize = 0.0f;
|
|
||||||
flags |= extra_flags;
|
|
||||||
|
|
||||||
char title[256];
|
char title[256];
|
||||||
if (name)
|
if (name)
|
||||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s", parent_window->Name, name);
|
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%s", parent_window->Name, name);
|
||||||
else
|
else
|
||||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", parent_window->Name, id);
|
ImFormatString(title, IM_ARRAYSIZE(title), "%s/%08X", parent_window->Name, id);
|
||||||
|
|
||||||
ImGui::SetNextWindowSize(size);
|
const float backup_border_size = g.Style.ChildBorderSize;
|
||||||
bool ret = ImGui::Begin(title, NULL, flags);
|
if (!border)
|
||||||
ImGuiWindow* child_window = ImGui::GetCurrentWindow();
|
g.Style.ChildBorderSize = 0.0f;
|
||||||
child_window->ChildId = id;
|
bool ret = Begin(title, NULL, flags);
|
||||||
child_window->AutoFitChildAxises = auto_fit_axises;
|
|
||||||
g.Style.ChildBorderSize = backup_border_size;
|
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
|
// 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);
|
FocusWindow(child_window);
|
||||||
ImGui::NavInitWindow(child_window, false);
|
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
|
SetActiveID(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
|
||||||
g.ActiveIdSource = ImGuiInputSource_Nav;
|
g.ActiveIdSource = ImGuiInputSource_Nav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user