UIElement

open class UIElement

The UIElement class is the base class for all ui widgets available in the SDK.

Each UIElement can be added directly to a screen or to a UIElementsGroup in order to draw it on the glasses display.

Similar to common UI elements, the UIElement has many options like defining its

  • X,Y location

  • Dimensions

  • Color

  • Style

  • Visibility

  • And more...

The SDK arrives with several stock ui elements (e.g. Polygon,Text, Line...).

You can easily create your own ui elements and complex custom controls.

Samples can be found in the SDK samples repository

See also

Inheritors

Constructors

Link copied to clipboard
constructor()

Default constructor. Id is auto generated

constructor(id: String)

Constructor with an id for the UI element

Functions

Link copied to clipboard

Add the UI element to the given group

Link copied to clipboard

Add the UI element to the given screen

Link copied to clipboard

Return the ui element Animator for performing animations

Link copied to clipboard

Cancel the ui element animations

Link copied to clipboard

Clear the background color if the ui element

Link copied to clipboard
fun clip(shouldClip: Boolean): UIElement

Clip the UI element rendering to its boundaries

Link copied to clipboard
protected open fun drawBackground(canvas: CanvasBuffer)

Draws the ui element background

Link copied to clipboard
protected open fun drawBorder(canvas: CanvasBuffer, color: Int, widthPix: Int, cornerRadiusPix: Float)

Override this function to enable custom border drawing when showBorder is true

Link copied to clipboard
open fun getBackgroundColor(): Int?

Get the foreground color of the ui element

Link copied to clipboard

Returns the bounding box of the ui element in screen coordinates

Link copied to clipboard

Get the foreground color of the ui element

Link copied to clipboard
open fun getHeight(): Float

Receive the ui element height

Link copied to clipboard

Get the ui element line style

Link copied to clipboard

Returns the parent ui element group

Link copied to clipboard

Get the ui element pen shape

Link copied to clipboard

Get the ui element pen thickness

Link copied to clipboard
open fun getScreenX(): Float

Return the absolute screen X position

Link copied to clipboard
open fun getScreenY(): Float

Return the absolute screen Y position

Link copied to clipboard
open fun getWidth(): Float

Receive the ui element width

Link copied to clipboard
open fun getX(): Float

Return the element X position (relative to its parent)

Link copied to clipboard
open fun getY(): Float

Return the element Y position (relative to its parent)

Link copied to clipboard
open fun hasAnimation(): Boolean

Return true if the ui element has any active animations

Link copied to clipboard

Returns true when the element has a parent

Link copied to clipboard
open fun invalidate(): UIElement

Invalidates the ui element, forcing it to be re-drawn on the next onDraw

Link copied to clipboard

Returns true when the element is attached to screen

Link copied to clipboard
open fun isDirty(): Boolean

Return true if the ui element was changed from the last draw

Link copied to clipboard
open fun isVisible(): Boolean

Returns the ui element visibility

Link copied to clipboard
protected open fun onAttachedToScreen()

Override this function to be notified when the ui element is attached to a screen

Link copied to clipboard
protected open fun onBeforeDetachFromScreen()

Override this function to be notified when the ui element is about to be detached from a screen

Link copied to clipboard
protected open fun onBeforeDraw(timestampMs: Long)

Override this function to be notified when the ui element is about to be drawn

Link copied to clipboard
protected open fun onCreate()

Override this function to be notified when the ui element is ready for its creation

Link copied to clipboard
protected open fun onDraw(canvas: CanvasBuffer)

The draw method is called to actually draw the ui element visual representation to the CanvasBuffer

Link copied to clipboard
protected open fun onLayout()

This function is called after the rendering tree onBeforeDraw cycle was completed and before the onDraw cycle is called

Link copied to clipboard

Removes the UIElement from its parent group

Link copied to clipboard

Reset all applied transformation (including animations)

Link copied to clipboard
open fun rotate(angleDegrees: Float): UIElement
open fun rotate(angleDegrees: Float, px: Float, py: Float, pivot: Pivot = Pivot.RelativeToSelf): UIElement

Sets the rotation angle for the ui element

Link copied to clipboard
fun scale(factor: Float): UIElement
fun scale(factor: Float, px: Float, py: Float, pivot: Pivot = Pivot.RelativeToSelf): UIElement

Sets the x & y scale factor for the ui element

open fun scale(sx: Float, sy: Float): UIElement
open fun scale(sx: Float, sy: Float, px: Float, py: Float, pivot: Pivot = Pivot.RelativeToSelf): UIElement

Sets the x,y scale factor for the ui element

Link copied to clipboard
open fun setBackgroundColor(color: Int): UIElement

Set the background color of the ui element

Link copied to clipboard
fun setBorderStyle(color: Int, widthPix: Int, cornerRadiusPix: Float): UIElement

Set the UIElement border style

Link copied to clipboard
open fun setDimensions(x: Float, y: Float, width: Float, height: Float): UIElement

Sets the ui element dimensions

Link copied to clipboard
open fun setForegroundColor(color: Int): UIElement

Set the foreground color of the ui element

Link copied to clipboard
open fun setHeight(height: Float): UIElement

Sets the ui element height

Link copied to clipboard

Set the ui element line style

Link copied to clipboard

Set the ui element pen shape

Link copied to clipboard
fun setPenThickness(thicknessPixels: Int): UIElement

Set the ui element pen thickness

Link copied to clipboard
open fun setVisibility(isVisible: Boolean): UIElement

Change the ui element visibility (Hide\Show the ui element)

Link copied to clipboard
open fun setWidth(width: Float): UIElement

Sets the ui element width

Link copied to clipboard
open fun setWidthHeight(width: Float, height: Float): UIElement

Sets the ui element size

Link copied to clipboard
open fun setX(x: Float): UIElement

Sets the element X position within its parent

Link copied to clipboard
open fun setXY(x: Float, y: Float): UIElement

Sets the element X and Y position within its parent

Link copied to clipboard
open fun setY(y: Float): UIElement

Sets the element Y position within its parent

Link copied to clipboard

Show a rectangle border according the UIElement getWidth and getHeight

Link copied to clipboard

Start the ui element animations

Link copied to clipboard
open override fun toString(): String

To String

Link copied to clipboard
open fun translateBy(dx: Float, dy: Float): UIElement

Sets the x,y translations of the ui element

Link copied to clipboard
open fun translateTo(x: Float, y: Float): UIElement

Sets the x,y translations of the ui element

Link copied to clipboard

Returns true when the element was created (the onCreate was called)

Properties

Link copied to clipboard

The screen which the ui element is attached to (if exists).

Link copied to clipboard
var Id: String

The ID of the screen. auto generate when using default constructor.

Link copied to clipboard
var tag: Any?

A Generic tag that can be attached to the UI Element