Set window state for Raylib, make Frame occupy full size of parent UIElement or window.
This commit is contained in:
@@ -81,7 +81,7 @@ namespace Voile.Rendering
|
||||
Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title);
|
||||
}
|
||||
|
||||
// Raylib.SetWindowState(windowFlags);
|
||||
Raylib.SetWindowState(windowFlags);
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,6 @@ using Voile.Rendering;
|
||||
|
||||
namespace Voile.UI.Containers;
|
||||
|
||||
// TODO: make Container extend Widget, it already implements similar behaviors.
|
||||
/// <summary>
|
||||
/// A base class for all UI containers, used to position and rendering child <see cref="IElement">s.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
using Voile.Rendering;
|
||||
|
||||
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 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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Parent <see cref="UIElement"/> of this element.
|
||||
/// </summary>
|
||||
public UIElement? Parent => _parent;
|
||||
|
||||
public Rect Size
|
||||
{
|
||||
get => _size;
|
||||
|
||||
Reference in New Issue
Block a user