WIP: dirty flag for UI.

This commit is contained in:
2025-06-20 19:34:10 +02:00
parent a9a8113dd9
commit 76dafe9996
3 changed files with 89 additions and 3 deletions

View File

@@ -22,11 +22,14 @@ public abstract class Widget : IElement, IRenderableElement, IInputElement, IRes
public Widget(Vector2 position)
{
Position = position;
Size = MinimumRect;
}
/// </inheritdoc>
public abstract Rect MinimumRect { get; }
public bool Dirty => _isDirty;
/// <summary>
/// Called when its time to draw this widget.
/// </summary>
@@ -41,15 +44,22 @@ public abstract class Widget : IElement, IRenderableElement, IInputElement, IRes
public void Update()
{
if (!_isDirty) return;
_isDirty = false;
if (Size == Rect.Zero)
{
Size = MinimumRect;
}
}
public void MarkDirty() => _isDirty = true;
public void DrawSize(RenderSystem renderer)
{
renderer.SetTransform(Position, Vector2.Zero);
renderer.DrawRectangleOutline(new Vector2(Size.Width, Size.Height), Color.Red, 2.0f);
}
private bool _isDirty = true;
}