Add container nesting.

This commit is contained in:
2025-06-19 14:50:05 +02:00
parent 806c9cc1d4
commit e499691714
8 changed files with 113 additions and 17 deletions

View File

@@ -1,27 +1,41 @@
using System.Numerics;
using Voile.UI.Widgets;
namespace Voile.UI.Containers;
/// <summary>
/// A base class for all UI containers, used to position and rendering child <see cref="Widget">s.
/// A base class for all UI containers, used to position and rendering child <see cref="IElement">s.
/// </summary>
public abstract class Container : IElement, IParentableElement
public abstract class Container : IElement, IParentableElement, IUpdatableElement
{
public IReadOnlyList<IElement> Children => _children;
public Vector2 Position { get; set; }
public Container()
{
}
public Container(List<IElement> children)
{
_children = children;
}
public void Update()
{
Arrange();
foreach (var child in _children)
{
if (child is not IUpdatableElement updatable) continue;
updatable.Update();
}
}
public abstract void Arrange();
public void AddChild(IElement child)
{
_children.Add(child);
Update();
}
private List<IElement> _children;
private List<IElement> _children = new();
}