Class KanziObject

The base class for the Kanzi UI classes that implement association with a Domain and supports setting and retrieving of property types.

This class contains a non-owning reference to the underlying runtime object.

See also ObjectRef

Synopsis

Methods
setProperty()

Sets the local value of a property type

getProperty()

Returns the current value of a property type

tryCreateReference()

Tries to create an owning ObjectRef instance to this KanziObject

isStale()

Returns whether an object is stale and its native object was deleted

KanziObject:setProperty(propertyType, value)

Sets the local value of a property type.

Example
-- Using a string property type.
contextNode:setProperty(Node.NameProperty, "New name")
-- Using a ColorRGBA property type.
local brush = ColorBrush:create("Color brush")
local color = ColorRGBA(1.0, 0.0, 0.0, 1.0)
brush:setProperty(ColorBrush.ColorProperty, color)
-- Using a Resource property type.
contextNode:setProperty(Node2D.BackgroundBrushProperty, brush)
Parameters
propertyType (PropertyType)

The PropertyType instance identifying the property to set.

value (string, number, boolean, KanziObject or userdata)

The value to set.

KanziObject:getProperty(propertyType)

Returns the current value of a property type.

This function returns a value that is the result of the property system evaluating the inputs that can affect the values of properties. It calculates the final value by determining the base value of the property and applying existing modifiers to it.

Base value is affected by the following inputs where the highest entry in the list determines the base value:

  1. Local value set with setProperty or loaded from kzb
  2. Value set by a style affecting the property.
  3. Value defined by class metadata.

When the base value is determined the system applies modifiers to the value that can change the value or replace it completely. The following is the list of possible modifiers, where the order of evaluation is determined by the order the modifiers were added or applied.

  1. Values defined in the states of a state manager.
  2. Animations.

If no inputs to the property value can be established the system returns the value registered in the property type metadata.

Example
-- Retrieve a string property type.
local name = contextNode:getProperty(Node.NameProperty)
print("The name of the node is " .. name)
-- Retrieve a Resource property type.
local brush = contextNode:getProperty(Node2D.BackgroundBrushProperty)
-- Retrieve a ColorRGBA property type.
local color = brush:getProperty(ColorBrush.ColorProperty)
Parameters
propertyType (PropertyType)

The PropertyType instance identifying the property to retrieve.

Return Values
(string, number, boolean, KanziObject or userdata)

Returns the evaluated property value.

KanziObject:tryCreateReference()

Tries to create an owning ObjectRef instance to this KanziObject. If the object is already stale, returns nil.

Example
-- Take the first child node of the context node.
local childNode = contextNode:getChild(0)
-- If you remove a child node without creating a reference, the child node becomes stale,
-- so create an owning reference first.
local childNodeRef = childNode:tryCreateReference()
contextNode:removeChild(childNode)
-- Insert the child node at a new position.
contextNode:insertChild(2, childNode)
Return Values
(ObjectRef or nil)

Owning ObjectRef instance. If the object is stale, returns nil.

KanziObject:isStale()

Returns whether an object is stale and its native object was deleted.

Return Values
(boolean)

If the object is stale, true, otherwise false.