diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index 3756c1d..26a7828 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -73,9 +73,16 @@ public class TestGame : Game _container.AddChild(new RectangleWidget(new Rect(32.0f, 32.0f), MathUtils.RandomColor())); } + if (Input.IsActionPressed("cancel") && _container.Children.Count != 0) + { + var lastChild = _container.Children.Last(); + _container.RemoveChild(lastChild); + } + if (Input.IsMouseButtonDown(MouseButton.Left)) { - _particleSystem.SetEmitterPosition(_emitterId, Input.GetMousePosition()); + var mousePos = Input.GetMousePosition(); + _container.Size = new Rect(mousePos.X, mousePos.Y); } } @@ -118,5 +125,5 @@ public class TestGame : Game private ResourceRef _sound; private ResourceRef _icon; - private GridContainer _container = new(); + private GridContainer _container = new(minimumSize: new Rect(64.0f, 64.0f), new()); } \ No newline at end of file diff --git a/Voile/Source/Input/InputSystem.cs b/Voile/Source/Input/InputSystem.cs index 578daca..a8b5584 100644 --- a/Voile/Source/Input/InputSystem.cs +++ b/Voile/Source/Input/InputSystem.cs @@ -137,6 +137,9 @@ namespace Voile.Input AddInputMapping("accept", [ new KeyInputAction(KeyboardKey.Enter), ]); + AddInputMapping("cancel", [ + new KeyInputAction(KeyboardKey.Backspace), + ]); } protected bool TryGetInputMappings(string forAction, [NotNullWhen(true)] out List? inputActions) diff --git a/Voile/Source/UI/Containers/Container.cs b/Voile/Source/UI/Containers/Container.cs index 0393e95..58ff889 100644 --- a/Voile/Source/UI/Containers/Container.cs +++ b/Voile/Source/UI/Containers/Container.cs @@ -12,7 +12,7 @@ public abstract class Container : IElement, IParentableElement, IUpdatableElemen public Vector2 Position { get; set; } public Rect MinimumRect { get; set; } = Rect.Zero; public Rect Size { get; set; } = Rect.Zero; - public bool Visible { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public bool Visible { get; set; } = true; public Container() { @@ -67,13 +67,15 @@ public abstract class Container : IElement, IParentableElement, IUpdatableElemen maxY = MathF.Max(maxY, pos.Y + size.Height); } - // Optionally apply padding - float padding = 0f; // or make this configurable + float padding = 0f; - Size = new Rect( - maxX - minX + padding * 2, - maxY - minY + padding * 2 - ); + float occupiedWidth = (maxX - minX) + padding * 2; + float occupiedHeight = (maxY - minY) + padding * 2; + + float finalWidth = MathF.Max(occupiedWidth, MinimumRect.Width); + float finalHeight = MathF.Max(occupiedHeight, MinimumRect.Height); + + Size = new Rect(finalWidth, finalHeight); } public void AddChild(IElement child) @@ -82,6 +84,12 @@ public abstract class Container : IElement, IParentableElement, IUpdatableElemen Update(); } + public void RemoveChild(IElement child) + { + _children.Remove(child); + Update(); + } + public void Render(RenderSystem renderer, Style style) { foreach (var child in Children) diff --git a/Voile/Source/UI/IElement.cs b/Voile/Source/UI/IElement.cs index dbf7872..26af153 100644 --- a/Voile/Source/UI/IElement.cs +++ b/Voile/Source/UI/IElement.cs @@ -14,6 +14,7 @@ public interface IParentableElement { public IReadOnlyList Children { get; } public void AddChild(IElement child); + public void RemoveChild(IElement child); } public interface IResizeableElement