Windows: BeginChild(): made it possible to call SetNextWindowSize() on a child window using ImGuiChildFlags_ResizeX/ImGuiChildFlags_ResizeY. (#1710, #8020)

This commit is contained in:
ocornut 2024-09-26 14:58:56 +02:00
parent 9644c51183
commit 797101a882
4 changed files with 29 additions and 6 deletions

View file

@ -43,6 +43,9 @@ Breaking changes:
Other changes:
- Windows: BeginChild(): made it possible to call SetNextWindowSize() on a child window
using ImGuiChildFlags_ResizeX,ImGuiChildFlags_ResizeY in order to override its current
size. (#1710, #8020)
- Scrollbar: Shift+Click scroll to clicked location (pre-1.90.8 default). (#8002, #7328)
- Scrollbar: added io.ConfigScrollbarScrollByPage setting (default to true). (#8002, #7328)
Set io.ConfigScrollbarScrollByPage=false to enforce always scrolling to clicked location.

View file

@ -5917,18 +5917,35 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, I
window_flags |= ImGuiWindowFlags_NoMove;
}
// Forward child flags
g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasChildFlags;
g.NextWindowData.ChildFlags = child_flags;
// Forward size
// Important: Begin() has special processing to switch condition to ImGuiCond_FirstUseEver for a given axis when ImGuiChildFlags_ResizeXXX is set.
// (the alternative would to store conditional flags per axis, which is possible but more code)
const ImVec2 size_avail = GetContentRegionAvail();
const ImVec2 size_default((child_flags & ImGuiChildFlags_AutoResizeX) ? 0.0f : size_avail.x, (child_flags & ImGuiChildFlags_AutoResizeY) ? 0.0f : size_avail.y);
const ImVec2 size = CalcItemSize(size_arg, size_default.x, size_default.y);
ImVec2 size = CalcItemSize(size_arg, size_default.x, size_default.y);
// A SetNextWindowSize() call always has priority (#8020)
// (since the code in Begin() never supported SizeVal==0.0f aka auto-resize via SetNextWindowSize() call, we don't support it here for now)
// FIXME: We only support ImGuiCond_Always in this path. Supporting other paths would requires to obtain window pointer.
if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) != 0 && (g.NextWindowData.SizeCond & ImGuiCond_Always) != 0)
{
if (g.NextWindowData.SizeVal.x > 0.0f)
{
size.x = g.NextWindowData.SizeVal.x;
child_flags &= ~ImGuiChildFlags_ResizeX;
}
if (g.NextWindowData.SizeVal.y > 0.0f)
{
size.y = g.NextWindowData.SizeVal.y;
child_flags &= ~ImGuiChildFlags_ResizeY;
}
}
SetNextWindowSize(size);
// Forward child flags
g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasChildFlags;
g.NextWindowData.ChildFlags = child_flags;
// Build up name. If you need to append to a same child from multiple location in the ID stack, use BeginChild(ImGuiID id) with a stable value.
// FIXME: 2023/11/14: commented out shorted version. We had an issue with multiple ### in child window path names, which the trailing hash helped workaround.
// e.g. "ParentName###ParentIdentifier/ChildName###ChildIdentifier" would get hashed incorrectly by ImHashStr(), trailing _%08X somehow fixes it.

View file

@ -29,7 +29,7 @@
// Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.91.3 WIP"
#define IMGUI_VERSION_NUM 19121
#define IMGUI_VERSION_NUM 19122
#define IMGUI_HAS_TABLE
/*

View file

@ -3931,6 +3931,9 @@ static void ShowDemoWindowLayout()
ImGui::SeparatorText("Manual-resize");
{
HelpMarker("Drag bottom border to resize. Double-click bottom border to auto-fit to vertical contents.");
//if (ImGui::Button("Set Height to 200"))
// ImGui::SetNextWindowSize(ImVec2(-FLT_MIN, 200.0f));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_FrameBg));
if (ImGui::BeginChild("ResizableChild", ImVec2(-FLT_MIN, ImGui::GetTextLineHeightWithSpacing() * 8), ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeY))
for (int n = 0; n < 10; n++)