130 lines
3.9 KiB
C#
130 lines
3.9 KiB
C#
using System.Numerics;
|
|
using Voile.Rendering;
|
|
|
|
namespace Voile.UI;
|
|
|
|
/// <summary>
|
|
/// Represents a basic UI element with position and size information.
|
|
/// </summary>
|
|
public interface IElement
|
|
{
|
|
/// <summary>
|
|
/// This element's position in pixels relative to the viewport top-left edge.
|
|
/// </summary>
|
|
public Vector2 GlobalPosition { get; }
|
|
/// <summary>
|
|
/// The size of this element.
|
|
/// </summary>
|
|
public Rect Size { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a UI element that can contain child elements.
|
|
/// </summary>
|
|
public interface IParentableElement
|
|
{
|
|
/// <summary>
|
|
/// This parentable element's children.
|
|
/// </summary>
|
|
public IReadOnlyList<UIElement> Children { get; }
|
|
/// <summary>
|
|
/// Add a child element to this element.
|
|
/// </summary>
|
|
/// <param name="child">Child <see cref="UIElement"/>.</param>
|
|
public void AddChild(UIElement child);
|
|
/// <summary>
|
|
/// Remove a child element from this element.
|
|
/// </summary>
|
|
/// <param name="child">Child <see cref="UIElement"/> to remove.</param>
|
|
public void RemoveChild(UIElement child);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a UI element that can provide a minimum size constraint.<br />
|
|
/// Implement this interface if your UI element is expected to be resizeable.
|
|
/// </summary>
|
|
public interface IResizeableElement
|
|
{
|
|
/// <summary>
|
|
/// Get a minimum rectangle size for this element.
|
|
/// </summary>
|
|
public abstract Rect MinimumSize { get; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a UI element that supports updates when its state changes.
|
|
/// </summary>
|
|
public interface IUpdatableElement
|
|
{
|
|
/// <summary>
|
|
/// Gets a value indicating whether the element's state has changed and needs to be updated.
|
|
/// </summary>
|
|
public bool Dirty { get; }
|
|
/// <summary>
|
|
/// Update this element.
|
|
/// </summary>
|
|
void Update(float dt = 0.0f);
|
|
/// <summary>
|
|
/// Marks this element as changed, requiring an update.
|
|
/// </summary>
|
|
void MarkDirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a UI element that can be rendered to the screen.
|
|
/// </summary>
|
|
public interface IRenderableElement
|
|
{
|
|
/// <summary>
|
|
/// Specifies if this element should be drawn.
|
|
/// </summary>
|
|
public bool Visible { get; set; }
|
|
/// <summary>
|
|
/// Render this element.
|
|
/// </summary>
|
|
/// <param name="renderer">Renderer to call draw operations on.</param>
|
|
/// <param name="style">A style to use to draw this element.</param>
|
|
public void Render(RenderSystem renderer, Style style);
|
|
/// <summary>
|
|
/// Draws this element's size bounds.
|
|
/// </summary>
|
|
/// <param name="renderer">Renderer to use.</param>
|
|
public void DrawSize(RenderSystem renderer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a UI element that can receive and process user input.
|
|
/// </summary>
|
|
public interface IInputElement
|
|
{
|
|
/// <summary>
|
|
/// Specifies if this element should ignore inputs.
|
|
/// </summary>
|
|
public bool IgnoreInput { get; set; }
|
|
/// <summary>
|
|
/// Send an input action to this element.
|
|
/// </summary>
|
|
/// <param name="action">Input action to send.</param>
|
|
void Input(UIInputContext action);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a UI element that supports positional anchoring within a parent.
|
|
/// </summary>
|
|
public interface IAnchorableElement
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets the anchor point relative to the parent container.
|
|
/// </summary>
|
|
public Anchor Anchor { get; set; }
|
|
/// <summary>
|
|
/// Gets or sets an additional offset to apply after anchoring, in pixels.
|
|
/// </summary>
|
|
public Vector2 AnchorOffset { get; set; }
|
|
/// <summary>
|
|
/// Applies the current anchor settings based on the parent's position and size.
|
|
/// </summary>
|
|
/// <param name="parentPosition">The parent's top-left global position.</param>
|
|
/// <param name="parentRect">The bounding rectangle of the parent container.</param>
|
|
public void ApplyAnchor(Vector2 parentPosition, Rect parentRect);
|
|
} |