Dynamic UI Generation Based on Model¶
The project is composed of two objects in the model: Motor and Klin. These objects own some variables of heterogeneous data types.
The ComlumnLayout1 object owns a NetLogic (UIPopulator) which has the ModelObject variable
attached to it. The aim of this NetLogic object is to iterate the variables of the object pointed by ModelObject. For each variable
the script builds some UI widgets based on the datatype of the variable
(i.e. for a boolean variable it creates a switch, for a float variable it creates a circular gauge). Each widget is added to the owner of the NetLogic (ColumnLayout1).
Moreover, the UIPopulator NetLogic listens to the changes made to the ModelObject variable
(which, in this case, is databound to the SelectedItem of the listbox that lists the two objects of the model):
modelObjectVariable = LogicObject.GetVariable("ModelObject");
modelObjectVariable.VariableChange += ModelObjectVariable_VariableChange;
The ModelObjectVariable_VariableChange
method is called as a callback and the UI is rebuilt based on the object pointed by ModelObject.
Scarica il progetto di esempio da qui
.