Skip to main content

Class YauiElement

A node of the UI: a flex layout box with a background, border and shadow, that can be transformed. The GameObject's Transform is ignored except for the hierarchy; its children with a Yaui.YauiElement are laid out inside this box and drawn on top of it in sibling order.

Assembly: Yaui.dll​
View Source​
Declaration
public class YauiElement : MonoBehaviour

Derived:
Yaui.YauiImage, Yaui.YauiRawImage, Yaui.YauiText

Properties​

AcceptsChildren​

Whether child elements are laid out and drawn. Elements that measure their content (Yaui.YauiElement.MeasuresContent) never have children.

View Source​
Declaration
protected virtual bool AcceptsChildren { get; }

IsRegistered​

Whether the element is in an enabled panel: it has its slots, and content can be written.

View Source​
Declaration
protected bool IsRegistered { get; }

Layout​

View Source​
Declaration
public LayoutStyle Layout { get; set; }

Box​

View Source​
Declaration
public BoxStyle Box { get; set; }

BackgroundColor​

View Source​
Declaration
public Color BackgroundColor { get; set; }

RenderTransform​

View Source​
Declaration
public TransformStyle RenderTransform { get; set; }

Translate​

View Source​
Declaration
public Vector2 Translate { get; set; }

Rotation​

Degrees, clockwise.

View Source​
Declaration
public float Rotation { get; set; }

Scale​

View Source​
Declaration
public Vector2 Scale { get; set; }

Opacity​

Multiplies the opacity of this element and its descendants.

View Source​
Declaration
public float Opacity { get; set; }

Material​

View Source​
Declaration
public Material Material { get; set; }

Tint​

Multiplies the colors this element draws (its box and content, not its children), like the color of uGUI's CanvasRenderer. Not serialized: selectables drive it for their transitions.

View Source​
Declaration
public Color Tint { get; set; }

RaycastTarget​

View Source​
Declaration
public bool RaycastTarget { get; set; }

ClipChildren​

View Source​
Declaration
public bool ClipChildren { get; set; }

LayoutRect​

The box from the last layout, relative to the parent's box, in canvas units. Updated right before rendering.

View Source​
Declaration
public Rect LayoutRect { get; }

HasVisibleContent​

Whether the element draws content besides its box: it is then hittable. Call Yaui.YauiElement.SyncHittable() when the value changes.

View Source​
Declaration
protected virtual bool HasVisibleContent { get; }

ContentIsMaskShape​

Whether a Yaui.YauiMask on this element takes the shape of the content (the alpha of its images) instead of the box's, while there is content.

View Source​
Declaration
protected virtual bool ContentIsMaskShape { get; }

ContentCount​

The number of content primitives.

View Source​
Declaration
protected int ContentCount { get; }

MeasuresContent​

Whether the size of the element comes from Yaui.YauiElement.MeasureContent(System.Single%2cYaui.YauiMeasureMode%2cSystem.Single%2cYaui.YauiMeasureMode), like a text. Such an element has no children. Must not change while the element is enabled.

View Source​
Declaration
protected virtual bool MeasuresContent { get; }

ContentBox​

The content box (inside the border and the padding) from the last layout, in the local space of the element's box.

View Source​
Declaration
public Rect ContentBox { get; }

Methods​

OnEnable()​

View Source​
Declaration
protected virtual void OnEnable()

OnDisable()​

View Source​
Declaration
protected virtual void OnDisable()

OnDestroy()​

View Source​
Declaration
protected virtual void OnDestroy()

OnTransformParentChanged()​

View Source​
Declaration
protected virtual void OnTransformParentChanged()

OnTransformChildrenChanged()​

View Source​
Declaration
protected virtual void OnTransformChildrenChanged()

OnValidate()​

View Source​
Declaration
protected virtual void OnValidate()

OnDidApplyAnimationProperties()​

View Source​
Declaration
protected virtual void OnDidApplyAnimationProperties()

