Add MarginContainer, mark parent elements dirty when child gets marked dirty too.

This commit is contained in:
2025-06-25 00:35:35 +02:00
parent 5bf052db96
commit 64d3dba42d
5 changed files with 111 additions and 13 deletions

View File

@@ -23,8 +23,6 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme
get => _size;
set
{
_size = value;
if (value.Width < MinimumSize.Width)
{
_size.Width = MinimumSize.Width;
@@ -35,7 +33,12 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme
_size.Height = MinimumSize.Height;
}
MarkDirty();
if (_size != value)
{
MarkDirty();
}
_size = value;
}
}
public Vector2 AnchorOffset { get; set; } = Vector2.Zero;
@@ -44,7 +47,15 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme
public abstract Rect MinimumSize { get; }
public bool Dirty => _dirty;
public virtual void MarkDirty() => _dirty = true;
public virtual void MarkDirty()
{
if (Parent != null && !Parent.Dirty)
{
Parent.MarkDirty();
}
_dirty = true;
}
/// <summary>
/// Sets a parent element for this <see cref="UIElement"/>.