Skip to content

API reference

Class Layer

Namespace: MicroEngine.UI
Assembly: MicroEngine.UI.dll
Guide: UI widgets

The whole UI view, with each child placed on its own: against an edge or a corner (a banner in a corner, a HUD block), or at a point (a speech bubble over a character, a damage number, a marker that follows something in the world). Children keep the size they measure; later children draw over earlier ones. Where no child is, the pointer passes through to gameplay. Use it as a root’s Content.

C#
public sealed class Layer : Widget

Inheritance

object ← Widget ← Layer

Inherited Members

Widget.Measure(UiContext), Widget.Arrange(RectF, UiContext), Widget.Draw(IRenderer, UiContext), Widget.Bounds, Widget.Visible, Widget.Enabled, Widget.Width, Widget.Height, Widget.Offset, Widget.Opacity, Widget.BlocksPointer, Widget.Parent, Widget.Root, Widget.Children, Widget.Focusable, Widget.ClipsChildren, Widget.IsFocused, Widget.IsHovered, Widget.IsPressed, Widget.IsEnabledInTree, Widget.IsVisibleInTree, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

Layer()

C#
public Layer()

Properties

BlocksPointer

The layer’s empty areas are not the UI’s: presses there reach gameplay.

C#
public override bool BlocksPointer { get; }

Property Value

bool

Children

The widgets this one contains, in focus and drawing order.

C#
public override IReadOnlyList<Widget> Children { get; }

Property Value

IReadOnlyList<Widget>

Methods

Add(Widget, Anchor, Vector2)

Adds child with its anchor point on the layer’s same point, moved by offset: Add(banner, Anchor.TopRight, new(-4, 4)) puts a banner 4 units from the top-right corner. Returns the layer.

C#
public Layer Add(Widget child, Anchor anchor = Anchor.TopLeft, Vector2 offset = default)

Parameters

child Widget

anchor Anchor

offset Vector2

Returns

Layer

Exceptions

InvalidOperationException

The child already belongs to another widget or root.

AddAt(Widget, Vector2, Anchor)

Adds child with its pivot point at point (UI units from the layer’s top-left): AddAt(bubble, head, Anchor.Bottom) puts a bubble’s bottom centre over a head. Returns the layer.

C#
public Layer AddAt(Widget child, Vector2 point, Anchor pivot = Anchor.Center)

Parameters

child Widget

point Vector2

pivot Anchor

Returns

Layer

Exceptions

InvalidOperationException

The child already belongs to another widget or root.

ArrangeContent(RectF, UiContext)

Places the children within bounds; nothing by default.

C#
protected override void ArrangeContent(RectF bounds, UiContext context)

Parameters

bounds RectF

context UiContext

DrawContent(IRenderer, UiContext)

Draws the widget in Bounds, and its children.

C#
protected override void DrawContent(IRenderer renderer, UiContext context)

Parameters

renderer IRenderer

context UiContext

MeasureContent(UiContext)

The UI view’s size: a layer fills it.

C#
protected override Vector2 MeasureContent(UiContext context)

Parameters

context UiContext

Returns

Vector2

Move(Widget, Vector2)

Moves child’s pivot to point, keeping its pivot (the centre if it was placed against an edge). Call it every update to follow something that moves.

C#
public void Move(Widget child, Vector2 point)

Parameters

child Widget

point Vector2

Exceptions

ArgumentException

The child is not in this layer.

Place(Widget, Anchor, Vector2)

Places child against the layer’s anchor point, as Add does.

C#
public void Place(Widget child, Anchor anchor, Vector2 offset = default)

Parameters

child Widget

anchor Anchor

offset Vector2

Exceptions

ArgumentException

The child is not in this layer.

Remove(Widget)

Removes child; false when it was not in the layer.

C#
public bool Remove(Widget child)

Parameters

child Widget

Returns

bool