From 58efd449a8ff72645cf56c2d75eaa2292fef1a8d Mon Sep 17 00:00:00 2001 From: dnesov Date: Tue, 24 Jun 2025 22:11:38 +0200 Subject: [PATCH] Set window state for Raylib, make Frame occupy full size of parent UIElement or window. --- Voile/Source/Rendering/RaylibRenderSystem.cs | 2 +- Voile/Source/Rendering/RenderSystem.cs | 2 +- Voile/Source/UI/Containers/Container.cs | 1 - Voile/Source/UI/Containers/Frame.cs | 40 +++++++++++++++++++- Voile/Source/UI/UIElement.cs | 5 +++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Voile/Source/Rendering/RaylibRenderSystem.cs b/Voile/Source/Rendering/RaylibRenderSystem.cs index 503c11f..82ca3b6 100644 --- a/Voile/Source/Rendering/RaylibRenderSystem.cs +++ b/Voile/Source/Rendering/RaylibRenderSystem.cs @@ -81,7 +81,7 @@ namespace Voile.Rendering Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title); } - // Raylib.SetWindowState(windowFlags); + Raylib.SetWindowState(windowFlags); } // TODO diff --git a/Voile/Source/Rendering/RenderSystem.cs b/Voile/Source/Rendering/RenderSystem.cs index 5665369..58f330f 100644 --- a/Voile/Source/Rendering/RenderSystem.cs +++ b/Voile/Source/Rendering/RenderSystem.cs @@ -256,7 +256,7 @@ namespace Voile.Rendering { public string Title; public Vector2 Size = new Vector2(1280, 720); - public bool Resizable { get; set; } + public bool Resizable { get; set; } = true; public WindowSettings(string title, Vector2 size) { diff --git a/Voile/Source/UI/Containers/Container.cs b/Voile/Source/UI/Containers/Container.cs index 2c9645e..bb6c327 100644 --- a/Voile/Source/UI/Containers/Container.cs +++ b/Voile/Source/UI/Containers/Container.cs @@ -3,7 +3,6 @@ using Voile.Rendering; namespace Voile.UI.Containers; -// TODO: make Container extend Widget, it already implements similar behaviors. /// /// A base class for all UI containers, used to position and rendering child s. /// diff --git a/Voile/Source/UI/Containers/Frame.cs b/Voile/Source/UI/Containers/Frame.cs index d00fc57..fcc4985 100644 --- a/Voile/Source/UI/Containers/Frame.cs +++ b/Voile/Source/UI/Containers/Frame.cs @@ -1,5 +1,10 @@ +using Voile.Rendering; + namespace Voile.UI.Containers; +/// +/// A frame is a special container that occupies the entire available size of the parent. +/// public class Frame : Container { public Frame() @@ -9,11 +14,44 @@ public class Frame : Container public Frame(Rect minimumSize) : base(minimumSize) { - + } 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; } \ No newline at end of file diff --git a/Voile/Source/UI/UIElement.cs b/Voile/Source/UI/UIElement.cs index 6196ce2..29306ba 100644 --- a/Voile/Source/UI/UIElement.cs +++ b/Voile/Source/UI/UIElement.cs @@ -10,6 +10,11 @@ public abstract class UIElement : IElement, IRenderableElement, IResizeableEleme public Vector2 LocalPosition { get; set; } = Vector2.Zero; public Vector2 GlobalPosition => _parent?.GlobalPosition + LocalPosition ?? LocalPosition; + /// + /// Parent of this element. + /// + public UIElement? Parent => _parent; + public Rect Size { get => _size;