Tutorial: Creating a slider

In this tutorial you learn how to create a slider in Kanzi Studio.

This video shows the result of the tutorial.

This tutorial assumes you understand the basics of working with Kanzi Studio. The best entry points for getting familiar with Kanzi Studio are:

Assets for the tutorial

The starting point of this tutorial is the Slider.kzproj Kanzi Studio project file stored in the <KanziWorkspace>/Tutorials/Slider/Assets directory.

The <KanziWorkspace>/Tutorials/Slider/Completed directory contains the completed project of this tutorial.

Create the slider structure

In this section you create the structure for the slider.

To create the slider structure:

  1. In Kanzi Studio open the project stored in the <KanziWorkspace>/Tutorials/Slider/Assets directory.
  2. In the Prefabs create a Slider 2D prefab and inside it create:
  3. In the Prefabs select the Rail node and in the Properties set the Image property to the Rail image.
  4. In the Prefabs select the Knob node and in the Properties set the Image property to the Knob image.
  5. Create a line trajectory that acts as the rail along which the knob of the slider moves:
    1. In the Library press Alt and right-click Trajectories and select the Line Trajectory.
    2. In the Properties set:
      • Length to 256.
        Set the Length property to the same length as is the length in pixels of the visual representation of the rail.
      • Direction X property field to 1, all other property fields to 0.
        This way you set the trajectory of the slider on the x axis so that the slider knob moves horizontally on the rail.
  6. In the Prefabs select the Trajectory Layout 2D and in the Properties set the Trajectory property to the Line Trajectory you created in the previous step.
  7. Create an alias that Kanzi uses to tell the slider which trajectory to use as the rail of the slider:
    1. In the Prefabs select the Slider 2D prefab, in the Dictionaries window click + Add Resource, and select Create > Alias.
    2. Name the alias $layout and set it to point to the Trajectory Layout 2D node in the Slider 2D prefab.
      Kanzi uses this alias to tell the slider along which trajectory to move the slider knob.

Set the slider size and make the knob move along the trajectory

In this section you set the layout sizes of the slider and the visual representation of the slider rail to meet the size of the visual representation and the trajectory along which the knob on the slider moves.

To set the slider sizes and make the knob move along the trajectory:

  1. From the Prefabs drag the Slider 2D to the Project and drop it on the Frame node to instantiate the prefab.
  2. In the Preview click to enter the Analyze mode, right-click , deselect 3D Grid, and select:
  3. In the Project select the instantiated Slider 2D prefab, in the Preview select the Node tool and click the center square to align the Slider 2D prefab instance to the center of the Frame node.
  4. In the Prefabs select the Slider 2D prefab, and in the Properties add and set:
  5. In the Prefabs select the Rail node, and in the Properties add and set:
  6. In the Prefabs select the Trajectory Layout 2D node, and in the Properties add and set:
  7. In the Prefabs select the Knob node, in the Properties add the Bindings property, and in the Binding Argument Editor set:Click Save.
  8. In the Preview click to exit the Analyze mode, click to enter the Interact mode, and click and drag the slider knob along the rail.

What's next?

In this tutorial you learned how to create a slider. Now you can:

See also

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

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

To learn more about creating Kanzi applications, see Tutorials.