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.
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 |
Sets the local value of a property type.
-- 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)
propertyType | (PropertyType) | The PropertyType instance identifying the property to set. |
value | (string, number, boolean, KanziObject or userdata) | The value to set. |
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:
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.
If no inputs to the property value can be established the system returns the value registered in the property type metadata.
-- 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)
propertyType | (PropertyType) | The PropertyType instance identifying the property to retrieve. |
(string, number, boolean, KanziObject or userdata) | Returns the evaluated property value. |
Tries to create an owning ObjectRef instance to this KanziObject. If the object is already stale, returns nil.
-- 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)
(ObjectRef or nil) | Owning ObjectRef instance. If the object is stale, returns nil. |
Returns whether an object is stale and its native object was deleted.
(boolean) | If the object is stale, true, otherwise false. |