You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling ImGui::SetWindowSize() with a size that hasn't been rounded to an integer value can make the window move by itself due to rounding errors inside ImGui::Begin().
Let's consider the following call: ImGui::SetWindowSize(ImVec2(348.48f, 400.0f));
This will set the value of "window->SizeFull.x" to "348.480011" in the SetWindowSize() function (the values were taken from the debugger).
On the next call to ImGui::Begin(), when the window position is clamped to the visible area, a rounding error can make the window position change (see my comments in the code):
// Clamp position so it stays visible
if (!(flags & ImGuiWindowFlags_ChildWindow))
{
if (!window_pos_set_by_api && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
{
ImVec2 padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
// Here window->Pos.x == 170.000000 and window->Size.x == 348.480011
window->Pos = ImMax(window->Pos + window->Size, padding) - window->Size;
// Here window->Pos.x == 169.999969 due to rounding error
window->Pos = ImMin(window->Pos, g.IO.DisplaySize - padding);
}
}
window->Pos = ImFloor(window->Pos);
// And finally, here window->Pos.x has become 169.000000
The solution would be to round the window size in the ImGui::SetWindowSize() function.
Of course, I changed the code on our side to make sure the size was always rounded before calling ImGui::SetWindowSize(), but it would be safer to round the size in the ImGui function to avoid weird behavior.
The text was updated successfully, but these errors were encountered:
I found that the same issue appears when SizeConstraintRect has non rounded values. In that case, the CalcSizeAfterConstraint function returns a new, non-rounded size which is then used by a code fragment quoted by OP.
Calling ImGui::SetWindowSize() with a size that hasn't been rounded to an integer value can make the window move by itself due to rounding errors inside ImGui::Begin().
Let's consider the following call:
ImGui::SetWindowSize(ImVec2(348.48f, 400.0f));
This will set the value of "window->SizeFull.x" to "348.480011" in the SetWindowSize() function (the values were taken from the debugger).
On the next call to ImGui::Begin(), when the window position is clamped to the visible area, a rounding error can make the window position change (see my comments in the code):
The solution would be to round the window size in the ImGui::SetWindowSize() function.
Of course, I changed the code on our side to make sure the size was always rounded before calling ImGui::SetWindowSize(), but it would be safer to round the size in the ImGui function to avoid weird behavior.
The text was updated successfully, but these errors were encountered: