Skip to main content
Version: 4.16

Slider

A slider is a graphical element with which the user may set a value by moving an indicator on a slider, or simply by clicking the slider. The slider can operate in horizontal or vertical mode. The slider has two bitmaps. One bitmap is used on one side of the indicator. The other is used on the other side. They can be used in indicating the part of the slider value range that is currently selected.

The slider operates on an integer value range that can be set by the user.

Inherits from: Container, Drawable

Protected Types#

enumSliderOrientation { HORIZONTAL, VERTICAL }
Values that represent slider orientations.

Public Functions#

virtual uint16_tgetIndicatorMax() const
Gets indicator maximum previous set using setupHorizontalSlider() or setupVerticalSlider().
virtual uint16_tgetIndicatorMin() const
Gets indicator minimum previously set using setupHorizontalSlider() or setupVerticalSlider().
virtual uint16_tgetMaxValue() const
Gets the maximum value previously set using setValueRange().
virtual uint16_tgetMinValue() const
Gets the minimum value previously set using setValueRange().
intgetValue()
Gets the current value represented by the indicator.
virtual voidhandleClickEvent(const ClickEvent & evt)
Defines the event handler interface for ClickEvents.
virtual voidhandleDragEvent(const DragEvent & evt)
Defines the event handler interface for DragEvents.
voidsetBitmaps(const Bitmap & sliderBackground, const Bitmap & sliderBackgroundSelected, const Bitmap & indicator)
Sets all the bitmaps for the Slider.
voidsetBitmaps(const BitmapId sliderBackground, const BitmapId sliderBackgroundSelected, const BitmapId indicator)
Sets all the bitmaps for the Slider.
voidsetNewValueCallback(GenericCallback< const Slider &, int > & callback)
Associates an action to be performed when the slider changes its value.
voidsetStartValueCallback(GenericCallback< const Slider &, int > & callback)
Associates an action to be performed when an interaction with the slider is initiated (click or drag).
voidsetStopValueCallback(GenericCallback< const Slider &, int > & callback)
Associates an action to be performed when an interaction with the slider ends (click or drag).
virtual voidsetupHorizontalSlider(uint16_t backgroundX, uint16_t backgroundY, uint16_t indicatorY, uint16_t indicatorMinX, uint16_t indicatorMaxX)
Sets up the slider in horizontal mode with the range going from the left to right.
virtual voidsetupVerticalSlider(uint16_t backgroundX, uint16_t backgroundY, uint16_t indicatorX, uint16_t indicatorMinY, uint16_t indicatorMaxY)
Sets up the slider in vertical mode with the range going from the bottom to top.
virtual voidsetValue(int value)
Places the indicator at the specified value relative to the specified value range.
virtual voidsetValueRange(int minValue, int maxValue)
Sets the value range of the slider.
virtual voidsetValueRange(int minValue, int maxValue, int newValue)
Sets the value range of the slider.
Slider()

Protected Functions#

virtual intgetIndicatorPositionRangeSize() const
Gets the indicator position range, i.e.
virtual uint16_tgetIndicatorRadius() const
Gets the indicator radius, which is half the size of the indicator.
virtual intgetValueRangeSize() const
Gets the value range, i.e.
virtual intpositionToValue(int16_t position) const
Translate a position (x coordinate in horizontal mode and y in vertical mode) in the indicator position range to the corresponding value in the value range.
virtual voidupdateIndicatorPosition(int16_t position)
Updates the indicator position described by position.
virtual int16_tvalueToPosition(int value) const
Translate a value in the value range to the corresponding position in the indicator position range (x coordinate in horizontal mode and y in vertical mode).

Protected Attributes#

Imagebackground
The background image.
ImagebackgroundSelected
The backgroundSelected image.
ContainerbackgroundSelectedViewPort
The backgroundSelected view port. Controls the visible part of the backgroundSelected image.
intcurrentValue
The current value represented by the slider.
Imageindicator
The indicator image.
int16_tindicatorMaxPosition
The maximum position of the indicator (either x coordinate in horizontal mode or y coordinate in vertical mode)
int16_tindicatorMinPosition
The minimum position of the indicator (either x coordinate in horizontal mode or y coordinate in vertical mode)
GenericCallback< const Slider &, int > *newValueCallback
The new value callback (called when the indicator is moved)
SliderOrientationsliderOrientation
The selected slider orientation.
GenericCallback< const Slider &, int > *startValueCallback
The start value callback (called when an interaction with the indicator is initiated)
GenericCallback< const Slider &, int > *stopValueCallback
The stop value callback (called when an interaction with the indicator ends)
intvalueRangeMax
The value range max.
intvalueRangeMin
The value range min.

Additional inherited members#

Public Functions inherited from Container#

virtual voidadd(Drawable & d)
Adds a Drawable instance as child to this Container.
Container()
virtual boolcontains(const Drawable & d)
Query if a given Drawable has been added directly to this Container.
virtual voiddraw(const Rect & invalidatedArea) const
Draw this drawable.
virtual voidforEachChild(GenericCallback< Drawable & > * function)
Executes the specified callback function for each child in the Container.
virtual Drawable *getFirstChild()
Obtain a pointer to the first child of this container.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last)
Gets the last child in the list of children in this Container.
virtual RectgetSolidRect() const
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual voidinsert(Drawable * previous, Drawable & d)
Inserts a Drawable after a specific child node.
virtual voidremove(Drawable & d)
Removes a Drawable from the container by removing it from the linked list of children.
virtual voidremoveAll()
Removes all children in the Container by resetting their parent and sibling pointers.
virtual voidunlink()
Removes all children by unlinking the first child.

Protected Functions inherited from Container#

virtual RectgetContainedArea() const
Gets a rectangle describing the total area covered by the children of this container.
virtual voidmoveChildrenRelative(int16_t deltaX, int16_t deltaY)
Calls moveRelative on all children.

Protected Attributes inherited from Container#

Drawable *firstChild
Pointer to the first child of this container. Subsequent children can be found through firstChild's nextSibling.

Public Functions inherited from Drawable#

virtual voidchildGeometryChanged()
This function can be called on parent nodes to signal that the size or position of one or more of its children has changed.
virtual voiddraw(const Rect & invalidatedArea) const =0
Draw this drawable.
Drawable()
Initializes a new instance of the Drawable class.
voiddrawToDynamicBitmap(BitmapId id)
Render the Drawable object into a dynamic bitmap.
RectgetAbsoluteRect() const
Helper function for obtaining the rectangle this Drawable covers, expressed in absolute coordinates.
virtual Drawable *getFirstChild()
Function for obtaining the first child of this drawable if any.
int16_tgetHeight() const
Gets the height of this Drawable.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last) =0
Function for obtaining the the last child of this drawable that intersects with the specified point.
Drawable *getNextSibling()
Gets the next sibling node.
Drawable *getParent() const
Returns the parent node.
const Rect &getRect() const
Gets the rectangle this Drawable covers, in coordinates relative to its parent.
virtual RectgetSolidRect() const =0
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual RectgetSolidRectAbsolute()
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates.
virtual voidgetVisibleRect(Rect & rect) const
Function for finding the visible part of this drawable.
int16_tgetWidth() const
Gets the width of this Drawable.
int16_tgetX() const
Gets the x coordinate of this Drawable, relative to its parent.
int16_tgetY() const
Gets the y coordinate of this Drawable, relative to its parent.
virtual voidhandleGestureEvent(const GestureEvent & evt)
Defines the event handler interface for GestureEvents.
virtual voidhandleTickEvent()
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
virtual voidinvalidate() const
Tell the framework that this entire Drawable needs to be redrawn.
virtual voidinvalidateRect(Rect & invalidatedArea) const
Request that a region of this drawable is redrawn.
boolisTouchable() const
Gets whether this Drawable receives touch events or not.
boolisVisible() const
Gets whether this Drawable is visible.
virtual voidmoveRelative(int16_t x, int16_t y)
Moves the drawable.
virtual voidmoveTo(int16_t x, int16_t y)
Moves the drawable.
virtual voidsetHeight(int16_t height)
Sets the height of this drawable.
voidsetPosition(const Drawable & drawable)
Sets the position of the Drawable to the same as the given Drawable.
voidsetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
Sets the size and position of this Drawable, relative to its parent.
voidsetTouchable(bool touch)
Controls whether this Drawable receives touch events or not.
voidsetVisible(bool vis)
Controls whether this Drawable should be visible.
virtual voidsetWidth(int16_t width)
Sets the width of this drawable.
voidsetWidthHeight(const Bitmap & bitmap)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Drawable & drawable)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Rect & rect)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(int16_t width, int16_t height)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
virtual voidsetX(int16_t x)
Sets the x coordinate of this Drawable, relative to its parent.
voidsetXY(const Drawable & drawable)
Sets the x and y coordinates of this Drawable.
voidsetXY(int16_t x, int16_t y)
Sets the x and y coordinates of this Drawable, relative to its parent.
virtual voidsetY(int16_t y)
Sets the y coordinate of this Drawable, relative to its parent.
virtual voidtranslateRectToAbsolute(Rect & r) const
Helper function for converting a region of this Drawable to absolute coordinates.
virtual ~Drawable()
Finalizes an instance of the Drawable class.

