Developer Resources

Slider

Overview

The Slider class represents a slider control.

Base Class

FormControl

Constructor

Slider(orientation : Integer, x_pos : Integer, y_pos : Integer, width : Integer, height : Integer)

Arguments

orientation
Determines the manner in which to create the Slider object, depending on whether it's Slider.Horizontal or Slider.Vertical.
x_pos
The x position of the control.
y_pos
The y position of the control.
width
The width of the control.
height
The height of the control.

Events

Slider.scroll
Fired when the slider moves.
Slider.scrollBottom
Fired when the slider moves to the maximum value of its range.
Slider.scrollDown
Fired when the slider moves a single interval towards its maximum value.
Slider.scrollPageDown
Fired when the slider moves a page interval towards its maximum value.
Slider.scrollPageUp
Fired when the slider moves a page interval towards its minimum value.
Slider.scrollTop
Fired when the slider moves to the minimum value of its range.
Slider.scrollUp
Fired when the slider moves a single interval towards its minimum value.
Slider.track
Fired when the slider is being moved by dragging it with the mouse
Slider.trackRelease
Fired when the slider is released from being dragged by the mouse

Properties

Slider.Horizontal
A flag representing that a horizontal slider should be created.
Slider.Vertical
A flag representing that a vertical slider should be created.

Methods

Slider.getLineSize
Gets the number of steps the slider moves when the slider bar is moved.
Slider.getMax
Gets the maximum value of the slider.
Slider.getMin
Gets the minimum value of the slider.
Slider.getPageSize
Gets the number of steps the slider moves on page up or page down.
Slider.getValue
Gets the position of the slider.
Slider.setLineSize
Sets the number of steps the slider moves when the slider bar is moved.
Slider.setPageSize
Sets the number of steps the slider moves on page up or page down.
Slider.setRange
Sets the minimum and maximum value the slider can have.
Slider.setValue
Sets the position of the slider.

Inherited Methods

FormControl.captureMouse
Captures the mouse on this form control.
FormControl.disablePaint
Disables the window from redrawing itself.
FormControl.enablePaint
Enables the window to redraw itself.
FormControl.getBackgroundColor
Gets the background color of the form control.
FormControl.getClientSize
Gets the client size of the form control.
FormControl.getEnabled
Indicates whether or not a form control is enabled.
FormControl.getFont
Gets the default font for the text of form control.
FormControl.getForegroundColor
Gets the foreground color of the form control.
FormControl.getMaxSize
Gets the maximum size of the form control.
FormControl.getMinSize
Gets the minimum size of the form control.
FormControl.getMousePosition
Gets the mouse position relative to this form control.
FormControl.getNativeHandle
Gets the native handle of the window/control
FormControl.getPosition
Gets the position of a form control.
FormControl.getSize
Gets the size of the form control.
FormControl.invalidate
Invalidates a form control, which will cause it to be repainted on the next paint event.
FormControl.refresh
Refreshes a form control, which immediately repaints the entire form control.
FormControl.releaseMouse
Releases the mouse from being captured on this form control.
FormControl.setBackgroundColor
Sets the background color of the form control.
FormControl.setClientSize
Sets the client size of a form control.
FormControl.setEnabled
Enables or disables the form control.
FormControl.setFocus
Sets the focus to the form control.
FormControl.setFont
Sets the default font for the text of the form control.
FormControl.setForegroundColor
Sets the foreground color of the form control.
FormControl.setMaxSize
Sets the maximum size of a form control.
FormControl.setMinSize
Sets the minimum size of a form control.
FormControl.setPosition
Sets the position of a form control relative to the the form control's parent.
FormControl.setSize
Sets the size of a form control.
FormControl.show
Shows or hides the form control.
FormControl.update
Updates a form control, which will immediately repaint any invalid areas.

Example

// create a new slider sample form
var f = new MyForm("Slider Example", 0, 0, 400, 300);
f.center();
f.show();
Application.run();


// define the slider sample form
class MyForm extends Form
{
    var m_slider;
    var m_line;
    var m_textbox;
    var m_layout;

