From 2576ea87bc9cc8c48fff8556e6b05adbaca4c419 Mon Sep 17 00:00:00 2001 From: dnesov Date: Mon, 1 Jun 2026 22:45:05 +0200 Subject: [PATCH] Move element update out of Render in UISystem, fix Size property retriggering MarkDirty. --- TestGame/TestGame.cs | 2 +- Voile/Source/UI/UIElement.cs | 25 ++++++++++++------------- Voile/Source/UI/UISystem.cs | 9 ++++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index fc11cbb..4c46e23 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -20,7 +20,7 @@ public class TestGame : Game InitializeSystemsDefault(); _uiSystem = new UISystem(Input); - // _uiSystem.RenderDebugRects = true; + _uiSystem.RenderDebugRects = true; ResourceManager.EnableFileWatching(); diff --git a/Voile/Source/UI/UIElement.cs b/Voile/Source/UI/UIElement.cs index 8301e97..fa15302 100644 --- a/Voile/Source/UI/UIElement.cs +++ b/Voile/Source/UI/UIElement.cs @@ -42,24 +42,23 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme get => _size; set { - if (value.Width < MinimumSize.Width) - { - _size.Width = MinimumSize.Width; - } + float width = Math.Max(value.Width, MinimumSize.Width); + float height = Math.Max(value.Height, MinimumSize.Height); - if (value.Height < MinimumSize.Height) - { - _size.Height = MinimumSize.Height; - } + bool changed = + _size.Width != width || + _size.Height != height; - if (_size != value) - { - MarkDirty(); - } + if (!changed) + return; - _size = value; + _size.Width = width; + _size.Height = height; + + MarkDirty(); } } + public Vector2 AnchorOffset { get; set; } = Vector2.Zero; public Anchor Anchor { get; set; } = Anchor.TopLeft; diff --git a/Voile/Source/UI/UISystem.cs b/Voile/Source/UI/UISystem.cs index 1d739a6..aa4921f 100644 --- a/Voile/Source/UI/UISystem.cs +++ b/Voile/Source/UI/UISystem.cs @@ -42,17 +42,16 @@ public class UISystem : IUpdatableSystem, IRenderableSystem, IReloadableSystem float dt = (float)deltaTime; PropagateTick(_elements, dt); HandleInput((float)deltaTime); - } - public void Render(RenderSystem renderer) - { foreach (var element in _elements) { if (element is not IUpdatableElement updatable) continue; updatable.Update(); } + } - + public void Render(RenderSystem renderer) + { foreach (var element in _elements) { if (element is IRenderableElement renderable) @@ -110,7 +109,7 @@ public class UISystem : IUpdatableSystem, IRenderableSystem, IReloadableSystem Vector2 currentMousePosition = _input.GetMousePosition(); bool inputHandled = false; - // 1. Process Actions (Pressed or Held) + // Process Actions (Pressed or Held) foreach (var (actionName, mappings) in InputSystem.InputMappings) { foreach (var action in mappings)