Protected Attributes inherited from Drawable#

Drawable *nextSibling
Pointer to the next Drawable.
Drawable *parent
Pointer to this drawable's parent.
Rectrect
The coordinates of this Drawable, relative to its parent.
booltouchable
True if this drawable should receive touch events.
boolvisible
True if this drawable should be drawn.

Protected Types Documentation#

SliderOrientation#

Values that represent slider orientations.

HORIZONTALThe Slider can be moved horizontally between left and right.
VERTICALThe Slider can be moved vertically between top and bottom.

Public Functions Documentation#

getIndicatorMax#

virtual uint16_t getIndicatorMax()const

Gets indicator maximum previous set using setupHorizontalSlider() or setupVerticalSlider().

Returns:

The calculated indicator maximum.

See also:

getIndicatorMin#

virtual uint16_t getIndicatorMin()const

Gets indicator minimum previously set using setupHorizontalSlider() or setupVerticalSlider().

Returns:

The indicator minimum.

See also:

getMaxValue#

virtual uint16_t getMaxValue()const

Gets the maximum value previously set using setValueRange().

Returns:

The maximum value.

See also:

getMinValue#

virtual uint16_t getMinValue()const

Gets the minimum value previously set using setValueRange().

Returns:

The minimum value.

See also:

getValue#

int getValue()

Gets the current value represented by the indicator.

Returns:

The current value.

handleClickEvent#

virtual void handleClickEvent(const ClickEvent &evt)

Defines the event handler interface for ClickEvents.

The default implementation ignores the event. The event is only received if the Drawable is touchable and visible.

Parameters:
evtThe ClickEvent received from the HAL.

Reimplements: touchgfx::Drawable::handleClickEvent

handleDragEvent#

virtual void handleDragEvent(const DragEvent &evt)

Defines the event handler interface for DragEvents.

The default implementation ignores the event. The event is only received if the drawable is touchable and visible.

Parameters:
evtThe DragEvent received from the HAL.

Reimplements: touchgfx::Drawable::handleDragEvent

setBitmaps#

void setBitmaps(const Bitmap &sliderBackground ,
const Bitmap &sliderBackgroundSelected ,
const Bitmap &indicator
)

Sets all the bitmaps for the Slider.

The Slider shows the sliderBackgroundSelected bitmap in the region of the Slider that is selected, that is the area to the left of the indicator for a horizontal Slider and below the indicator for a vertical Slider. The sliderBackground is shown on the other side of the Slider. To ignore this effect simply use the same bitmap for both the sliderBackground and the sliderBackgroundSelected.

Parameters:
sliderBackgroundThe slider background with the slider range unselected.
sliderBackgroundSelectedThe slider background with the slider range selected.
indicatorThe indicator.

setBitmaps#

