Update arrangement logic for containers, remove position property from Rect, add Size property to IElement.

This commit is contained in:
2025-06-19 15:08:23 +02:00
parent e499691714
commit 6affded730
9 changed files with 56 additions and 23 deletions

View File

@@ -7,11 +7,12 @@ namespace Voile.UI.Widgets;
/// <summary>
/// A base class for all UI widgets.
/// </summary>
public abstract class Widget : IElement, IRenderableElement, IInputElement
public abstract class Widget : IElement, IRenderableElement, IInputElement, IResizeableElement, IUpdatableElement
{
public bool Visible { get; set; } = true;
public bool IgnoreInput { get; set; }
public Vector2 Position { get; set; } = Vector2.Zero;
public Rect Size { get; set; } = new();
public Widget()
{
@@ -23,9 +24,7 @@ public abstract class Widget : IElement, IRenderableElement, IInputElement
Position = position;
}
/// <summary>
/// Get a minimum rectangle size for this widget.
/// </summary>
/// </inheritdoc>
public abstract Rect MinimumRect { get; }
/// <summary>
@@ -38,4 +37,12 @@ public abstract class Widget : IElement, IRenderableElement, IInputElement
/// </summary>
/// <param name="action">An input action this widget received.</param>
public abstract void Input(IInputAction action);
public void Update()
{
if (Size == Rect.Zero)
{
Size = MinimumRect;
}
}
}