Initial implementation of UI anchors, update TestGame.

This commit is contained in:
2025-06-21 22:23:19 +02:00
parent ae1b612524
commit 683656dee8
8 changed files with 148 additions and 20 deletions

View File

@@ -56,7 +56,9 @@ public class TestGame : Game
Input.AddInputMapping("reload", new IInputAction[] { new KeyInputAction(KeyboardKey.R) });
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _fireEffect);
_uiSystem.AddElement(_container);
_frame.AddChild(_container);
_uiSystem.AddElement(_frame);
}
@@ -78,6 +80,12 @@ public class TestGame : Game
var lastChild = _container.Children.Last();
_container.RemoveChild(lastChild);
}
if (Input.IsMouseButtonDown(MouseButton.Left))
{
var mousePos = Input.GetMousePosition();
_frame.Size = new Rect(mousePos.X, mousePos.Y);
}
}
protected override void Render(double deltaTime)
@@ -119,14 +127,22 @@ public class TestGame : Game
private ResourceRef<Sound> _sound;
private ResourceRef<Texture2d> _icon;
private FlexContainer _container = new(minimumSize: new Rect(64.0f, 64.0f), new())
// private FlexContainer _container = new(minimumSize: new Rect(64.0f, 64.0f), new())
// {
// ConfineToContents = false,
// Size = new Rect(500, 300),
// Direction = FlexDirection.Column,
// Justify = JustifyContent.Start,
// Align = AlignItems.Center,
// Wrap = true,
// Gap = 10f
// };
private Frame _frame = new();
private HorizontalContainer _container = new(new Rect(128.0f, 64.0f), new(), 16)
{
ConfineToContents = false,
Size = new Rect(500, 300),
Direction = FlexDirection.Row,
Justify = JustifyContent.Start,
Align = AlignItems.Center,
Wrap = true,
Gap = 10f
ConfineToContents = true,
Anchor = Anchor.TopCenter,
AnchorOffset = new Vector2(0.5f, 0.0f)
};
}