void setBitmaps(const BitmapIdsliderBackground ,
const BitmapIdsliderBackgroundSelected ,
const BitmapIdindicator
)

Sets all the bitmaps for the Slider.

The Slider shows the sliderBackgroundSelected bitmap in the region of the Slider that is selected, that is the area to the left of the indicator for a horizontal Slider and below the indicator for a vertical Slider. The sliderBackground is shown on the other side of the Slider. To ignore this effect simply use the same bitmap for both the sliderBackground and the sliderBackgroundSelected.

Parameters:
sliderBackgroundThe slider background with the slider range unselected.
sliderBackgroundSelectedThe slider background with the slider range selected.
indicatorThe indicator.

setNewValueCallback#

void setNewValueCallback(GenericCallback< const Slider &, int > &callback)

Associates an action to be performed when the slider changes its value.

Parameters:
callbackThe callback to be executed. The callback will be given a reference to the Slider and the current value of the slider.
See also:

setStartValueCallback#

void setStartValueCallback(GenericCallback< const Slider &, int > &callback)

Associates an action to be performed when an interaction with the slider is initiated (click or drag).

Parameters:
callbackThe callback to be executed. The callback will be given a reference to the Slider and the current value of the slider at interaction start.
See also:

setStopValueCallback#

void setStopValueCallback(GenericCallback< const Slider &, int > &callback)

Associates an action to be performed when an interaction with the slider ends (click or drag).

Parameters:
callbackThe callback to be executed. The callback will be given a reference to the Slider and the current value of the slider at interaction end.
See also:

setupHorizontalSlider#

virtual void setupHorizontalSlider(uint16_tbackgroundX ,
uint16_tbackgroundY ,
uint16_tindicatorY ,
uint16_tindicatorMinX ,
uint16_tindicatorMaxX
)

Sets up the slider in horizontal mode with the range going from the left to right.

Places the backgrounds and the indicator inside the Slider container. It is possible to place the end points of the indicator outside the background image if it needs to go beyond the boundaries of the background. The width and height of the Slider will be adjusted appropriately so that both the background and the indicator will be fully visible in both the minimum and maximum indicator positions.

Calls setValue() with the current value (default 0) and triggers the newSliderValue callback.

Parameters:
backgroundXThe background x coordinate inside the slider.
backgroundYThe background y coordinate inside the slider.
indicatorYThe indicator y coordinate inside the slider.
indicatorMinXThe indicator minimum x coordinate inside the slider. This is the position used when the slider is at its minimum value. Must be less than indicatorMaxX.
indicatorMaxXThe indicator maximum x coordinate inside the slider. This is the position used when the slider is at its maximum value. Must be greater than indicatorMinX.
Note

The x and y position of the Slider will either be the left/top of the background or the left/top of the indicator in its minimum x coordinate.

setupVerticalSlider#

virtual void setupVerticalSlider(uint16_tbackgroundX ,
uint16_tbackgroundY ,
uint16_tindicatorX ,
uint16_tindicatorMinY ,
uint16_tindicatorMaxY
)

Sets up the slider in vertical mode with the range going from the bottom to top.

Places the backgrounds and the indicator inside the Slider container. It is possible to place the end points of the indicator outside the background image if it needs to go beyond the boundaries of the background. The width and height of the Slider will be adjusted appropriately so that both the background and the indicator will be fully visible in both the minimum and maximum indicator positions.

Calls setValue with the current value (default 0) and triggers the newSliderValue callback.

Parameters:
backgroundXThe background x coordinate inside the slider.
backgroundYThe background y coordinate inside the slider.
indicatorXThe indicator x coordinate inside the slider.
indicatorMinYThe indicator minimum y coordinate inside the slider. This is the position used when the slider is at its maximum value. Must be less than indicatorMaxX.
indicatorMaxYThe indicator maximum y coordinate inside the slider. This is the position used when the slider is at its minimum value. Must be greater than indicatorMinX.
Note

The x and y position of the Slider will either be the left/top of the background or the left/top of the indicator in its minimum y coordinate.

setValue#

virtual void setValue(intvalue)