    function MyForm(caption, x_pos, y_pos, width, height)
    {
        // MyForm() gets called when a new object is created;
        // the super() function calls the contructor on the
        // base class, which in this case is Form since MyForm
        // extends Form
        super(caption, x_pos, y_pos, width, height);
    
        // create a new slider, with a range from 0 to 200 
        // units and an initial value of 100
        m_slider = new Slider;
        m_slider.setRange(0, 200);
        m_slider.setValue(100);
        
        // create a new line and textbox
        m_line = new Line(Line.Horizontal);
        m_textbox = new TextBox();
        m_textbox.setMultiline(true);

        // connect the slider events to the slider handler; these 
        // handlers will be called when the corresponding slider event 
        // is fired; here, we use one handler, onSliderChanged, for 
        // simplicity, but we could also add different handlers 
        // different events
        m_slider.scroll.connect(this, onSliderChanged);
        m_slider.scrollTop.connect(this, onSliderChanged);
        m_slider.scrollBottom.connect(this, onSliderChanged);
        m_slider.scrollUp.connect(this, onSliderChanged);
        m_slider.scrollDown.connect(this, onSliderChanged);
        m_slider.scrollPageUp.connect(this, onSliderChanged);
        m_slider.scrollPageDown.connect(this, onSliderChanged);
        m_slider.track.connect(this, onSliderChanged);
        m_slider.trackRelease.connect(this, onSliderChanged);
        
        // connect the form resize event
        this.sizeChanged.connect(this, onFormSizeChanged);

        // add the slider, line, and the textbox to the form
        m_layout = new BoxLayout(Layout.Vertical);
        m_layout.addSpacer();
        m_layout.add(m_slider, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
        m_layout.addSpacer(10);
        m_layout.add(m_line, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
        m_layout.addSpacer(10);
        m_layout.add(m_textbox, 1, Layout.Expand | Layout.Left | Layout.Right, 5);
        m_layout.addSpacer();
        
        // use m_layout for the main form layout
        setLayout(m_layout);
    }

    function onSliderChanged(sender, event_args)
    {
        // when the slider is changed, append text to the textbox 
        // with the new slider value
        m_textbox.appendText("Slider changed: " + event_args.value + "\n");
    }
    
    function onFormSizeChanged(sender, event_args)
    {
        // when the form is resized, append text to the textbox
        // with the new form size
        var size = "(" + getSize().width + "," + getSize().height + ")";
        m_textbox.appendText("Form resized: " + size + "\n");
        layout();        
    }    
}

Slider.getLineSize

function Slider.getLineSize() : Integer

Returns

Returns the number of steps the slider moves when the slider bar is moved.

Description

Returns the number of steps the slider moves when the slider bar is moved.

Slider.getMax

function Slider.getMax() : Integer

Returns

Returns the maximum value the slider can have.

Description

Returns the maximum value the slider can have.

Slider.getMin

function Slider.getMin() : Integer

Returns

Returns the minimum value the slider can have.

Description

Returns the minimum value the slider can have.

Slider.getPageSize

function Slider.getPageSize() : Integer

Returns

Returns the number of steps the slider moves on page up or page down.

Description

Returns the number of steps the slider moves on page up or page down.

Slider.getValue

function Slider.getValue() : Integer

Returns

Returns the position of the slider.

Description

Returns the position of the slider.

Slider.setLineSize

function Slider.setLineSize(steps : Integer)

Arguments

steps
The number of steps the slider moves when the slider bar is moved.

Description

Sets the number of steps the slider moves when the slider bar is moved.

Slider.setPageSize

function Slider.setPageSize(increment : Integer)

Arguments

increment
The number of steps the slider moves on a page up or page down.

Description

Sets the number of steps the slider moves on page up or page down.

Slider.setRange

function Slider.setRange(minimum : Integer, maximum : Integer)

Arguments

minimum
The minimum value the slider can have.
maximum
The maximum value the slider can have.

Description

Sets the minimum and maximum value the slider can have.

Slider.setValue

function Slider.setValue(position : Integer)

Arguments

position
The position to which to set the slider.

Description

Sets the position of the slider.