Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Slider widget

Modules

 Slider widget options
 These options can be ORed together to specify the behaviour of a slider widget when creating it with wtk_slider_create.
 

Functions

struct win_windowwtk_slider_as_child (struct wtk_slider *slider)
 Get pointer to slider window. More...
 
struct wtk_sliderwtk_slider_create (struct win_window *parent, struct win_area const *area, uint8_t maximum, uint8_t value, uint8_t option, win_command_t command_data)
 Create a new slider widget. More...
 
win_command_t wtk_slider_get_command (struct wtk_slider *slider)
 This function returns the window command of the specified slider, as set when the widget was created. More...
 
uint8_t wtk_slider_get_value (struct wtk_slider const *slider)
 Get slider value. More...
 
bool wtk_slider_is_moving (struct wtk_slider const *slider)
 Get slider status. More...
 
bool wtk_slider_set_value (struct wtk_slider *slider, uint8_t value)
 Set new slider value. More...
 
enum  wtk_slider_state {
  WTK_SLIDER_NORMAL,
  WTK_SLIDER_MOVING
}
 Valid states for slider, relevant to pointer operations. More...
 
static bool wtk_slider_handler (struct win_window *win, enum win_event_type type, void const *data)
 Slider event handler. More...
 

Valid states for slider, relevant to pointer operations.

Enumerator
WTK_SLIDER_NORMAL 

Normal state, no highlight or movement.

WTK_SLIDER_MOVING 

Slider is pressed, highlighted and moving.

struct win_window* wtk_slider_as_child ( struct wtk_slider slider)

Get pointer to slider window.

Returns a reference to the window that should be used when managing the widget, such as destroying, moving or reparenting it.

Parameters
sliderPointer to wtk_slider struct to manage.
Returns
Pointer to window to be used for managing the slider.

References Assert, and wtk_slider::container.

struct wtk_slider* wtk_slider_create ( struct win_window parent,
struct win_area const *  area,
uint8_t  maximum,
uint8_t  value,
uint8_t  option,
win_command_t  command 
)

Create a new slider widget.

Allocates the necessary memory and intializes the window and data for slider widgets. If there is not enough memory, the function returns NULL.
To destroy a slider widget and all its contents, and free its memory, call win_destroy() on the slider's child reference, given by wtk_slider_as_child(), like this: "win_destroy(wtk_slider_as_child(my_slider_ptr));".

Slider widgets fill the specified area and perform a mapping of the slider knob's position to a value between 0 and maximum. The length of the slider cannot exceed 255 pixels.

By default, the value 0 corresponds to the top-most position for a vertical slider, and the left-most position for a horizontal one. The slider's orientation and inversion of the value can be configured.

A slider can be configured to issue command events whenever its value is changed by a pointer and/or when a pointer releases it.

Refer to <gfx/wtk.h> for available configuration options.

Parameters
parentPointer to parent win_window struct.
areaPointer to win_area struct with position and size of the slider.
maximumMaximum value of the slider.
valueInitial value of the slider.
optionConfiguration options for slider. See Slider widget options
commandCommand to send to parent window. Must be non-zero if used.
Returns
Pointer to new slider, if memory allocation was successful.

References win_attributes::area, Assert, win_attributes::background, win_attributes::behavior, wtk_slider::command, wtk_slider::container, win_attributes::custom, win_attributes::event_handler, length, wtk_slider::maximum, maximum(), membag_alloc(), membag_free(), NULL, wtk_slider::option, option, wtk_slider::position, wtk_slider::root_pos, win_area::size, wtk_slider::state, wtk_slider::value, win_create(), win_translate_win_to_root(), wtk_rescale_value(), WTK_SLIDER_CMD_MOVE, WTK_SLIDER_CMD_RELEASE, wtk_slider_handler(), WTK_SLIDER_INVERT, WTK_SLIDER_NORMAL, WTK_SLIDER_VERTICAL, win_point::x, and win_point::y.

win_command_t wtk_slider_get_command ( struct wtk_slider slider)

This function returns the window command of the specified slider, as set when the widget was created.

Parameters
sliderSlider widget to manage.
Returns
Associated window command of the slider widget.

References Assert, and wtk_slider::command.

uint8_t wtk_slider_get_value ( struct wtk_slider const *  slider)

Get slider value.

Returns the slider value, inverted if such behavior is configured.

Parameters
sliderPointer to wtk_slider struct to get value from.
Returns
Value of slider.

References Assert, wtk_slider::maximum, wtk_slider::option, wtk_slider::value, and WTK_SLIDER_INVERT.

static bool wtk_slider_handler ( struct win_window win,
enum win_event_type  type,
void const *  data 
)
static

Slider event handler.

This is the window event handler for slider widgets. It handles the three relevant event types sent to a slider's container window, i.e., drawing, pointer and destroy events.

For POINTER events, the slider value is only updated when the pointer moves, and not upon press or release events. The handler will grab the pointer and allow for it to move outside the actual widget window and still control the slider knob.

Parameters
winWindow receiving the event.
typeThe event type.
dataCustom data, depending on event type.
Returns
True if the event was recognized and accepted.

References Assert, win_command_event::data, gfx_draw_filled_rect, gfx_draw_rect, length, membag_free(), NULL, option, win_clip_region::origin, win_area::pos, win_command_event::recipient, win_command_event::sender, win_area::size, win_pointer_event::type, WIN_EVENT_DESTROY, WIN_EVENT_DRAW, WIN_EVENT_POINTER, win_get_area(), win_get_custom_data(), win_grab_pointer(), win_inflate_area(), WIN_POINTER_MOVE, WIN_POINTER_PRESS, WIN_POINTER_RELEASE, win_queue_command_event(), win_redraw(), win_translate_win_to_root(), wtk_rescale_value(), WTK_SLIDER_CMD_MOVE, WTK_SLIDER_CMD_RELEASE, WTK_SLIDER_MOVING, WTK_SLIDER_NORMAL, WTK_SLIDER_VERTICAL, win_point::x, and win_point::y.

Referenced by wtk_slider_create().

bool wtk_slider_is_moving ( struct wtk_slider const *  slider)

Get slider status.

Returns whether or not the slider is currently being manipulated by pointer events, i.e., it is moving.

Parameters
sliderPointer to wtk_slider struct to get status of.
Returns
True if slider is currently moving.

References Assert, wtk_slider::state, and WTK_SLIDER_MOVING.

bool wtk_slider_set_value ( struct wtk_slider slider,
uint8_t  value 
)

Set new slider value.

Updates the current value and issues a redrawing of the slider if its value was indeed changed. In this case, the new position of the slider knob is also computed.

Parameters
sliderPointer to wtk_slider struct to set new value for.
valueNew value for the slider.
Returns
True if slider value was changed.

References Assert, wtk_slider::container, length, wtk_slider::maximum, maximum(), wtk_slider::option, option, wtk_slider::position, win_area::size, wtk_slider::value, win_get_area(), win_redraw(), wtk_rescale_value(), WTK_SLIDER_INVERT, WTK_SLIDER_VERTICAL, win_point::x, and win_point::y.