Manuals >User's Guide >Creating Graphic User Interfaces
Print version of this Book (PDF file)
prevnext

More on Sliders (Examples)

Review of Key Features of the Slider

    • The Slider operates both as an input and an output device. When the value representing the slider position is changed, the slider position moves accordingly.
    • The Slider has no output device of its own for numbers. You would typically use an Edit Text box (for editable numbers) or a Label for read-only numbers.
    • The output is an integer.
    • The default min/max range is 0 to 100. The minimum value is 0 or greater, and the maximum value is unlimited.

Six Versions of a Slider GUI (slider.mdl)

SliderVersion1 uses the default settings. The range is 0 to 100 in steps of 1.

The slider option Current Position shares the variable slidePosn with the Edit Text Box option Field Value.

To operate SliderVersion1:

  1   Select SliderVersion1 and click on Display.

  2   Drag the slider button back and forth between its limits. Notice how smoothly it moves. Actually, it moves 2 inches in 100 steps of 0.02 inches.

  3   Edit the number in the text box. When Enter is pressed note how the slider position responds to the edited value. Click on the Model Variables tab. You will see the value of slidePosn responding to our GUI.

  4   When you edit the value of slidePosn in the Model Variables table and then press Enter, you will see both the slider position and the number in the edit box change in response.

SliderVersion2 has the slider Minimum and Maximum values set to 50 and 60 respectively.

To operate SliderVersion2:

  1   Select SliderVersion2 and click on Display.

  2   Drag the slider button back and forth between its limits.

  3   Notice how jerkily it moves. Actually, it moves 2 inches in 10 steps of 0.2 inches.

The values of slidePosn can only be changed in increments of 1 (a coarse resolution of 10%).

SliderVersion3 has the slider Minimum and Maximum values set to 5 and 6 respectively.

To operate SliderVersion3:

  1   Select SliderVersion3 and click on Display.

  2   Drag the slider button back and forth between its limits. Notice how it jumps back and forth between 5 and 6. Actually, it moves 2 inches in a single step without being able to stop in between.

The values of slidePosn can only be changed by an increment of 1 (a coarse resolution of 100%).

SliderVersion4 has the slider Minimum and Maximum reset to the default values of 0 and 100.

To operate SliderVersion4:

  1   Select SliderVersion4 and click on Display.

  2   Drag the slider button back and forth between its limits. Notice how smoothly it moves again (back to the previous 2 inches in 100 steps of 0.02 inches).

  3   The value of the new variable displayVal displayed in the Edit box is now calculated from the value of slidePosn by PEL code in a macro called sliderMoved. Click on the Macros tab to see the calculation:

displayVal=5.0+slidePosn/100

Look at the Properties dialog for the slider Callbacks. We are using the Slider Moving callback to call the Macro sliderMoved. Click on the Slider Moving callback. In the right hand callback editing dialog sliderMoved is shown as the "Item to act on", and Execute as the "action" to take.

As long as the slider is moving, the new value of slidePosn keeps changing in increments of 1 and the callback Slider Moving executes the sliderMoved macro which updates displayVal, which in turn automatically updates the number displayed in the Edit box.

But notice that editing the value of slidePosn in the Variables table has no effect on the value displayed in the Edit box. Similarly, editing the value of displayVal in the Variables table has no effect on the slider's position. This situation is corrected in SliderVersion5.

Look at the Properties dialog for the Edit Text box. The callback Variable Changed is used to call the macro valChanged. Click on the Macros tab to see the calculation:

slidePosn=(displayVal-5.0) * 100

This macro recalculates the value of slidePosn any time displayVal changes. Now if a process changes the value of displayVal, the position of the slider will be automatically updated.

The calling of the valChanged macro is not associated with the Edit Text box but with the value of displayVal changing—for any reason.

To view a demonstration of this, see sliderVersion6.

The Variable Changed callback is now in the Slider callbacks, instead of the Edit Text callbacks where we first put it. You could also put the Variable changed callback in the enclosing Table. But wherever you put it, you only need it in one place.


Note


The callback Variable Changed is associated with the variable it tracks, not the widget where it is specified.

The Variable Changed callback is so useful for making smooth working GUIs that we made it available, for your convenience, on every single widget.



prevnext