Places the indicator at the specified value relative to the specified value range.

Values beyond the value range will be rounded to the min/max value in the value range.

Parameters:
valueThe value.
Note

The value update triggers a newSliderValue callback just as a drag or click does. If the value range is larger than the number of pixels specified for the indicator min and indicator max, some values will not be represented by the slider and thus is not possible to set with this method. In this case the value will be rounded to the nearest value that is represented in the current setting.

See also:

setValueRange#

virtual void setValueRange(intminValue ,
intmaxValue
)

Sets the value range of the slider.

Values accepted and returned by the slider will be in this range.

The slider will set its value to the current value or round to minValue or maxValue if the current value is outside the new range.

Parameters:
minValueThe minimum value. Must be less than maxValue.
maxValueThe maximum value. Must be greater than minValue.
Note

If the range is larger than the number of pixels specified for the indicator min and indicator max, some values will not be represented by the slider.

setValueRange#

virtual void setValueRange(intminValue ,
intmaxValue ,
intnewValue
)

Sets the value range of the slider.

Values accepted and returned by the slider will be in this range.

The slider will set its value to the specified new value.

Parameters:
minValueThe minimum value. Must be less than maxValue.
maxValueThe maximum value. Must be greater than minValue.
newValueThe new value.
Note

If the range is larger than the number of pixels specified for the indicator min and max some values will not be represented by the slider.

Slider#

Protected Functions Documentation#

getIndicatorPositionRangeSize#

virtual int getIndicatorPositionRangeSize()const

Gets the indicator position range, i.e.

the difference between max and min for the position of the indicator.

Returns:

The indicator position range.

getIndicatorRadius#

virtual uint16_t getIndicatorRadius()const

Gets the indicator radius, which is half the size of the indicator.

Returns:

The the indicator radius.

getValueRangeSize#

virtual int getValueRangeSize()const

Gets the value range, i.e.

the difference between max and min for the value range.

Returns:

The value range.

positionToValue#

virtual int positionToValue(int16_tposition)

Translate a position (x coordinate in horizontal mode and y in vertical mode) in the indicator position range to the corresponding value in the value range.

Parameters:
positionThe position.
Returns:

The value that corresponds to the coordinate.

updateIndicatorPosition#

virtual void updateIndicatorPosition(int16_tposition)

Updates the indicator position described by position.

Calls the newSliderValueCallback with the new value.

Parameters:
positionThe position (x coordinate in horizontal mode and y coordinate in vertical mode).

valueToPosition#

virtual int16_t valueToPosition(intvalue)

Translate a value in the value range to the corresponding position in the indicator position range (x coordinate in horizontal mode and y in vertical mode).

Parameters:
valueThe value.
Returns:

The coordinate that corresponds to the value.

Protected Attributes Documentation#

background#

Image background

The background image.

backgroundSelected#

Image backgroundSelected

The backgroundSelected image.

backgroundSelectedViewPort#

Container backgroundSelectedViewPort

The backgroundSelected view port. Controls the visible part of the backgroundSelected image.

currentValue#

int currentValue

The current value represented by the slider.

indicator#

Image indicator

The indicator image.

indicatorMaxPosition#

int16_t indicatorMaxPosition

The maximum position of the indicator (either x coordinate in horizontal mode or y coordinate in vertical mode)

indicatorMinPosition#

int16_t indicatorMinPosition

The minimum position of the indicator (either x coordinate in horizontal mode or y coordinate in vertical mode)

newValueCallback#

GenericCallback< const Slider &, int > * newValueCallback

The new value callback (called when the indicator is moved)

sliderOrientation#

SliderOrientation sliderOrientation

The selected slider orientation.

startValueCallback#

GenericCallback< const Slider &, int > * startValueCallback

The start value callback (called when an interaction with the indicator is initiated)

stopValueCallback#

GenericCallback< const Slider &, int > * stopValueCallback

The stop value callback (called when an interaction with the indicator ends)

valueRangeMax#

int valueRangeMax

The value range max.

valueRangeMin#

int valueRangeMin

The value range min.