Step 2 - Control UI elements

In this step of the tutorial you add widgets to the cluster UI and learn:

  • How to use the Activity nodes to create a structure that enables you to show the same widget presented in a different layout, depending on the application state.

  • How to use Activity controller properties to control which node is active in an Activity Host node.

Create the structure for the widgets

In this section you learn how to use the Activities to create a structure that enables you to show the same widget presented in a different layout, depending on the cluster mode:

  • Maximized widget in the Drive mode

  • Minimized widget in the Browse mode

To create the structures for the widgets:

  1. In the Activity Browser in the GaugeViewActivityHost Activity Host:

    1. Add an Activity and name it and its prefab LeftArea.

      You use the LeftArea Activity to show the widgets on the left side of the main gauge.

      ../../_images/create-left-area.png
    2. In the LeftArea Activity create an Exclusive Activity Host named MaximizedMinimizedSwitcher.

      You use this Exclusive Activity Host to show either large widgets in the Drive mode or small widgets in the Browse mode.

      An Exclusive Activity Host can have only one of its child Activities active at a time. In the Activity Browser Exclusive Activity Hosts are teal.

      ../../_images/create-maximizedminimizedswitcher.png
    ../../_images/ab-leftarea-w-switcher.png
  2. In the Activity Browser select the LeftArea Activity and in the side panel set the InitiallyActive property to enabled.

    This way you set the widgets in the left area to always be visible, regardless of the cluster mode.

    ../../_images/ab-leftarea-initiallyactive.png
  3. In the Activity Browser create the structure for the widgets when they are maximized:

    1. In the MaximizedMinimizedSwitcher Activity Host add an Activity named MaximizedLeft, and inside it add an Exclusive Activity Host named MaximizedWidget.

      You use an Exclusive Activity Host because you want to show in the left area only one maximized widget at a time.

      ../../_images/create-maximizedleft.png ../../_images/ab-maximizedleft.png
    2. In the Prefabs select the MaximizedLeft > MaximizedWidget node and in the properties add and set:

      • Horizontal Padding property Left property field to 220

      • Vertical Padding property Top property field to 220

      For the purpose of this tutorial you use these properties to set the absolute position of maximized widgets in the cluster. In a real project, the best way to position such UI elements is to use one of the Kanzi layouts.

      ../../_images/prefabs-maximizedwidget.png ../../_images/properties-maximizedwidget.png
    3. In the Activity Browser in the MaximizedWidget Activity Host add these Activities:

      • WidgetBatteryMaximized

      • WidgetMusicMaximized

      • WidgetNavigationMaximized

      ../../_images/ab-maximizedwidget-activities.png
    4. In the Prefabs drag:

      • WidgetBatteryMaximizedImage to the WidgetBatteryMaximized prefab

      • WidgetMusicMaximizedImage to the WidgetMusicMaximized prefab

      • WidgetNavigationMaximizedImage to the WidgetNavigationMaximized prefab

      ../../_images/prefabs-maximized-widgets.png

    Tip

    The Activity Browser simulates the activation of Activities in your application. To see the content of an Activity in the Preview, you can manually activate it in the Activity Browser by clicking activate in the Activity that you want to activate.

    When an Activity is active, in the Activity Browser it gets a check mark and the node border turns blue.

    ../../_images/ab-activate-manually.gif
  4. Create the structure for the widgets when they are minimized:

    1. In the MaximizedMinimizedSwitcher Activity Host add an Activity named MinimizedLeft, and inside it add an Exclusive Activity Host named MinimizedWidget.

      You use an Exclusive Activity Host because you want to show in the left area only one minimized widget at a time.

      ../../_images/create-minimizedleft.png ../../_images/ab-minimizedwidget.png
    2. In the Prefabs select the MinimizedLeft > MinimizedWidget node and in the properties add and set:

      • Horizontal Padding property Left property field to 200

      • Vertical Padding property Top property field to 610

      ../../_images/prefabs-minimizedwidget.png ../../_images/properties-minimizedwidget.png
    3. In the Activity Browser in the MinimizedWidget Activity Host add these Activities:

      • WidgetBatteryMinimized

      • WidgetMusicMinimized

      • WidgetNavigationMinimized

      ../../_images/ab-minimizedwidget-activities.png
    4. In the Prefabs drag:

      • WidgetBatteryMinimizedImage to the WidgetBatteryMinimized prefab

      • WidgetMusicMinimizedImage to the WidgetMusicMinimized prefab

      • WidgetNavigationMinimizedImage to the WidgetNavigationMinimized prefab

      ../../_images/prefabs-minimized-widgets.png

