Move element update out of Render in UISystem, fix Size property retriggering MarkDirty.
This commit is contained in:
@@ -20,7 +20,7 @@ public class TestGame : Game
|
||||
InitializeSystemsDefault();
|
||||
|
||||
_uiSystem = new UISystem(Input);
|
||||
// _uiSystem.RenderDebugRects = true;
|
||||
_uiSystem.RenderDebugRects = true;
|
||||
|
||||
ResourceManager.EnableFileWatching();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user