Step 1 - Navigate the application screens

In this step, you learn how to create navigation for application screens. You enable the user to navigate the application screens using both touch and key input.

Assets for the tutorial

The starting point of this tutorial is the <KanziWorkspace>/Tutorials/UI navigation/Start/UI navigation.kzproj Kanzi Studio project.

You can find the completed Kanzi Studio project of this tutorial in the <KanziWorkspace>/Tutorials/UI navigation/Completed directory.

The starting point project contains the content that you need to complete this tutorial:

  • The MainScreen Activity prefab contains:

    • The NavigationBar toggle button group that shows the navigation button menu.

      In the NavigationBar, the toggle buttons are instances of the NavigationButton prefab. The NavigationButton prefab uses a state manager that sets the appearance of the toggle button based on its toggle state.

      In this tutorial, you use these toggle buttons to activate the application screens.

      ../../_images/preview-navigation-bar.png
    • ApplicationScreens Exclusive Activity Host contains Activities that each represent an application screen:

      • Home contains a temperature slider.

      • Media contains lists of albums, playlists, and radio stations.

      • Maps contains a static image.

      • Settings contains a settings menu.

      In this tutorial, you learn how enable the user to move between these screens and interact with UI elements in each screen using both touch and key input.

      ../../_images/activity-browser-preview-start.gif
  • The AlbumItem, PlaylistItem, RadioItem, and SettingsItem prefabs are the templates for the items in different types of lists.

    ../../_images/prefabs-list-item-prefabs-selected.png
  • In the Media Activity prefab, the Albums, Playlists, and Radio are instances of the MediaList prefab. The MediaList contains a customizable title and a Grid List Box node that shows a list with a customizable item template and items source. The Media Activity gets the list items from a data source.

    ../../_images/prefabs-albums-playlists-radio.png
  • In the Settings Activity prefab, the list items in the SettingsMenu are instances of the SettingsItem prefab.

    ../../_images/prefabs-settings-menu.png
  • Library > State Managers > List State Manager sets the background brush of a node based on the focus state.

    You use this state manager in Step 2 of this tutorial.

    ../../_images/library-list-state-manager.png

Set the focus at application startup

In this section, you set the node that receives the key focus when application starts.

To receive key input, a node must be focusable. A focusable node has the Focusable property enabled. Interactivity control nodes, such as the Slider and Button nodes, have the Focusable property enabled by default.

In this tutorial project, the application screens are Activities. Activity nodes are focus scopes and handle the key focus and key input by default. A focus scope helps handle the key navigation. When the key focus moves to a focus scope node, that focus scope forwards the focus to its first focusable child node.

To set the key focus at application startup:

  1. In the Prefabs, select the MainScreen > Dock Layout 2D > ApplicationScreens Exclusive Activity Host.

    ../../_images/prefabs-application-screens.png
  2. In the Properties, add the Focus On Activating Activity property and set it to Always.

    This way, you set the key focus to the Home Activity that the application activates when the application starts.

    When the Home Activity activates, Kanzi moves the focus to that Activity. The Home Activity forwards the focus to its only focusable node, the Slider node. The Slider node becomes the key focus node, which receives key input.

    ../../_images/properties-focus-on-activating-activity.png

Now, when you select the Preview window, you can use these keys to adjust the temperature using the slider on the home screen:

  • (Up) and (Down) to move the knob

  • Home to move the slider knob to the bottom of the rail

  • End to move the slider knob to the top of the rail

Slider nodes handle the input from these keys by default.

../../_images/preview-slider-key-input.gif

See also

To learn more about how to use the Activity Browser, see Using the Activity Browser.

To learn more about the Activity system, see Activities.

To learn more about using bindings, see Using bindings and Bindings expressions reference.

To learn more about using sliders, see Using the Slider nodes.

To learn more about focus, see Focus and Using focus.

To learn more about handling user input in Kanzi, see Handling user input.

To learn more about triggers and actions, see Triggers.

To learn more about using the List Box nodes, see List Box nodes.