To see the widgets in the Preview, in the Activity Browser click activate in the Activity that you want to activate.

../../_images/widgets-preview.gif

Control activation of nodes with a controller property

In this section you learn how to use activity controller properties to control which node is active in an Activity Host.

To control activation of nodes with a controller property:

  1. In the Activity Browser select the MaximizedMinimizedSwitcher Activity Host, in the side panel in the Controller Source click controller-source, select Property, and set the Property to the ActivityProperty.Cluster.MainView property.

    This way you set the property that you want to use to control which Activities an Activity Host activates.

    An Activity node takes the value of a controller property from the closest ancestor node that has the same controller property that you set in that Activity node. In this case this is the Cluster node.

    ../../_images/ab-maximizedminimizedswitcher-controller-source.png ../../_images/ab-select-controller-property.png

    Tip

    When you set a controller property, the Activity Browser assigns the values from that controller property to the ControllerValue property of child Activities in that Activity Host. In an Activity node, the value of the ControllerValue property sets when an Activity Host activates that Activity.

    If the number of value options in a controller property and the number of child Activities do not match, you must set manually in each child Activity the value of the ControllerValue property.

    ../../_images/ab-controllervalue-drive.png ../../_images/ab-controllervalue-browse.png
  2. In the Library > Property Types > ActivityProperty press Alt and right-click, select Property Type, and in the New Property Type window set:

    • Name to ActivityProperty.LeftWidget

    • Category to Controller Properties

    • Data Type to Enumeration

    • Enumeration Options to:

      Key

      Value

      Battery

      0

      Music

      1

      Navigation

      2

    You use this Activity Controller Property to control which Activity is active in the MaximizedWidget and MinimizedWidget Activity Hosts.

    ../../_images/leftwidget-controller-property.png ../../_images/library-property-leftwidget.png
  3. In the Node Tree select the Cluster node, in the Properties add the Controller Properties > ActivityProperty.LeftWidget property.

    An Activity node takes the value of a controller property from the closest ancestor node that has the same controller property that you set in that Activity node. In this case this is the Cluster node.

    After you add a controller property to an Activity Host, you can set the value of that property in the Activity Browser in the side panel.

    ../../_images/node-tree-root-pah.png ../../_images/properties-controller-property-leftwidget.png
  4. In the Activity Browser select the MaximizedWidget Activity Host, in the side panel click controller-source, and set the Property to the ActivityProperty.LeftWidget property.

    This way you set the MaximizedWidget Exclusive Activity Host to use the ActivityProperty.LeftWidget property to show a widget when the cluster is in the Drive mode.

    ../../_images/ab-minimizedwidget-controller-source.png ../../_images/ab-minimizedwidget-select-controller-property.png

    The Activity Browser assigns the values from that controller property to the ControllerValue property of child Activities in that Activity Host.

    ../../_images/ab-controllervalue-battery.png ../../_images/ab-controllervalue-music.png ../../_images/ab-controllervalue-navigation.png
  5. Repeat the previous step for the MinimizedWidget Exclusive Activity Host.

    This way you set the cluster to show the same widget in the Browse mode as in the Drive mode, but the minimized version.

    Tip

    To see in the Activity Browser which Activity Host sets the value of a controller property, select an Exclusive Activity Host and in the side panel click show-controller-property.

    ../../_images/ab-show-controller-property1.png ../../_images/ab-show-controller-property-canvas.png

Now when you select in the Activity Browser the Cluster node you can in the side panel switch between the Drive and Browse modes, and set the widget that you want to show in both modes.

../../_images/ab-left-area.gif

< Previous step

See also

To learn more about the Activity system, see Activities.

To learn more about Kanzi layouts, see Layout control nodes.