Open redmercury opened 4 weeks ago
I should add to this that I want the user to be able to dynamically resize the child (hence ImGuiChildFlags_ResizeY) as well as force it in code.
I should add to this that I want the user to be able to dynamically resize the child (hence ImGuiChildFlags_ResizeY) as well as force it in code.
Presumably not at the same time? As in, you are not calling SetNextWindowSizs() every frame, but only on certain events?
I will investigate this when possible, it is possible that there may be an issue.
If you force the height every frame, the user won't be able to resize at all, you need to restrict the forced height to those frames where you actually want to set it. Besides that, for user resizable children the user specified size is prioritized and overwrites the size specified by code, so you might need to get a bit creative.
One option is to automatically resize with ImGuiChildFlags_AutoResizeY
(for one frame), you can set the content size beforehand with ImGui::SetNextWindowContentSize()
. That should work if you want to resize to the actual content size.
Another option is to (also for one frame) limit the size with ImGui::SetNextWindowSizeConstraints()
. You can set the minimum and maximum height to the same value to force it. For the width you can specify 0.0f
and FLT_MAX
to not affect the current value.
I can confirm that this currently doesn't work:
if (ImGui::Button("Set Height to 500"))
ImGui::SetNextWindowSize(ImVec2(-FLT_MIN, 500.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++)
ImGui::Text("Line %04d", n);
ImGui::PopStyleColor();
ImGui::EndChild();
Aka SetNextWindowSize()
is (and was always) completely ignored by BeginChild()
, because it itself takes a size parameter.
This was ok for a long time, but with the addition of e.g. ImGuiChildFlags_ResizeY
which makes the size parameter an "initial size" it would make sense that SetNextWindowSize()
was honored as a possible override.
I have pushed a fix 797101a for the case in my previous post. I'm not entirely sure this is what you wanted but it seems useful to allow it. Unfortunately we can't easily support SetNextWindowSize()
conditional flags in that path, but they make much less sense.
Amended test: https://github.com/ocornut/imgui_test_engine/commit/473e9ef89cb9d35f3aa5564bcf397827ff599f73
Let me know if that solves your problem!
Version/Branch of Dear ImGui:
Latest master (9644c5118357cd0c0ba0ea957b3328ff49cf6260)
Back-ends:
imgui_impl_dx12.cpp + imgui_impl_win32.cpp
Compiler, OS:
Windows 11, MSVC 2022
Full config/build information:
1.91.3 WIP (19121)
Details:
My Issue/Question: I'm trying to resize some children from their initially created size based on some factors and miserably failing. The children resize with the horizontal resize bars, but if I try to force it from code the size doesn't apply. Am I holding it wrong?
In the MCVE I set a certain size on the first frame which is applied to the window and subsequently try to set a different size on later frames.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code: