UIElement

open class UIElement : Drawable

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
fun addTo(screen: Screen): UIElement

Add the UI element to the given screen

Add the UI element to the given group

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): Drawable

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

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 getXEnd(): Float

Utility method, returns the other X coordinate getX+getWidth

Link copied to clipboard
open fun getY(): Float

Return the element Y position (relative to its parent)

Link copied to clipboard
open fun getYBottom(): Float

Utility method, returns the bottom Y coordinate getY+getHeight

Link copied to clipboard
open fun hasAnimation(): Boolean

Return true if the ui element has any active animations

Link copied to clipboard
open override fun invalidate(): UIElement

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

Link copied to clipboard
open fun isDirty(): Boolean

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

Link copied to clipboard

Gets an existing or creates a new modifier for the UIElement.

Link copied to clipboard
fun UIElement.modify(modifier: (modifier: Modifier) -> Unit): UIElement

Modify the UIElement using a specified modifier function.

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

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

Link copied to clipboard
fun removeAfter(removeAfterMs: Long): UIElement
fun removeAfter(removeAfterMs: Long, onRemove: (UIElement) -> Unit): UIElement

The UIElement is automatically removed after removeAfterMsms

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 override 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 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