1 #include <Elementary.h>
5 * @defgroup Slider Slider
7 * The slider adds a dragable “slider” widget for selecting the value of
8 * something within a range.
11 * A slider can be horizontal or vertical. It can contain an Icon and has a
12 * primary label as well as a units label (that is formatted with floating
13 * point values and thus accepts a printf-style format string, like
14 * “%1.2f units”. There is also an indicator string that may be somewhere
15 * else (like on the slider itself) that also accepts a format string like
16 * units. Label, Icon Unit and Indicator strings/objects are optional.
18 * A slider may be inverted which means values invert, with high vales being
19 * on the left or top and low values on the right or bottom (as opposed to
20 * normally being low on the left or top and high on the bottom and right).
22 * The slider should have its minimum and maximum values set by the
23 * application with elm_slider_min_max_set() and value should also be set by
24 * the application before use with elm_slider_value_set(). The span of the
25 * slider is its length (horizontally or vertically). This will be scaled by
26 * the object or applications scaling factor. At any point code can query the
27 * slider for its value with elm_slider_value_get().
29 * Signals that you can add callbacks for are:
31 * "changed" - Whenever the slider value is changed by the user.
32 * "slider,drag,start" - dragging the slider indicator around has started
33 * "slider,drag,stop" - dragging the slider indicator around has stopped
34 * "delay,changed" - A short time after the value is changed by the user.
35 * This will be called only when the user stops dragging for
36 * a very short period or when they release their
37 * finger/mouse, so it avoids possibly expensive reactions to
41 typedef struct _Widget_Data Widget_Data;
54 const char *indicator;
56 const char *(*indicator_format_func)(double val);
57 void (*indicator_format_free)(const char *str);
59 const char *(*units_format_func)(double val);
60 void (*units_format_free)(const char *str);
62 double val, val_min, val_max;
65 Eina_Bool horizontal : 1;
66 Eina_Bool inverted : 1;
67 Eina_Bool indicator_show : 1;
70 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
72 static const char *widtype = NULL;
73 static void _del_hook(Evas_Object *obj);
74 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
75 static void _theme_hook(Evas_Object *obj);
76 static void _disable_hook(Evas_Object *obj);
77 static void _sizing_eval(Evas_Object *obj);
78 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
79 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
80 static void _units_set(Evas_Object *obj);
81 static void _val_set(Evas_Object *obj);
82 static void _indicator_set(Evas_Object *obj);
83 static void _on_focus_hook(void *data, Evas_Object *obj);
84 static void _drag_up(void *data, Evas_Object *obj,
85 const char *emission, const char *source);
86 static void _drag_down(void *data, Evas_Object *obj,
87 const char *emission, const char *source);
88 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
89 Evas_Callback_Type type, void *event_info);
90 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
92 static const char SIG_CHANGED[] = "changed";
93 static const char SIG_DELAY_CHANGED[] = "delay,changed";
94 static const char SIG_DRAG_START[] = "slider,drag,start";
95 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
96 static const Evas_Smart_Cb_Description _signals[] = {
98 {SIG_DELAY_CHANGED, ""},
105 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
107 Evas_Event_Mouse_Wheel *mev;
108 Evas_Event_Key_Down *ev;
111 wd = elm_widget_data_get(obj);
112 if (!wd) return EINA_FALSE;
114 if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
115 else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
118 if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
119 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
121 if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
122 else _drag_down(obj, NULL, NULL, NULL);
123 mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
128 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
129 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
130 if ((!strcmp(ev->keyname, "Left"))
131 || (!strcmp(ev->keyname, "KP_Left")))
133 if (!wd->horizontal) return EINA_FALSE;
134 if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
135 else _drag_up(obj, NULL, NULL, NULL);
136 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
139 else if ((!strcmp(ev->keyname, "Right"))
140 || (!strcmp(ev->keyname, "KP_Right")))
142 if (!wd->horizontal) return EINA_FALSE;
143 if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
144 else _drag_down(obj, NULL, NULL, NULL);
145 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
148 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
150 if (wd->horizontal) return EINA_FALSE;
151 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
152 else _drag_down(obj, NULL, NULL, NULL);
153 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
156 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
158 if (wd->horizontal) return EINA_FALSE;
159 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
160 else _drag_up(obj, NULL, NULL, NULL);
161 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
164 else return EINA_FALSE;
168 _del_hook(Evas_Object *obj)
170 Widget_Data *wd = elm_widget_data_get(obj);
172 if (wd->label) eina_stringshare_del(wd->label);
173 if (wd->indicator) eina_stringshare_del(wd->units);
174 if (wd->delay) ecore_timer_del(wd->delay);
179 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
181 Widget_Data *wd = elm_widget_data_get(obj);
183 if (elm_widget_focus_get(obj))
185 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
186 evas_object_focus_set(wd->slider, EINA_TRUE);
190 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
191 evas_object_focus_set(wd->slider, EINA_FALSE);
196 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
198 Widget_Data *wd = elm_widget_data_get(obj);
200 edje_object_mirrored_set(wd->slider, rtl);
204 _theme_hook(Evas_Object *obj)
206 Widget_Data *wd = elm_widget_data_get(obj);
208 _elm_widget_mirrored_reload(obj);
209 _mirrored_set(obj, elm_widget_mirrored_get(obj));
211 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
213 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
216 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
217 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
220 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
222 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
225 edje_object_part_text_set(wd->slider, "elm.text", wd->label);
226 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
230 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
233 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
235 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
238 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
240 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
243 edje_object_message_signal_process(wd->slider);
244 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
250 _disable_hook(Evas_Object *obj)
252 Widget_Data *wd = elm_widget_data_get(obj);
254 if (elm_widget_disabled_get(obj))
255 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
257 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
261 _sizing_eval(Evas_Object *obj)
263 Widget_Data *wd = elm_widget_data_get(obj);
264 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
266 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
267 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
268 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
269 evas_object_size_hint_min_set(obj, minw, minh);
270 evas_object_size_hint_max_set(obj, maxw, maxh);
274 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
276 Widget_Data *wd = elm_widget_data_get(data);
278 if ((obj != wd->icon) && (obj != wd->end)) return;
283 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
285 Widget_Data *wd = elm_widget_data_get(obj);
286 Evas_Object *sub = event_info;
290 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
291 evas_object_event_callback_del_full
292 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
294 edje_object_message_signal_process(wd->slider);
299 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
300 evas_object_event_callback_del_full(sub,
301 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
302 _changed_size_hints, obj);
304 edje_object_message_signal_process(wd->slider);
310 _delay_change(void *data)
312 Widget_Data *wd = elm_widget_data_get(data);
313 if (!wd) return ECORE_CALLBACK_CANCEL;
315 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
316 return ECORE_CALLBACK_CANCEL;
320 _val_fetch(Evas_Object *obj)
323 Widget_Data *wd = elm_widget_data_get(obj);
324 double posx = 0.0, posy = 0.0, pos = 0.0, val;
326 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
328 if (wd->horizontal) pos = posx;
331 rtl = elm_widget_mirrored_get(obj);
332 if ((!rtl && wd->inverted) || (rtl &&
333 ((!wd->horizontal && wd->inverted) ||
334 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
335 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
339 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
340 if (wd->delay) ecore_timer_del(wd->delay);
341 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
346 _val_set(Evas_Object *obj)
349 Widget_Data *wd = elm_widget_data_get(obj);
352 if (wd->val_max > wd->val_min)
353 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
356 if (pos < 0.0) pos = 0.0;
357 else if (pos > 1.0) pos = 1.0;
359 rtl = elm_widget_mirrored_get(obj);
360 if ((!rtl && wd->inverted) || (rtl &&
361 ((!wd->horizontal && wd->inverted) ||
362 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
363 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
367 _units_set(Evas_Object *obj)
369 Widget_Data *wd = elm_widget_data_get(obj);
371 if (wd->units_format_func)
374 buf = wd->units_format_func(wd->val);
375 edje_object_part_text_set(wd->slider, "elm.units", buf);
376 if (wd->units_format_free) wd->units_format_free(buf);
382 snprintf(buf, sizeof(buf), wd->units, wd->val);
383 edje_object_part_text_set(wd->slider, "elm.units", buf);
386 edje_object_part_text_set(wd->slider, "elm.units", NULL);
390 _indicator_set(Evas_Object *obj)
392 Widget_Data *wd = elm_widget_data_get(obj);
394 if (wd->indicator_format_func)
397 buf = wd->indicator_format_func(wd->val);
398 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
399 if (wd->indicator_format_free) wd->indicator_format_free(buf);
401 else if (wd->indicator)
404 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
405 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
408 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
412 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
416 _indicator_set(data);
420 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
423 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
425 _indicator_set(data);
426 elm_widget_scroll_freeze_push(data);
430 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
433 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
435 _indicator_set(data);
436 elm_widget_scroll_freeze_pop(data);
440 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
444 _indicator_set(data);
448 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
453 wd = elm_widget_data_get(data);
456 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
458 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
462 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
467 wd = elm_widget_data_get(data);
470 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
472 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
476 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
478 Widget_Data *wd = elm_widget_data_get(data);
479 Evas_Event_Mouse_Down *ev = event_info;
480 Evas_Coord x, y, w, h;
481 double button_x, button_y;
483 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
484 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
487 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
488 if (button_x > 1) button_x = 1;
489 if (button_x < 0) button_x = 0;
493 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
494 if (button_y > 1) button_y = 1;
495 if (button_y < 0) button_y = 0;
497 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
498 evas_event_feed_mouse_cancel(e, 0, NULL);
499 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
503 _elm_slider_label_set(Evas_Object *obj, const char *item, const char *label)
505 ELM_CHECK_WIDTYPE(obj, widtype);
506 Widget_Data *wd = elm_widget_data_get(obj);
507 if (item && strcmp(item, "default")) return;
509 eina_stringshare_replace(&wd->label, label);
512 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
513 edje_object_message_signal_process(wd->slider);
517 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
518 edje_object_message_signal_process(wd->slider);
520 edje_object_part_text_set(wd->slider, "elm.text", label);
525 _elm_slider_label_get(const Evas_Object *obj, const char *item)
527 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
528 Widget_Data *wd = elm_widget_data_get(obj);
529 if (item && strcmp(item, "default")) return NULL;
530 if (!wd) return NULL;
535 * Add a new slider to the parent
537 * @param parent The parent object
538 * @return The new object or NULL if it cannot be created
543 elm_slider_add(Evas_Object *parent)
549 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
551 ELM_SET_WIDTYPE(widtype, "slider");
552 elm_widget_type_set(obj, "slider");
553 elm_widget_sub_object_add(parent, obj);
554 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
555 elm_widget_data_set(obj, wd);
556 elm_widget_del_hook_set(obj, _del_hook);
557 elm_widget_theme_hook_set(obj, _theme_hook);
558 elm_widget_disable_hook_set(obj, _disable_hook);
559 elm_widget_can_focus_set(obj, EINA_TRUE);
560 elm_widget_event_hook_set(obj, _event_hook);
561 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
562 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
564 wd->horizontal = EINA_TRUE;
565 wd->indicator_show = EINA_TRUE;
570 wd->slider = edje_object_add(e);
571 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
572 elm_widget_resize_object_set(obj, wd->slider);
573 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
574 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
575 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
576 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
577 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
578 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
579 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
581 wd->spacer = evas_object_rectangle_add(e);
582 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
583 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
584 elm_widget_sub_object_add(obj, wd->spacer);
585 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
586 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
587 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
589 _mirrored_set(obj, elm_widget_mirrored_get(obj));
592 // TODO: convert Elementary to subclassing of Evas_Smart_Class
593 // TODO: and save some bytes, making descriptions per-class and not instance!
594 evas_object_smart_callbacks_descriptions_set(obj, _signals);
599 * Set the label of the slider
601 * @param obj The slider object
602 * @param label The text label string in UTF-8
607 elm_slider_label_set(Evas_Object *obj, const char *label)
609 _elm_slider_label_set(obj, NULL, label);
613 * Get the label of the slider
615 * @param obj The slider object
616 * @return The text label string in UTF-8
621 elm_slider_label_get(const Evas_Object *obj)
623 return _elm_slider_label_get(obj, NULL);
627 * Set the icon object (leftmost widget) of the slider object.
629 * Once the icon object is set, a previously set one will be deleted.
630 * If you want to keep that old content object, use the
631 * elm_slider_icon_unset() function.
633 * @param obj The slider object
634 * @param icon The icon object
636 * @note If the object being set does not have minimum size hints set,
637 * it won't get properly displayed.
642 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
644 ELM_CHECK_WIDTYPE(obj, widtype);
645 Widget_Data *wd = elm_widget_data_get(obj);
647 if (wd->icon == icon) return;
648 if (wd->icon) evas_object_del(wd->icon);
652 elm_widget_sub_object_add(obj, icon);
653 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
654 _changed_size_hints, obj);
655 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
656 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
657 edje_object_message_signal_process(wd->slider);
663 * Unset the leftmost widget of the slider, unparenting and
666 * @param obj The slider object
667 * @return the previously set icon sub-object of this slider, on
670 * @see elm_slider_icon_set()
675 elm_slider_icon_unset(Evas_Object *obj)
677 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
678 Widget_Data *wd = elm_widget_data_get(obj);
679 Evas_Object *ret = NULL;
680 if (!wd) return NULL;
683 elm_widget_sub_object_del(obj, wd->icon);
685 edje_object_part_unswallow(wd->slider, wd->icon);
686 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
694 * Get the icon object of the slider object. This object is owned by
695 * the scrolled entry and should not be modified.
697 * @param obj The slider object
698 * @return The icon object
703 elm_slider_icon_get(const Evas_Object *obj)
705 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
706 Widget_Data *wd = elm_widget_data_get(obj);
707 if (!wd) return NULL;
712 * Set the length of the dragable region of the slider
714 * This sets the minimum width or height (depending on orientation) of the
715 * area of the slider that allows the slider to be dragged around. This in
716 * turn affects the objects minimum size (along with icon label and unit
717 * text). Note that this will also get multiplied by the scale factor.
719 * @param obj The slider object
720 * @param size The length of the slider area
725 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
727 ELM_CHECK_WIDTYPE(obj, widtype);
728 Widget_Data *wd = elm_widget_data_get(obj);
730 if (wd->size == size) return;
733 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
735 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
736 if (wd->indicator_show)
737 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
739 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
740 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
745 * Get the length of the dragable region of the slider
747 * This gets the minimum width or height (depending on orientation) of
748 * the area of the slider that allows the slider to be dragged
749 * around. Note that this will also get multiplied by the scale
752 * @param obj The slider object
753 * @return The length of the slider area
758 elm_slider_span_size_get(const Evas_Object *obj)
760 ELM_CHECK_WIDTYPE(obj, widtype) 0;
761 Widget_Data *wd = elm_widget_data_get(obj);
767 * Set the format string of the unit area
769 * If NULL, this disabls the unit area display. If not it sets the format
770 * string for the unit text. The unit text is provided a floating point
771 * value, so the unit text can display up to 1 floating point value. Note that
772 * this is optional. Use a format string such as "%1.2f meters" for example.
774 * @param obj The slider object
775 * @param units The format string for the units display
780 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
782 ELM_CHECK_WIDTYPE(obj, widtype);
783 Widget_Data *wd = elm_widget_data_get(obj);
785 eina_stringshare_replace(&wd->units, units);
788 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
789 edje_object_message_signal_process(wd->slider);
793 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
794 edje_object_message_signal_process(wd->slider);
801 * Get the format string for the unit area
803 * The slider may also display a value (the value of the slider) somewhere
804 * (for example above the slider knob that is dragged around). This sets the
805 * format string for this. See elm_slider_unit_format_set() for more
806 * information on how this works.
808 * @param obj The slider object
809 * @return The format string for the unit display.
814 elm_slider_unit_format_get(const Evas_Object *obj)
816 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
817 Widget_Data *wd = elm_widget_data_get(obj);
818 if (!wd) return NULL;
823 * Set the format string for the indicator area
825 * The slider may also display a value (the value of the slider) somewhere
826 * (for example above the slider knob that is dragged around). This sets the
827 * format string for this. See elm_slider_unit_format_set() for more
828 * information on how this works.
830 * @param obj The slider object
831 * @param indicator The format string for the indicator display
836 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
838 ELM_CHECK_WIDTYPE(obj, widtype);
839 Widget_Data *wd = elm_widget_data_get(obj);
841 eina_stringshare_replace(&wd->indicator, indicator);
846 * Get the format string for the indicator area
848 * The slider may also display a value (the value of the slider) somewhere
849 * (for example above the slider knob that is dragged around). This sets the
850 * format string for this. See elm_slider_indicator_format_set() for more
851 * information on how this works.
853 * @param obj The slider object
854 * @return The format string for the indicator display.
859 elm_slider_indicator_format_get(const Evas_Object *obj)
861 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
862 Widget_Data *wd = elm_widget_data_get(obj);
863 if (!wd) return NULL;
864 return wd->indicator;
868 * Set orientation of the slider
870 * @param obj The slider object
871 * @param horizontal If set, the slider will be horizontal
876 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
878 ELM_CHECK_WIDTYPE(obj, widtype);
879 Widget_Data *wd = elm_widget_data_get(obj);
881 horizontal = !!horizontal;
882 if (wd->horizontal == horizontal) return;
883 wd->horizontal = horizontal;
888 * Get orientation of the slider
890 * @param obj The slider object
891 * @return If @c EINA_TRUE the slider will be horizontal, else it is
896 elm_slider_horizontal_get(const Evas_Object *obj)
898 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
899 Widget_Data *wd = elm_widget_data_get(obj);
900 if (!wd) return EINA_FALSE;
901 return wd->horizontal;
905 * Set the minimum and maximum values for the slider
907 * Maximum mut be greater than minimum.
909 * @param obj The slider object
910 * @param min The minimum value
911 * @param max The maximum value
916 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
918 ELM_CHECK_WIDTYPE(obj, widtype);
919 Widget_Data *wd = elm_widget_data_get(obj);
921 if ((wd->val_min == min) && (wd->val_max == max)) return;
924 if (wd->val < wd->val_min) wd->val = wd->val_min;
925 if (wd->val > wd->val_max) wd->val = wd->val_max;
932 * Get the minimum and maximum values for the slider
934 * @param obj The slider object
935 * @param min The pointer to store minimum value, may be @c NULL.
936 * @param max The pointer to store maximum value, may be @c NULL.
941 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
945 ELM_CHECK_WIDTYPE(obj, widtype);
946 Widget_Data *wd = elm_widget_data_get(obj);
948 if (min) *min = wd->val_min;
949 if (max) *max = wd->val_max;
953 * Set the value the slider indicates
955 * @param obj The slider object
956 * @param val The value (must be between min and max for the slider)
961 elm_slider_value_set(Evas_Object *obj, double val)
963 ELM_CHECK_WIDTYPE(obj, widtype);
964 Widget_Data *wd = elm_widget_data_get(obj);
966 if (wd->val == val) return;
968 if (wd->val < wd->val_min) wd->val = wd->val_min;
969 if (wd->val > wd->val_max) wd->val = wd->val_max;
976 * Get the value the slider has
978 * @param obj The slider object
979 * @return The value of the slider
984 elm_slider_value_get(const Evas_Object *obj)
986 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
987 Widget_Data *wd = elm_widget_data_get(obj);
993 * Invert the slider display
995 * Normally the slider will display and interpret values from low to high
996 * and when horizontal that is left to right. When vertical that is top
997 * to bottom. This inverts this (so from right to left or bottom to top) if
998 * inverted is set to 1.
1000 * @param obj The slider object
1001 * @param inverted The inverted flag. 1 == inverted, 0 == normal
1006 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
1008 ELM_CHECK_WIDTYPE(obj, widtype);
1009 Widget_Data *wd = elm_widget_data_get(obj);
1011 inverted = !!inverted;
1012 if (wd->inverted == inverted) return;
1013 wd->inverted = inverted;
1015 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1017 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1018 edje_object_message_signal_process(wd->slider);
1021 _indicator_set(obj);
1025 * Get if the slider display is inverted (backwards)
1027 * @param obj The slider object
1028 * @return If @c EINA_TRUE the slider will be inverted.
1032 elm_slider_inverted_get(const Evas_Object *obj)
1034 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1035 Widget_Data *wd = elm_widget_data_get(obj);
1036 if (!wd) return EINA_FALSE;
1037 return wd->inverted;
1041 * Set the format function pointer for the indicator area
1043 * Set the callback function to format the indicator string.
1044 * See elm_slider_indicator_format_set() for more info on how this works.
1046 * @param obj The slider object
1047 * @param indicator The format string for the indicator display
1048 * @param func The indicator format function
1049 * @param free_func The freeing function for the format string
1054 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
1056 ELM_CHECK_WIDTYPE(obj, widtype);
1057 Widget_Data *wd = elm_widget_data_get(obj);
1059 wd->indicator_format_func = func;
1060 wd->indicator_format_free = free_func;
1061 _indicator_set(obj);
1065 * Set the format function pointer for the units area
1067 * Set the callback function to format the indicator string.
1068 * See elm_slider_units_format_set() for more info on how this works.
1070 * @param obj The slider object
1071 * @param indicator The format string for the units display
1072 * @param func The units format function
1073 * @param free_func The freeing function for the format string
1078 elm_slider_units_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
1080 ELM_CHECK_WIDTYPE(obj, widtype);
1081 Widget_Data *wd = elm_widget_data_get(obj);
1083 wd->units_format_func = func;
1084 wd->units_format_free = free_func;
1085 _indicator_set(obj);
1089 * Set the end object (rightmost widget) of the slider object.
1091 * Once the end object is set, a previously set one will be deleted.
1092 * If you want to keep that old content object, use the
1093 * elm_button_end_unset() function.
1095 * @param obj The slider object
1096 * @param end The end object
1098 * @note If the object being set does not have minimum size hints set,
1099 * it won't get properly displayed.
1104 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
1106 ELM_CHECK_WIDTYPE(obj, widtype);
1107 Widget_Data *wd = elm_widget_data_get(obj);
1109 if (wd->end == end) return;
1110 if (wd->end) evas_object_del(wd->end);
1114 elm_widget_sub_object_add(obj, end);
1115 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1116 _changed_size_hints, obj);
1117 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
1118 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
1119 edje_object_message_signal_process(wd->slider);
1125 * Unset the rightmost widget of the slider, unparenting and
1128 * @param obj The slider object
1129 * @return the previously set end sub-object of this slider, on
1132 * @see elm_slider_end_set()
1137 elm_slider_end_unset(Evas_Object *obj)
1139 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1140 Widget_Data *wd = elm_widget_data_get(obj);
1141 Evas_Object *ret = NULL;
1142 if (!wd) return NULL;
1145 elm_widget_sub_object_del(obj, wd->end);
1147 edje_object_part_unswallow(wd->slider, wd->end);
1148 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
1156 * Get the end icon object of the slider object. This object is owned
1157 * by the scrolled entry and should not be modified.
1159 * @param obj The slider object
1160 * @return The end icon object
1165 elm_slider_end_get(const Evas_Object *obj)
1167 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1168 Widget_Data *wd = elm_widget_data_get(obj);
1169 if (!wd) return NULL;
1174 * Set whether to the slider indicator (augmented knob) at all.
1176 * @param obj The slider object
1177 * @param show @c EINA_TRUE will make it show it, @c EINA_FALSE will
1178 * let the knob alwayes at default size.
1180 * @note It will conflict with elm_slider_indicator_format_set(), if
1181 * you wanted those effects.
1186 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1188 ELM_CHECK_WIDTYPE(obj, widtype);
1189 Widget_Data *wd = elm_widget_data_get(obj);
1191 wd->indicator_show = EINA_TRUE;
1192 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1195 wd->indicator_show = EINA_FALSE;
1196 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1201 * Get the state of indicator in the slider (if it's being shown or
1204 * @param obj The slider object
1205 * @return @c EINA_TRUE if the indicator is being shown, @c EINA_FALSE
1211 elm_slider_indicator_show_get(const Evas_Object *obj)
1213 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1214 Widget_Data *wd = elm_widget_data_get(obj);
1215 if (!wd) return EINA_FALSE;
1216 return wd->indicator_show;