1.145 class slider

A slider is a graphical representation of a numeric value in a predefined range. The value can be changed by dragging the slider. Sliders are commonly used to view/edit numeric values that should not be exact (it is difficult to drag to an exact value). Examples are the speed of something or a percentage(done).

A slider selects or visualises an numeric value in the range (slider<-low, slider<-high). Its current value is (as with all dialog_item objects) accessible through slider<->selection. The exact value is normally shown in textual form as well. This may be controlled by slider<->show_value. slider->show_label determines whether or not the label visible.

If either slider<-low or slider<-high is a real object, the slider will assume it operates on floating point numbers. If both slider<-low and slider<-high is integer, the slider will assume integer values. So, to specify a slider from 0 to 10 in floating point, use:

?- new(S, slider(value, 0,0, 10.0, 5.0)).

When a slider is operated by the user (by dragging the value), dialog_item<-message may be send either on termination or at each drag-event. This is controlled by slider<->drag. When message is executed, the arguments are:

@receiver The slider
@arg1 The current slider<-selection
@arg2 The event object.

Bugs: Sliders should be able to handle ranges of floating-point numbers too.

See also
- class scroll_bar
- class dialog_item
- class text_item

1.145.1 Instance variables

slider-default: int|real|function
The default selection or function to get it. Used by slider->restore.
slider <-> drag: bool
When @on, dialog_item<-message will be activated on each drag-event received by the slider. Otherwise, dialog_item<-message will only be sent when the mouse-button is released.

Defaults: @off (only send at mouse-up).

slider <- format: [name]
Format specification used to represent the textual values. The specification is as for the C printf() call (see also string->format). The default format for floating point values is %f and for integers %d. The following defines a slider in 0.01 steps from 0.0 .. 1.0:
?- new(S, slider(value, 0.0, 1.0, 0.5)),
   send(S, format, '%.2f').
slider <- high: int|real
Together with slider<-low this variable describes the (including) range.
See also
- slider-selection
- slider-low
dialog_item <- label_font: font*
Font used to print the dialog_item<-label if slider<-show_label equals @on.
See also
slider-show_label
slider <- low: int|real
Lowest value for slider<->selection. See slider->high.
See also
- slider-selection
- slider-high
slider <- selection: int|real
Current value. An integer for which slider<-low <= slider<-selection <= slider<-high.
See also
- slider-high
- slider-low
slider <- show_label: bool
When @on, the dialog_item<-label of the slider is printed at the left-side in dialog_item<-label_font.

Defaults: @on

See also
- slider-show_value
- slider-label_font
slider <- show_value: bool
When @on, the current value is printed in textual format too. It will be printed in slider<-value_font.

Defaults: @on

See also
- slider-value_font
- slider-show_label
slider <- value_font: font
@see slider-show_value
slider-width: int
Length of the bar-part of the slider in pixels.

Defaults: 200 pixels.

1.145.2 Send methods

slider ->compute:
Computes the layout and sets graphical<-area and slider<-reference using the various attributes.
slider ->default: value=int|real|function
Sets the -default value and the slider->selection.
slider ->event: event
A slider is operated by the left pointer-button. It will execute it's dialog_item<-message when the user releases the button (slider<-drag: @off) or anytime the user moves the pointer with the button held down (slider<-drag: @on).

First tries dialog_item<-event.

slider ->initialise: name, low=int|real, high=int|real, value=int|real|function, message=[code]*
Create a slider object from its dialog_item<-label, slider<-low, slider<-high and slider->default.
slider ->modified: bool
Inherits description from: slider<-modified

1.145.3 Get methods

slider <-default: -> int|real
If -default holds a function, execute it and return the result. Otherwise return the plain value of -default. Used by slider->restore.
slider <-modified: -> bool
A slider is considered modified if the currently displayed value (slider<-selection) is not equal to the slider<-displayed_value.

slider->modified: @off sets slider<-displayed_value to slider<-selection.