From b3daa0b7947f74bb6cb24f1c0e1f3174a79bbfb6 Mon Sep 17 00:00:00 2001 From: eoineoineoin Date: Tue, 14 Jul 2026 03:59:12 +0100 Subject: [PATCH] Fix BaseWindow jittering on resize (#6788) --- .../UserInterface/Controls/LayoutContainer.cs | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/Robust.Client/UserInterface/Controls/LayoutContainer.cs b/Robust.Client/UserInterface/Controls/LayoutContainer.cs index f161c3b6cc..01f35d48c1 100644 --- a/Robust.Client/UserInterface/Controls/LayoutContainer.cs +++ b/Robust.Client/UserInterface/Controls/LayoutContainer.cs @@ -462,20 +462,19 @@ namespace Robust.Client.UserInterface.Controls protected override Vector2 MeasureOverride(Vector2 availableSize) { var min = Vector2.Zero; - var uiScale = UIScale; foreach (var child in Children) { var growH = child.GetValue(GrowHorizontalProperty); var growV = child.GetValue(GrowVerticalProperty); - var anchorMargins = CalcAnchorMargins(availableSize, uiScale, child); + var anchorMargins = CalcAnchorMargins(availableSize, child); var size = availableSize; if (growH == GrowDirection.Constrain) - size.X = anchorMargins.Width / uiScale; + size.X = anchorMargins.Width; if (growV == GrowDirection.Constrain) - size.Y = anchorMargins.Height / uiScale; + size.Y = anchorMargins.Height; child.Measure(size); min = Vector2.Max(min, child.DesiredSize); @@ -488,7 +487,7 @@ namespace Robust.Client.UserInterface.Controls { foreach (var child in Children) { - child.Arrange(CalcChildRect(finalSize, UIScale, child, out _)); + child.Arrange(CalcChildRect(finalSize, child, out _)); } return finalSize; @@ -509,7 +508,7 @@ namespace Robust.Client.UserInterface.Controls continue; } - var rect = CalcChildRect(Size, UIScale, child, out var anchorSize); + var rect = CalcChildRect(Size, child, out var anchorSize); var left = rect.Left * UIScale; var right = rect.Right * UIScale; @@ -542,24 +541,22 @@ namespace Robust.Client.UserInterface.Controls } } - private static UIBox2 CalcAnchorMargins(Vector2 ourSize, float uiScale, Control child) + private static UIBox2 CalcAnchorMargins(Vector2 ourSize, Control child) { - var (pSizeX, pSizeY) = ourSize * uiScale; - var anchorLeft = child.GetValue(AnchorLeftProperty); var anchorTop = child.GetValue(AnchorTopProperty); var anchorRight = child.GetValue(AnchorRightProperty); var anchorBottom = child.GetValue(AnchorBottomProperty); - var marginLeft = child.GetValue(MarginLeftProperty) * uiScale; - var marginTop = child.GetValue(MarginTopProperty) * uiScale; - var marginRight = child.GetValue(MarginRightProperty) * uiScale; - var marginBottom = child.GetValue(MarginBottomProperty) * uiScale; + var marginLeft = child.GetValue(MarginLeftProperty); + var marginTop = child.GetValue(MarginTopProperty); + var marginRight = child.GetValue(MarginRightProperty); + var marginBottom = child.GetValue(MarginBottomProperty); - var left = anchorLeft * pSizeX + marginLeft; - var top = anchorTop * pSizeY + marginTop; - var right = anchorRight * pSizeX + marginRight; - var bottom = anchorBottom * pSizeY + marginBottom; + var left = anchorLeft * ourSize.X + marginLeft; + var top = anchorTop * ourSize.Y + marginTop; + var right = anchorRight * ourSize.X + marginRight; + var bottom = anchorBottom * ourSize.Y + marginBottom; // Yes, this can return boxes with left > right (and top > bottom). // This is "intentional", see comment in CalcChildRect. @@ -567,23 +564,23 @@ namespace Robust.Client.UserInterface.Controls return new UIBox2(left, top, right, bottom); } - private static UIBox2 CalcChildRect(Vector2 ourSize, float uiScale, Control child, out UIBox2 anchorSize) + private static UIBox2 CalcChildRect(Vector2 ourSize, Control child, out UIBox2 anchorSize) { // Calculate where the control "wants" to be by its anchors/margins. var growHorizontal = child.GetValue(GrowHorizontalProperty); var growVertical = child.GetValue(GrowVerticalProperty); - anchorSize = CalcAnchorMargins(ourSize, uiScale, child); + anchorSize = CalcAnchorMargins(ourSize, child); // This intentionally results in negatives if the right bound is < the left bound. // Which then causes HandleLayoutOverflow to CORRECTLY work from the right bound instead. var (wSizeX, wSizeY) = (anchorSize.Right - anchorSize.Left, anchorSize.Bottom - anchorSize.Top); - var (minSizeX, minSizeY) = child.DesiredPixelSize; + var (minSizeX, minSizeY) = child.DesiredSize; HandleLayoutOverflow(growHorizontal, minSizeX, anchorSize.Left, wSizeX, out var posX, out var sizeX); HandleLayoutOverflow(growVertical, minSizeY, anchorSize.Top, wSizeY, out var posY, out var sizeY); - return UIBox2.FromDimensions(posX / uiScale, posY / uiScale, sizeX / uiScale, sizeY / uiScale); + return UIBox2.FromDimensions(posX, posY, sizeX, sizeY); } private static void HandleLayoutOverflow(GrowDirection direction, float minSize, float wPos, float wSize,