From 389a73cf245dab04e11c5919c02187939d5ef2b2 Mon Sep 17 00:00:00 2001 From: dnesov Date: Tue, 24 Jun 2025 23:44:38 +0200 Subject: [PATCH] Don't reassign Size in Container if the new size is identical to current size in RecalculateSizes. --- TestGame/TestGame.cs | 31 +++++++++++++------------ Voile/Source/UI/Containers/Container.cs | 7 +++++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index 7803ece..4525dc7 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -127,22 +127,23 @@ public class TestGame : Game private ResourceRef _sound; private ResourceRef _icon; - // private FlexContainer _container = new(minimumSize: new Rect(64.0f, 64.0f), new()) - // { - // Anchor = Anchor.Center, - // Size = new Rect(500, 300), - // Direction = FlexDirection.Column, - // Justify = JustifyContent.Start, - // Align = AlignItems.Center, - // Wrap = true, - // Gap = 10f - // }; - - private Frame _frame = new(); - private VerticalContainer _container = new(new Rect(128.0f, 64.0f), new(), 16) + private FlexContainer _container = new(minimumSize: new Rect(64.0f, 64.0f), new()) { ConfineToContents = true, - Anchor = Anchor.CenterLeft, - AnchorOffset = new Vector2(0.5f, 0.0f) + Anchor = Anchor.Center, + Size = new Rect(500, 300), + Direction = FlexDirection.Column, + Justify = JustifyContent.Start, + Align = AlignItems.Center, + Wrap = true, + Gap = 10f }; + + private Frame _frame = new(); + // private HorizontalContainer _container = new(new Rect(128.0f, 64.0f), new(), 16) + // { + // ConfineToContents = true, + // Anchor = Anchor.CenterRight, + // AnchorOffset = new Vector2(0.5f, 0.0f) + // }; } \ No newline at end of file diff --git a/Voile/Source/UI/Containers/Container.cs b/Voile/Source/UI/Containers/Container.cs index 9c1c0f9..c9112ca 100644 --- a/Voile/Source/UI/Containers/Container.cs +++ b/Voile/Source/UI/Containers/Container.cs @@ -95,7 +95,12 @@ public abstract class Container : UIElement, IParentableElement float finalWidth = MathF.Max(occupiedWidth, _minimumSize.Width); float finalHeight = MathF.Max(occupiedHeight, _minimumSize.Height); - Size = new Rect(finalWidth, finalHeight); + var finalSize = new Rect(finalWidth, finalHeight); + + if (finalSize != Size) + { + Size = finalSize; + } if (_minimumSize > Size) {