SyncHittable()​

Updates whether the box receives hits, after the box, the content or the flag changed.

View Source​
Declaration
protected void SyncHittable()

OnBoxChanged()​

Called after the box style was written (e.g. content that uses its corner radii).

View Source​
Declaration
protected virtual void OnBoxChanged()

OnRegistered()​

Called after the element got its slots in a panel (when enabled, or moved to another panel): write the content here. Content written before is gone.

View Source​
Declaration
protected virtual void OnRegistered()

OnUnregistering()​

Called before the element releases its slots, including its content. The stores may already be shut down (domain reload).

View Source​
Declaration
protected virtual void OnUnregistering()

SetContent(ReadOnlySpan<YauiPrimitive>)​

Replaces the content: primitives drawn on top of the box and under the children, in the order given. They follow the element's transform, opacity, tint and clips. Does nothing unless Yaui.YauiElement.IsRegistered; write the content in Yaui.YauiElement.OnRegistered().

View Source​
Declaration
protected void SetContent(ReadOnlySpan<YauiPrimitive> primitives)
Parameters​
TypeName
System.ReadOnlySpan<Yaui.YauiPrimitive>primitives

SetContent(int, in YauiPrimitive)​

Replaces one content primitive, below Yaui.YauiElement.ContentCount.

View Source​
Declaration
protected void SetContent(int index, in YauiPrimitive primitive)
Parameters​
TypeName
System.Int32index
Yaui.YauiPrimitiveprimitive

ClearContent()​

Removes the content.

View Source​
Declaration
protected void ClearContent()

MeasureContent(float, YauiMeasureMode, float, YauiMeasureMode)​

The size of the content (inside the padding and the border) within the given constraints. Called during the layout, on a worker thread, possibly several times with different constraints and concurrently with other elements: read only state captured in Yaui.YauiElement.OnPrepareMeasure(), and no Unity objects.

View Source​
Declaration
protected virtual Vector2 MeasureContent(float width, YauiMeasureMode widthMode, float height, YauiMeasureMode heightMode)
Returns​

Vector2

Parameters​
TypeName
System.Singlewidth
Yaui.YauiMeasureModewidthMode
System.Singleheight
Yaui.YauiMeasureModeheightMode

OnPrepareMeasure()​

Main thread, before a layout that measures the content again: capture what Yaui.YauiElement.MeasureContent(System.Single%2cYaui.YauiMeasureMode%2cSystem.Single%2cYaui.YauiMeasureMode) reads. The layout may run until rendering, while the main thread goes on.

View Source​
Declaration
protected virtual void OnPrepareMeasure()

MarkMeasureDirty()​

The size of the content changed: measures it again at the next layout.

View Source​
Declaration
protected void MarkMeasureDirty()

ScreenToLocal(Vector2, out Vector2)​

Converts a screen position (pixels, origin at the bottom-left, like PointerEventData.position) to the local space of this element's box (canvas units, origin at the top-left, Y down), with the transforms last rendered. False if the element is not in an active panel or the point is not on it.

View Source​
Declaration
public bool ScreenToLocal(Vector2 screenPosition, out Vector2 local)
Returns​

System.Boolean

Parameters​
TypeName
Vector2screenPosition
Vector2local

LocalToScreen(Vector2, out Vector2)​

Converts a point in the local space of this element's box to a screen position (pixels, origin at the bottom-left), with the transforms last rendered.

View Source​
Declaration
public bool LocalToScreen(Vector2 local, out Vector2 screenPosition)
Returns​

System.Boolean

Parameters​
TypeName
Vector2local
Vector2screenPosition

OnLayoutApplied()​

Main thread, once a frame right before rendering: the layout of this element changed (Yaui.YauiElement.LayoutRect, Yaui.YauiElement.ContentBox). Content written here is drawn in this frame.

View Source​
Declaration
protected virtual void OnLayoutApplied()