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
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
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
protected bool IsRegistered { get; }
Layout
View Source
public LayoutStyle Layout { get; set; }
Box
View Source
public BoxStyle Box { get; set; }
BackgroundColor
View Source
public Color BackgroundColor { get; set; }
RenderTransform
View Source
public TransformStyle RenderTransform { get; set; }
Translate
View Source
public Vector2 Translate { get; set; }
Rotation
Degrees, clockwise.
View Source
public float Rotation { get; set; }
Scale
View Source
public Vector2 Scale { get; set; }
Opacity
Multiplies the opacity of this element and its descendants.
View Source
public float Opacity { get; set; }
Material
View Source
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
public Color Tint { get; set; }
RaycastTarget
View Source
public bool RaycastTarget { get; set; }
ClipChildren
View Source
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
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
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
protected virtual bool ContentIsMaskShape { get; }
ContentCount
The number of content primitives.
View Source
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
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
public Rect ContentBox { get; }
Methods
OnEnable()
View Source
protected virtual void OnEnable()
OnDisable()
View Source
protected virtual void OnDisable()
OnDestroy()
View Source
protected virtual void OnDestroy()
OnTransformParentChanged()
View Source
protected virtual void OnTransformParentChanged()
OnTransformChildrenChanged()
View Source
protected virtual void OnTransformChildrenChanged()
OnValidate()
View Source
protected virtual void OnValidate()
OnDidApplyAnimationProperties()
View Source
protected virtual void OnDidApplyAnimationProperties()
SyncHittable()
Updates whether the box receives hits, after the box, the content or the flag changed.
View Source
protected void SyncHittable()
OnBoxChanged()
Called after the box style was written (e.g. content that uses its corner radii).
View Source
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
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
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
protected void SetContent(ReadOnlySpan<YauiPrimitive> primitives)
Parameters
| Type | Name |
|---|---|
System.ReadOnlySpan<Yaui.YauiPrimitive> | primitives |
SetContent(int, in YauiPrimitive)
Replaces one content primitive, below Yaui.YauiElement.ContentCount.
View Source
protected void SetContent(int index, in YauiPrimitive primitive)
Parameters
| Type | Name |
|---|---|
System.Int32 | index |
| Yaui.YauiPrimitive | primitive |
ClearContent()
Removes the content.
View Source
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
protected virtual Vector2 MeasureContent(float width, YauiMeasureMode widthMode, float height, YauiMeasureMode heightMode)
Returns
Vector2
Parameters
| Type | Name |
|---|---|
System.Single | width |
| Yaui.YauiMeasureMode | widthMode |
System.Single | height |
| Yaui.YauiMeasureMode | heightMode |
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
protected virtual void OnPrepareMeasure()
MarkMeasureDirty()
The size of the content changed: measures it again at the next layout.
View Source
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
public bool ScreenToLocal(Vector2 screenPosition, out Vector2 local)
Returns
System.Boolean
Parameters
| Type | Name |
|---|---|
Vector2 | screenPosition |
Vector2 | local |
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
public bool LocalToScreen(Vector2 local, out Vector2 screenPosition)
Returns
System.Boolean
Parameters
| Type | Name |
|---|---|
Vector2 | local |
Vector2 | screenPosition |
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
protected virtual void OnLayoutApplied()