Sanko Robinson > FLTK-0.532009 > FLTK::Slider



Annotate this POD


View/Report Bugs
Module Version: 0.532006   Source  


FLTK::Slider - Slider value control

Description ^

This widget contains a sliding "knob" that controls a single floating-point value. Moving the box all the way to the left or bottom sets it to the minimum( ), and to the top/right to the maximum( ) value. The minimum( ) may be greater than the maximum( ) in case you want the larger number at the opposite end.

See Valuator for how to set or get the value or handle callbacks when the value changes.

The appearance of the base class may be changed in several ways:

Setting the box( ) to any value other than the default of FLAT_BOX will remove the "slot" and draw a box around the slider and the tick marks. The color( ) (which defaults to GRAY75) is used to fill in the area behind the slider and tick marks.

You can use set_vertical( ) to make the slider move up/down rather than horizontally.

The following bits may be or'd together and given to type( ):

The tick marks are placed the slider_size( ) or more apart (they are also no closer than the step( ) value). The color of the tick marks is controlled by textcolor( ), and the font used to draw the numbers is textfont( ) and textsize( ) (which defaults to 8).

You can change the glyph( ) function to change how the moving part is drawn. The drawflags( ) determines what part of the slider is being drawn. The ScrollBar subclass turns on ALIGN_TOP/LEFT/RIGHT/BOTTOM to draw the buttons at the end (this is the same as Widget::default_glyph( ) takes and the default slider glyph just calls that). The moving part has bit 16 turned on, unless this is a fill slider in which case bit 16 is off. You can check the LAYOUT_VERTICAL flag to see which direction the slider is going in.

"Log" sliders have a non-uniform scale. The scale is truly logarithmic if both the minimum( ) and the maximum( ) are non-zero and have the same sign. Otherwise the slider position is the square root of the value (or -sqrt(-value) for negative values).

Functions ^


$slider->draw_ticks( $rect, $min_spacing );

Draw tick marks. These lines cross the passed rectangle perpendicular to the slider direction. In the direction parallel to the slider direction the box should have the same size as the area the slider moves in.


my $self = $slider->new( $x, $y, $w, $h, $label );

Creates a new FLTK::Slider widget.


my $position = $slider->position_value( $x, $w );

This is used by subclasses to handle events correctly:

Return the value if the left/top edge of a box of slider_size( ) is placed at $x pixels from the edge of an area of size $w pixels. The range( ) and log( ) settings are taken into account, and it also rounds the value to multiples of step( ), using powers of 10 larger and multiples of 2 or 5 to get the steps close to 1 pixel so the user is presented with nice numerical values.


my $position = $slider->slider_position( $value, $w );

This is used by subclasses to draw the slider correctly. Return the location of the left/top edge of a box of slider_size( ) would be if the slider is set to $value and can move in an area of $w pixels. The range( ) and log( ) settings are taken into account.


$slider->slider_size( $value );

Set the dimensions of the moving piece of slider. This is measured in pixels in a direction parallel to the slider's movement. The default value is 12.

Setting slider_size( ) to zero will make the slider into a "fill" slider that draws a solid bar from the left/bottom to the current value. This is useful for indicating progress or as a output indicator.


$slider->tick_size( $value );

The slider is shrunk this many pixels from the widget's width so that the tick marks are visible next to it. The default value is 4.

Values for type( ) ^

Subclassing FLTK::Slider ^

If you plan on subclassing FLTK::Slider, consider these notes...

draw( $rect, $flags, $slot )

Subclasses can use this to redraw the moving part. Draw everything that is inside the box, such as the tick marks, the moving slider, and the "slot". The slot only drawn if $slot is true. You should already have drawn the background of the slider.

The default method is called if this does not return a true value.

handle( $event, $rect )

This call is provied so subclasses can draw the moving part inside an arbitrary rectangle.

The default method is called if this does not return a true value.

Author ^

Sanko Robinson <> -

License and Legal ^

Copyright (C) 2008-2010 by Sanko Robinson <>

This program is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0. See the LICENSE file included with this distribution or notes on the Artistic License 2.0 for clarification.

When separated from the distribution, all original POD documentation is covered by the Creative Commons Attribution-Share Alike 3.0 License. See the clarification of the CCA-SA3.0.

syntax highlighting: