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;
51 const char *indicator;
52 const char *(*indicator_format_func)(double val);
53 Eina_Bool horizontal : 1;
54 Eina_Bool inverted : 1;
55 Eina_Bool indicator_show : 1;
56 double val, val_min, val_max;
61 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
63 static const char *widtype = NULL;
64 static void _del_hook(Evas_Object *obj);
65 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
66 static void _theme_hook(Evas_Object *obj);
67 static void _disable_hook(Evas_Object *obj);
68 static void _sizing_eval(Evas_Object *obj);
69 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
70 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
71 static void _units_set(Evas_Object *obj);
72 static void _val_set(Evas_Object *obj);
73 static void _indicator_set(Evas_Object *obj);
74 static void _on_focus_hook(void *data, Evas_Object *obj);
75 static void _drag_up(void *data, Evas_Object *obj,
76 const char *emission, const char *source);
77 static void _drag_down(void *data, Evas_Object *obj,
78 const char *emission, const char *source);
79 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
80 Evas_Callback_Type type, void *event_info);
81 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
83 static const char SIG_CHANGED[] = "changed";
84 static const char SIG_DELAY_CHANGED[] = "delay,changed";
85 static const char SIG_DRAG_START[] = "slider,drag,start";
86 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
87 static const Evas_Smart_Cb_Description _signals[] = {
89 {SIG_DELAY_CHANGED, ""},
96 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
98 Evas_Event_Mouse_Wheel *mev;
99 Evas_Event_Key_Down *ev;
102 wd = elm_widget_data_get(obj);
103 if (!wd) return EINA_FALSE;
105 if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
106 else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
109 if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
110 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
112 if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
113 else _drag_down(obj, NULL, NULL, NULL);
114 mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
119 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
120 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
121 if ((!strcmp(ev->keyname, "Left"))
122 || (!strcmp(ev->keyname, "KP_Left")))
124 if (!wd->horizontal) return EINA_FALSE;
125 if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
126 else _drag_up(obj, NULL, NULL, NULL);
127 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
130 else if ((!strcmp(ev->keyname, "Right"))
131 || (!strcmp(ev->keyname, "KP_Right")))
133 if (!wd->horizontal) return EINA_FALSE;
134 if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
135 else _drag_down(obj, NULL, NULL, NULL);
136 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
139 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
141 if (wd->horizontal) return EINA_FALSE;
142 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
143 else _drag_down(obj, NULL, NULL, NULL);
144 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
147 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
149 if (wd->horizontal) return EINA_FALSE;
150 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
151 else _drag_up(obj, NULL, NULL, NULL);
152 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
155 else return EINA_FALSE;
159 _del_hook(Evas_Object *obj)
161 Widget_Data *wd = elm_widget_data_get(obj);
163 if (wd->label) eina_stringshare_del(wd->label);
164 if (wd->indicator) eina_stringshare_del(wd->units);
165 if (wd->delay) ecore_timer_del(wd->delay);
170 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
172 Widget_Data *wd = elm_widget_data_get(obj);
174 if (elm_widget_focus_get(obj))
176 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
177 evas_object_focus_set(wd->slider, EINA_TRUE);
181 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
182 evas_object_focus_set(wd->slider, EINA_FALSE);
187 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
189 Widget_Data *wd = elm_widget_data_get(obj);
191 edje_object_mirrored_set(wd->slider, rtl);
195 _theme_hook(Evas_Object *obj)
197 Widget_Data *wd = elm_widget_data_get(obj);
199 _elm_widget_mirrored_reload(obj);
200 _mirrored_set(obj, elm_widget_mirrored_get(obj));
202 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
204 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
207 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
208 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
211 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
213 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
216 edje_object_part_text_set(wd->slider, "elm.text", wd->label);
217 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
221 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
224 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
226 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
229 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
231 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
234 edje_object_message_signal_process(wd->slider);
235 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
241 _disable_hook(Evas_Object *obj)
243 Widget_Data *wd = elm_widget_data_get(obj);
245 if (elm_widget_disabled_get(obj))
246 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
248 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
252 _sizing_eval(Evas_Object *obj)
254 Widget_Data *wd = elm_widget_data_get(obj);
255 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
257 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
258 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
259 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
260 evas_object_size_hint_min_set(obj, minw, minh);
261 evas_object_size_hint_max_set(obj, maxw, maxh);
265 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
267 Widget_Data *wd = elm_widget_data_get(data);
269 if ((obj != wd->icon) && (obj != wd->end)) return;
274 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
276 Widget_Data *wd = elm_widget_data_get(obj);
277 Evas_Object *sub = event_info;
281 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
282 evas_object_event_callback_del_full
283 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
285 edje_object_message_signal_process(wd->slider);
290 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
291 evas_object_event_callback_del_full(sub,
292 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
293 _changed_size_hints, obj);
295 edje_object_message_signal_process(wd->slider);
301 _delay_change(void *data)
303 Widget_Data *wd = elm_widget_data_get(data);
304 if (!wd) return ECORE_CALLBACK_CANCEL;
306 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
307 return ECORE_CALLBACK_CANCEL;
311 _val_fetch(Evas_Object *obj)
314 Widget_Data *wd = elm_widget_data_get(obj);
315 double posx = 0.0, posy = 0.0, pos = 0.0, val;
317 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
319 if (wd->horizontal) pos = posx;
322 rtl = elm_widget_mirrored_get(obj);
323 if ((!rtl && wd->inverted) || (rtl &&
324 ((!wd->horizontal && wd->inverted) ||
325 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
326 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
330 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
331 if (wd->delay) ecore_timer_del(wd->delay);
332 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
337 _val_set(Evas_Object *obj)
340 Widget_Data *wd = elm_widget_data_get(obj);
343 if (wd->val_max > wd->val_min)
344 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
347 if (pos < 0.0) pos = 0.0;
348 else if (pos > 1.0) pos = 1.0;
350 rtl = elm_widget_mirrored_get(obj);
351 if ((!rtl && wd->inverted) || (rtl &&
352 ((!wd->horizontal && wd->inverted) ||
353 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
354 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
358 _units_set(Evas_Object *obj)
360 Widget_Data *wd = elm_widget_data_get(obj);
366 snprintf(buf, sizeof(buf), wd->units, wd->val);
367 edje_object_part_text_set(wd->slider, "elm.units", buf);
370 edje_object_part_text_set(wd->slider, "elm.units", NULL);
374 _indicator_set(Evas_Object *obj)
376 Widget_Data *wd = elm_widget_data_get(obj);
378 if (wd->indicator_format_func)
381 buf = wd->indicator_format_func(wd->val);
382 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
384 else if (wd->indicator)
387 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
388 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
391 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
395 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
399 _indicator_set(data);
403 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
406 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
408 _indicator_set(data);
409 elm_widget_scroll_freeze_push(data);
413 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
416 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
418 _indicator_set(data);
419 elm_widget_scroll_freeze_pop(data);
423 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
427 _indicator_set(data);
431 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
436 wd = elm_widget_data_get(data);
439 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
441 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
445 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
450 wd = elm_widget_data_get(data);
453 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
455 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
459 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
461 Widget_Data *wd = elm_widget_data_get(data);
462 Evas_Event_Mouse_Down *ev = event_info;
463 Evas_Coord x, y, w, h;
464 double button_x, button_y;
466 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
467 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
470 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
471 if (button_x > 1) button_x = 1;
472 if (button_x < 0) button_x = 0;
476 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
477 if (button_y > 1) button_y = 1;
478 if (button_y < 0) button_y = 0;
480 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
481 evas_event_feed_mouse_cancel(e, 0, NULL);
482 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
486 _elm_slider_label_set(Evas_Object *obj, const char *item, const char *label)
488 ELM_CHECK_WIDTYPE(obj, widtype);
489 Widget_Data *wd = elm_widget_data_get(obj);
490 if (item && strcmp(item, "default")) return;
492 eina_stringshare_replace(&wd->label, label);
495 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
496 edje_object_message_signal_process(wd->slider);
500 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
501 edje_object_message_signal_process(wd->slider);
503 edje_object_part_text_set(wd->slider, "elm.text", label);
508 _elm_slider_label_get(const Evas_Object *obj, const char *item)
510 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
511 Widget_Data *wd = elm_widget_data_get(obj);
512 if (item && strcmp(item, "default")) return NULL;
513 if (!wd) return NULL;
518 * Add a new slider to the parent
520 * @param parent The parent object
521 * @return The new object or NULL if it cannot be created
526 elm_slider_add(Evas_Object *parent)
532 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
534 ELM_SET_WIDTYPE(widtype, "slider");
535 elm_widget_type_set(obj, "slider");
536 elm_widget_sub_object_add(parent, obj);
537 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
538 elm_widget_data_set(obj, wd);
539 elm_widget_del_hook_set(obj, _del_hook);
540 elm_widget_theme_hook_set(obj, _theme_hook);
541 elm_widget_disable_hook_set(obj, _disable_hook);
542 elm_widget_can_focus_set(obj, EINA_TRUE);
543 elm_widget_event_hook_set(obj, _event_hook);
544 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
545 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
547 wd->horizontal = EINA_TRUE;
548 wd->indicator_show = EINA_TRUE;
553 wd->slider = edje_object_add(e);
554 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
555 elm_widget_resize_object_set(obj, wd->slider);
556 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
557 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
558 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
559 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
560 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
561 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
562 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
564 wd->spacer = evas_object_rectangle_add(e);
565 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
566 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
567 elm_widget_sub_object_add(obj, wd->spacer);
568 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
569 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
570 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
572 _mirrored_set(obj, elm_widget_mirrored_get(obj));
575 // TODO: convert Elementary to subclassing of Evas_Smart_Class
576 // TODO: and save some bytes, making descriptions per-class and not instance!
577 evas_object_smart_callbacks_descriptions_set(obj, _signals);
582 * Set the label of the slider
584 * @param obj The slider object
585 * @param label The text label string in UTF-8
590 elm_slider_label_set(Evas_Object *obj, const char *label)
592 _elm_slider_label_set(obj, NULL, label);
596 * Get the label of the slider
598 * @param obj The slider object
599 * @return The text label string in UTF-8
604 elm_slider_label_get(const Evas_Object *obj)
606 return _elm_slider_label_get(obj, NULL);
610 * Set the icon object (leftmost widget) of the slider object.
612 * Once the icon object is set, a previously set one will be deleted.
613 * If you want to keep that old content object, use the
614 * elm_slider_icon_unset() function.
616 * @param obj The slider object
617 * @param icon The icon object
619 * @note If the object being set does not have minimum size hints set,
620 * it won't get properly displayed.
625 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
627 ELM_CHECK_WIDTYPE(obj, widtype);
628 Widget_Data *wd = elm_widget_data_get(obj);
630 if (wd->icon == icon) return;
631 if (wd->icon) evas_object_del(wd->icon);
635 elm_widget_sub_object_add(obj, icon);
636 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
637 _changed_size_hints, obj);
638 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
639 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
640 edje_object_message_signal_process(wd->slider);
646 * Unset the leftmost widget of the slider, unparenting and
649 * @param obj The slider object
650 * @return the previously set icon sub-object of this slider, on
653 * @see elm_slider_icon_set()
658 elm_slider_icon_unset(Evas_Object *obj)
660 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
661 Widget_Data *wd = elm_widget_data_get(obj);
662 Evas_Object *ret = NULL;
663 if (!wd) return NULL;
666 elm_widget_sub_object_del(obj, wd->icon);
668 edje_object_part_unswallow(wd->slider, wd->icon);
669 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
677 * Get the icon object of the slider object. This object is owned by
678 * the scrolled entry and should not be modified.
680 * @param obj The slider object
681 * @return The icon object
686 elm_slider_icon_get(const Evas_Object *obj)
688 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
689 Widget_Data *wd = elm_widget_data_get(obj);
690 if (!wd) return NULL;
695 * Set the length of the dragable region of the slider
697 * This sets the minimum width or height (depending on orientation) of the
698 * area of the slider that allows the slider to be dragged around. This in
699 * turn affects the objects minimum size (along with icon label and unit
700 * text). Note that this will also get multiplied by the scale factor.
702 * @param obj The slider object
703 * @param size The length of the slider area
708 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
710 ELM_CHECK_WIDTYPE(obj, widtype);
711 Widget_Data *wd = elm_widget_data_get(obj);
713 if (wd->size == size) return;
716 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
718 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
719 if (wd->indicator_show)
720 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
722 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
723 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
728 * Get the length of the dragable region of the slider
730 * This gets the minimum width or height (depending on orientation) of
731 * the area of the slider that allows the slider to be dragged
732 * around. Note that this will also get multiplied by the scale
735 * @param obj The slider object
736 * @return The length of the slider area
741 elm_slider_span_size_get(const Evas_Object *obj)
743 ELM_CHECK_WIDTYPE(obj, widtype) 0;
744 Widget_Data *wd = elm_widget_data_get(obj);
750 * Set the format string of the unit area
752 * If NULL, this disabls the unit area display. If not it sets the format
753 * string for the unit text. The unit text is provided a floating point
754 * value, so the unit text can display up to 1 floating point value. Note that
755 * this is optional. Use a format string such as "%1.2f meters" for example.
757 * @param obj The slider object
758 * @param units The format string for the units display
763 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
765 ELM_CHECK_WIDTYPE(obj, widtype);
766 Widget_Data *wd = elm_widget_data_get(obj);
768 eina_stringshare_replace(&wd->units, units);
771 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
772 edje_object_message_signal_process(wd->slider);
776 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
777 edje_object_message_signal_process(wd->slider);
784 * Get the format string for the unit area
786 * The slider may also display a value (the value of the slider) somewhere
787 * (for example above the slider knob that is dragged around). This sets the
788 * format string for this. See elm_slider_unit_format_set() for more
789 * information on how this works.
791 * @param obj The slider object
792 * @return The format string for the unit display.
797 elm_slider_unit_format_get(const Evas_Object *obj)
799 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
800 Widget_Data *wd = elm_widget_data_get(obj);
801 if (!wd) return NULL;
806 * Set the format string for the indicator area
808 * The slider may also display a value (the value of the slider) somewhere
809 * (for example above the slider knob that is dragged around). This sets the
810 * format string for this. See elm_slider_unit_format_set() for more
811 * information on how this works.
813 * @param obj The slider object
814 * @param indicator The format string for the indicator display
819 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
821 ELM_CHECK_WIDTYPE(obj, widtype);
822 Widget_Data *wd = elm_widget_data_get(obj);
824 eina_stringshare_replace(&wd->indicator, indicator);
829 * Get the format string for the indicator area
831 * The slider may also display a value (the value of the slider) somewhere
832 * (for example above the slider knob that is dragged around). This sets the
833 * format string for this. See elm_slider_indicator_format_set() for more
834 * information on how this works.
836 * @param obj The slider object
837 * @return The format string for the indicator display.
842 elm_slider_indicator_format_get(const Evas_Object *obj)
844 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
845 Widget_Data *wd = elm_widget_data_get(obj);
846 if (!wd) return NULL;
847 return wd->indicator;
851 * Set orientation of the slider
853 * @param obj The slider object
854 * @param horizontal If set, the slider will be horizontal
859 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
861 ELM_CHECK_WIDTYPE(obj, widtype);
862 Widget_Data *wd = elm_widget_data_get(obj);
864 horizontal = !!horizontal;
865 if (wd->horizontal == horizontal) return;
866 wd->horizontal = horizontal;
871 * Get orientation of the slider
873 * @param obj The slider object
874 * @return If @c EINA_TRUE the slider will be horizontal, else it is
879 elm_slider_horizontal_get(const Evas_Object *obj)
881 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
882 Widget_Data *wd = elm_widget_data_get(obj);
883 if (!wd) return EINA_FALSE;
884 return wd->horizontal;
888 * Set the minimum and maximum values for the slider
890 * Maximum mut be greater than minimum.
892 * @param obj The slider object
893 * @param min The minimum value
894 * @param max The maximum value
899 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
901 ELM_CHECK_WIDTYPE(obj, widtype);
902 Widget_Data *wd = elm_widget_data_get(obj);
904 if ((wd->val_min == min) && (wd->val_max == max)) return;
907 if (wd->val < wd->val_min) wd->val = wd->val_min;
908 if (wd->val > wd->val_max) wd->val = wd->val_max;
915 * Get the minimum and maximum values for the slider
917 * @param obj The slider object
918 * @param min The pointer to store minimum value, may be @c NULL.
919 * @param max The pointer to store maximum value, may be @c NULL.
924 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
928 ELM_CHECK_WIDTYPE(obj, widtype);
929 Widget_Data *wd = elm_widget_data_get(obj);
931 if (min) *min = wd->val_min;
932 if (max) *max = wd->val_max;
936 * Set the value the slider indicates
938 * @param obj The slider object
939 * @param val The value (must be between min and max for the slider)
944 elm_slider_value_set(Evas_Object *obj, double val)
946 ELM_CHECK_WIDTYPE(obj, widtype);
947 Widget_Data *wd = elm_widget_data_get(obj);
949 if (wd->val == val) return;
951 if (wd->val < wd->val_min) wd->val = wd->val_min;
952 if (wd->val > wd->val_max) wd->val = wd->val_max;
959 * Get the value the slider has
961 * @param obj The slider object
962 * @return The value of the slider
967 elm_slider_value_get(const Evas_Object *obj)
969 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
970 Widget_Data *wd = elm_widget_data_get(obj);
976 * Invert the slider display
978 * Normally the slider will display and interpret values from low to high
979 * and when horizontal that is left to right. When vertical that is top
980 * to bottom. This inverts this (so from right to left or bottom to top) if
981 * inverted is set to 1.
983 * @param obj The slider object
984 * @param inverted The inverted flag. 1 == inverted, 0 == normal
989 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
991 ELM_CHECK_WIDTYPE(obj, widtype);
992 Widget_Data *wd = elm_widget_data_get(obj);
994 inverted = !!inverted;
995 if (wd->inverted == inverted) return;
996 wd->inverted = inverted;
998 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1000 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1001 edje_object_message_signal_process(wd->slider);
1004 _indicator_set(obj);
1008 * Get if the slider display is inverted (backwards)
1010 * @param obj The slider object
1011 * @return If @c EINA_TRUE the slider will be inverted.
1015 elm_slider_inverted_get(const Evas_Object *obj)
1017 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1018 Widget_Data *wd = elm_widget_data_get(obj);
1019 if (!wd) return EINA_FALSE;
1020 return wd->inverted;
1024 * Set the format function pointer for the inducator area
1026 * Set the callback function to format the indicator string.
1027 * See elm_slider_indicator_format_set() for more info on how this works.
1029 * @param obj The slider object
1030 * @param indicator The format string for the indicator display
1031 * @param func The indicator format function
1036 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val))
1038 ELM_CHECK_WIDTYPE(obj, widtype);
1039 Widget_Data *wd = elm_widget_data_get(obj);
1041 wd->indicator_format_func = func;
1042 _indicator_set(obj);
1046 * Set the end object (rightmost widget) of the slider object.
1048 * Once the end object is set, a previously set one will be deleted.
1049 * If you want to keep that old content object, use the
1050 * elm_button_end_unset() function.
1052 * @param obj The slider object
1053 * @param end The end object
1055 * @note If the object being set does not have minimum size hints set,
1056 * it won't get properly displayed.
1061 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
1063 ELM_CHECK_WIDTYPE(obj, widtype);
1064 Widget_Data *wd = elm_widget_data_get(obj);
1066 if (wd->end == end) return;
1067 if (wd->end) evas_object_del(wd->end);
1071 elm_widget_sub_object_add(obj, end);
1072 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1073 _changed_size_hints, obj);
1074 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
1075 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
1076 edje_object_message_signal_process(wd->slider);
1082 * Unset the rightmost widget of the slider, unparenting and
1085 * @param obj The slider object
1086 * @return the previously set end sub-object of this slider, on
1089 * @see elm_slider_end_set()
1094 elm_slider_end_unset(Evas_Object *obj)
1096 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1097 Widget_Data *wd = elm_widget_data_get(obj);
1098 Evas_Object *ret = NULL;
1099 if (!wd) return NULL;
1102 elm_widget_sub_object_del(obj, wd->end);
1104 edje_object_part_unswallow(wd->slider, wd->end);
1105 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
1113 * Get the end icon object of the slider object. This object is owned
1114 * by the scrolled entry and should not be modified.
1116 * @param obj The slider object
1117 * @return The end icon object
1122 elm_slider_end_get(const Evas_Object *obj)
1124 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1125 Widget_Data *wd = elm_widget_data_get(obj);
1126 if (!wd) return NULL;
1131 * Set whether to the slider indicator (augmented knob) at all.
1133 * @param obj The slider object
1134 * @param show @c EINA_TRUE will make it show it, @c EINA_FALSE will
1135 * let the knob alwayes at default size.
1137 * @note It will conflict with elm_slider_indicator_format_set(), if
1138 * you wanted those effects.
1143 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1145 ELM_CHECK_WIDTYPE(obj, widtype);
1146 Widget_Data *wd = elm_widget_data_get(obj);
1148 wd->indicator_show = EINA_TRUE;
1149 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1152 wd->indicator_show = EINA_FALSE;
1153 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1158 * Get the state of indicator in the slider (if it's being shown or
1161 * @param obj The slider object
1162 * @return @c EINA_TRUE if the indicator is being shown, @c EINA_FALSE
1168 elm_slider_indicator_show_get(const Evas_Object *obj)
1170 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1171 Widget_Data *wd = elm_widget_data_get(obj);
1172 if (!wd) return EINA_FALSE;
1173 return wd->indicator_show;