Set window state for Raylib, make Frame occupy full size of parent UIElement or window.

This commit is contained in:
2025-06-24 22:11:38 +02:00
parent 78b46cb38e
commit 58efd449a8
5 changed files with 46 additions and 4 deletions

View File

@@ -81,7 +81,7 @@ namespace Voile.Rendering
Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title); Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title);
} }
// Raylib.SetWindowState(windowFlags); Raylib.SetWindowState(windowFlags);
} }
// TODO // TODO

View File

@@ -256,7 +256,7 @@ namespace Voile.Rendering
{ {
public string Title; public string Title;
public Vector2 Size = new Vector2(1280, 720); public Vector2 Size = new Vector2(1280, 720);
public bool Resizable { get; set; } public bool Resizable { get; set; } = true;
public WindowSettings(string title, Vector2 size) public WindowSettings(string title, Vector2 size)
{ {

View File

@@ -3,7 +3,6 @@ using Voile.Rendering;
namespace Voile.UI.Containers; namespace Voile.UI.Containers;
// TODO: make Container extend Widget, it already implements similar behaviors.
/// <summary> /// <summary>
/// A base class for all UI containers, used to position and rendering child <see cref="IElement">s. /// A base class for all UI containers, used to position and rendering child <see cref="IElement">s.
/// </summary> /// </summary>

View File

@@ -1,5 +1,10 @@
using Voile.Rendering;
namespace Voile.UI.Containers; namespace Voile.UI.Containers;
/// <summary>
/// A frame is a special container that occupies the entire available size of the parent.
/// </summary>
public class Frame : Container public class Frame : Container
{ {
public Frame() public Frame()
@@ -9,11 +14,44 @@ public class Frame : Container
public Frame(Rect minimumSize) : base(minimumSize) public Frame(Rect minimumSize) : base(minimumSize)
{ {
} }
public override void Arrange() public override void Arrange()
{ {
} }
public override void Render(RenderSystem renderer, Style style)
{
base.Render(renderer, style);
Rect parentSize;
if (Parent != null)
{
parentSize = Parent.Size;
}
else
{
var windowSize = renderer.WindowSize;
var windowRect = new Rect(windowSize.X, windowSize.Y);
parentSize = windowRect;
}
if (_lastParentSize != parentSize)
{
Size = parentSize;
_lastParentSize = parentSize;
}
}
protected override void OnUpdate()
{
base.OnUpdate();
Size = _lastParentSize;
}
private Rect _lastParentSize = Rect.Zero;
} }

View File

@@ -10,6 +10,11 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme
public Vector2 LocalPosition { get; set; } = Vector2.Zero; public Vector2 LocalPosition { get; set; } = Vector2.Zero;
public Vector2 GlobalPosition => _parent?.GlobalPosition + LocalPosition ?? LocalPosition; public Vector2 GlobalPosition => _parent?.GlobalPosition + LocalPosition ?? LocalPosition;
/// <summary>
/// Parent <see cref="UIElement"/> of this element.
/// </summary>
public UIElement? Parent => _parent;
public Rect Size public Rect Size
{ {
get => _size; get => _size;