Slider Widgets

The slider widget is a draggable bar that is used to select a value within a certain range.

Table of Contents

Adding a Slider

This is how to create a slider object.

Evas_Object *slider;
slider = elm_slider_add(parent);

Configuring the Slider

Orientation is set with the elm_slider_horizontal_set() function, and it is inverted the same way as the progressbar widget. Here we set it vertical and inverted.

elm_slider_horizontal_set(slider, EINA_FALSE);
elm_slider_inverted_set(slider, EINA_TRUE);

It can contain icons (“icon” and “end” partnames), a label, a unit label and an indicator label.

Evas_Object *icon1, *icon2;
 
// Set the icons
elm_object_part_content_set(slider, "icon", icon1);
elm_object_part_content_set(slider, "end", icon2);
 
// Set the label
elm_object_part_text_set(slider, "default", "slider label");
 
// Set the unit format
elm_slider_unit_format_set(slider, "%1.2f meters");

Before using the slider, its minimum and maximum values are set with elm_slider_min_max_set(). The current value is set with (elm_slider_value_set()). Here we set the minimum value to 0, the maximum value to 100, and the current value to 50.

elm_slider_min_max_set(slider, 0.0, 100.0);
elm_slider_value_set(slider, 50.0);

The span of the slider represents its length (horizontally or vertically). It is set with elm_slider_span_size_set() and is scaled by the object or applications scaling factor.

We can retrieve the current value of the slider anytime.

double value = elm_slider_value_get(slider);

By default, the slider indicator becomes bigger when the user drags it. This can be disabled if we want the slider indicator to keep its default size. Here we set the state of the indicator enlargement and then invert the behavior.

// Get the current state of the indicator
Eina_Bool enlarge = elm_slider_indicator_show_get(slider);
 
// Invert the behavior
elm_slider_indicator_show_set(slider, !enlarge);
 

Using Slider Callbacks

This widget emits the following signals, besides the ones sent from Layout:

  • “changed” - Whenever the slider value is changed by the user.
  • “slider,drag,start” - dragging the slider indicator around has started.
  • “slider,drag,stop” - dragging the slider indicator around has stopped.
  • “delay,changed” - A short time after the value is changed by the user. This will be called only when the user stops dragging for a very short period or when they release their finger/mouse, so it avoids possibly expensive reactions to the value change.
  • “focused” - When the slider has received focus. (since 1.8)
  • “unfocused” - When the slider has lost focus. (since 1.8)
  • “language,changed” - the program's language changed (since 1.9)

For all these signals, event_info is NULL.

This is how to register a callback on the “changed” signal.

evas_object_smart_callback_add(slider, "changed", _changed_cb, data);
// Callback function for the "changed" signal
// This callback is called when the slider value changes
static void
_changed_cb(void *data, Evas_Object *obj, void *event_info)
{
   printf("The slider has changed\n");
}


A Slider Example