1 #include <Elementary.h>
5 * @defgroup Slider Slider
8 * The slider adds a dragable “slider” widget for selecting the value of
9 * something within a range.
12 * A slider can be horizontal or vertical. It can contain an Icon and has a
13 * primary label as well as a units label (that is formatted with floating
14 * point values and thus accepts a printf-style format string, like
15 * “%1.2f units”. There is also an indicator string that may be somewhere
16 * else (like on the slider itself) that also accepts a format string like
17 * units. Label, Icon Unit and Indicator strings/objects are optional.
19 * A slider may be inverted which means values invert, with high vales being
20 * on the left or top and low values on the right or bottom (as opposed to
21 * normally being low on the left or top and high on the bottom and right).
23 * The slider should have its minimum and maximum values set by the
24 * application with elm_slider_min_max_set() and value should also be set by
25 * the application before use with elm_slider_value_set(). The span of the
26 * slider is its length (horizontally or vertically). This will be scaled by
27 * the object or applications scaling factor. At any point code can query the
28 * slider for its value with elm_slider_value_get().
30 * Signals that you can add callbacks for are:
32 * "changed" - Whenever the slider value is changed by the user.
33 * "slider,drag,start" - dragging the slider indicator around has started
34 * "slider,drag,stop" - dragging the slider indicator around has stopped
35 * "delay,changed" - A short time after the value is changed by the user.
36 * This will be called only when the user stops dragging for
37 * a very short period or when they release their
38 * finger/mouse, so it avoids possibly expensive reactions to
42 typedef struct _Widget_Data Widget_Data;
55 const char *indicator;
57 const char *(*indicator_format_func)(double val);
58 void (*indicator_format_free)(const char *str);
60 const char *(*units_format_func)(double val);
61 void (*units_format_free)(const char *str);
63 double val, val_min, val_max;
66 Eina_Bool horizontal : 1;
67 Eina_Bool inverted : 1;
68 Eina_Bool indicator_show : 1;
72 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
74 static const char *widtype = NULL;
75 static void _del_hook(Evas_Object *obj);
76 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
77 static void _theme_hook(Evas_Object *obj);
78 static void _disable_hook(Evas_Object *obj);
79 static void _sizing_eval(Evas_Object *obj);
80 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
81 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
82 static void _units_set(Evas_Object *obj);
83 static void _val_set(Evas_Object *obj);
84 static void _indicator_set(Evas_Object *obj);
85 static void _on_focus_hook(void *data, Evas_Object *obj);
86 static void _drag_up(void *data, Evas_Object *obj,
87 const char *emission, const char *source);
88 static void _drag_down(void *data, Evas_Object *obj,
89 const char *emission, const char *source);
90 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
91 Evas_Callback_Type type, void *event_info);
92 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
94 static const char SIG_CHANGED[] = "changed";
95 static const char SIG_DELAY_CHANGED[] = "delay,changed";
96 static const char SIG_DRAG_START[] = "slider,drag,start";
97 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
98 static const Evas_Smart_Cb_Description _signals[] = {
100 {SIG_DELAY_CHANGED, ""},
101 {SIG_DRAG_START, ""},
107 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
109 Evas_Event_Mouse_Wheel *mev;
110 Evas_Event_Key_Down *ev;
113 wd = elm_widget_data_get(obj);
114 if (!wd) return EINA_FALSE;
115 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
117 if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
118 else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
121 if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
122 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
124 if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
125 else _drag_down(obj, NULL, NULL, NULL);
126 mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
131 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
132 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
133 if ((!strcmp(ev->keyname, "Left"))
134 || (!strcmp(ev->keyname, "KP_Left")))
136 if (!wd->horizontal) return EINA_FALSE;
137 if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
138 else _drag_up(obj, NULL, NULL, NULL);
139 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
142 else if ((!strcmp(ev->keyname, "Right"))
143 || (!strcmp(ev->keyname, "KP_Right")))
145 if (!wd->horizontal) return EINA_FALSE;
146 if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
147 else _drag_down(obj, NULL, NULL, NULL);
148 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
151 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
153 if (wd->horizontal) return EINA_FALSE;
154 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
155 else _drag_down(obj, NULL, NULL, NULL);
156 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
159 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
161 if (wd->horizontal) return EINA_FALSE;
162 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
163 else _drag_up(obj, NULL, NULL, NULL);
164 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
167 else return EINA_FALSE;
171 _del_hook(Evas_Object *obj)
173 Widget_Data *wd = elm_widget_data_get(obj);
175 if (wd->label) eina_stringshare_del(wd->label);
176 if (wd->indicator) eina_stringshare_del(wd->units);
177 if (wd->delay) ecore_timer_del(wd->delay);
182 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
184 Widget_Data *wd = elm_widget_data_get(obj);
186 if (elm_widget_focus_get(obj))
188 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
189 evas_object_focus_set(wd->slider, EINA_TRUE);
193 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
194 evas_object_focus_set(wd->slider, EINA_FALSE);
199 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
201 Widget_Data *wd = elm_widget_data_get(obj);
203 edje_object_mirrored_set(wd->slider, rtl);
207 _theme_hook(Evas_Object *obj)
209 Widget_Data *wd = elm_widget_data_get(obj);
211 _elm_widget_mirrored_reload(obj);
212 _mirrored_set(obj, elm_widget_mirrored_get(obj));
214 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
216 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
217 if (elm_widget_disabled_get(obj))
218 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
220 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
223 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
224 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
227 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
229 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
232 edje_object_part_text_set(wd->slider, "elm.text", wd->label);
233 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
237 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
240 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
242 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
245 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
247 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
250 edje_object_message_signal_process(wd->slider);
251 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
257 _disable_hook(Evas_Object *obj)
259 Widget_Data *wd = elm_widget_data_get(obj);
261 if (elm_widget_disabled_get(obj))
262 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
264 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
268 _sizing_eval(Evas_Object *obj)
270 Widget_Data *wd = elm_widget_data_get(obj);
271 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
273 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
274 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
275 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
276 evas_object_size_hint_min_set(obj, minw, minh);
277 evas_object_size_hint_max_set(obj, maxw, maxh);
281 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
283 Widget_Data *wd = elm_widget_data_get(data);
285 if ((obj != wd->icon) && (obj != wd->end)) return;
290 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
292 Widget_Data *wd = elm_widget_data_get(obj);
293 Evas_Object *sub = event_info;
297 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
298 evas_object_event_callback_del_full
299 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
301 edje_object_message_signal_process(wd->slider);
306 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
307 evas_object_event_callback_del_full(sub,
308 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
309 _changed_size_hints, obj);
311 edje_object_message_signal_process(wd->slider);
317 _delay_change(void *data)
319 Widget_Data *wd = elm_widget_data_get(data);
320 if (!wd) return ECORE_CALLBACK_CANCEL;
322 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
323 return ECORE_CALLBACK_CANCEL;
327 _val_fetch(Evas_Object *obj)
330 Widget_Data *wd = elm_widget_data_get(obj);
331 double posx = 0.0, posy = 0.0, pos = 0.0, val;
333 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
335 if (wd->horizontal) pos = posx;
338 rtl = elm_widget_mirrored_get(obj);
339 if ((!rtl && wd->inverted) || (rtl &&
340 ((!wd->horizontal && wd->inverted) ||
341 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
342 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
346 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
347 if (wd->delay) ecore_timer_del(wd->delay);
348 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
353 _val_set(Evas_Object *obj)
356 Widget_Data *wd = elm_widget_data_get(obj);
359 if (wd->val_max > wd->val_min)
360 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
363 if (pos < 0.0) pos = 0.0;
364 else if (pos > 1.0) pos = 1.0;
366 rtl = elm_widget_mirrored_get(obj);
367 if ((!rtl && wd->inverted) || (rtl &&
368 ((!wd->horizontal && wd->inverted) ||
369 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
370 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
374 _units_set(Evas_Object *obj)
376 Widget_Data *wd = elm_widget_data_get(obj);
378 if (wd->units_format_func)
381 buf = wd->units_format_func(wd->val);
382 edje_object_part_text_set(wd->slider, "elm.units", buf);
383 if (wd->units_format_free) wd->units_format_free(buf);
389 snprintf(buf, sizeof(buf), wd->units, wd->val);
390 edje_object_part_text_set(wd->slider, "elm.units", buf);
393 edje_object_part_text_set(wd->slider, "elm.units", NULL);
397 _indicator_set(Evas_Object *obj)
399 Widget_Data *wd = elm_widget_data_get(obj);
401 if (wd->indicator_format_func)
404 buf = wd->indicator_format_func(wd->val);
405 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
406 if (wd->indicator_format_free) wd->indicator_format_free(buf);
408 else if (wd->indicator)
411 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
412 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
415 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
419 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
421 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
422 if (elm_widget_disabled_get(data)) return;
423 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
424 edje_object_message_signal_process(wd->slider);
427 _indicator_set(data);
431 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
433 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
434 if (elm_widget_disabled_get(data)) return;
436 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
437 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
438 edje_object_message_signal_process(wd->slider);
440 _indicator_set(data);
441 elm_widget_scroll_freeze_push(data);
445 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
447 if (elm_widget_disabled_get(data)) return;
449 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
451 _indicator_set(data);
452 elm_widget_scroll_freeze_pop(data);
456 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
458 if (elm_widget_disabled_get(data)) return;
461 _indicator_set(data);
465 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
469 if (elm_widget_disabled_get(data)) return;
471 wd = elm_widget_data_get(data);
474 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
476 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
480 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
484 if (elm_widget_disabled_get(data)) return;
486 wd = elm_widget_data_get(data);
489 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
491 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
495 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
497 Widget_Data *wd = elm_widget_data_get(data);
498 Evas_Event_Mouse_Down *ev = event_info;
499 Evas_Coord x, y, w, h;
500 double button_x, button_y;
501 if (elm_widget_disabled_get(data)) return;
503 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
504 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
507 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
508 if (button_x > 1) button_x = 1;
509 if (button_x < 0) button_x = 0;
513 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
514 if (button_y > 1) button_y = 1;
515 if (button_y < 0) button_y = 0;
517 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
518 evas_event_feed_mouse_cancel(e, 0, NULL);
521 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
526 _elm_slider_label_set(Evas_Object *obj, const char *item, const char *label)
528 ELM_CHECK_WIDTYPE(obj, widtype);
529 Widget_Data *wd = elm_widget_data_get(obj);
530 if (item && strcmp(item, "default")) return;
532 eina_stringshare_replace(&wd->label, label);
535 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
536 edje_object_message_signal_process(wd->slider);
540 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
541 edje_object_message_signal_process(wd->slider);
543 edje_object_part_text_set(wd->slider, "elm.text", label);
548 _elm_slider_label_get(const Evas_Object *obj, const char *item)
550 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
551 Widget_Data *wd = elm_widget_data_get(obj);
552 if (item && strcmp(item, "default")) return NULL;
553 if (!wd) return NULL;
558 * Add a new slider to the parent
560 * @param parent The parent object
561 * @return The new object or NULL if it cannot be created
566 elm_slider_add(Evas_Object *parent)
572 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
574 ELM_SET_WIDTYPE(widtype, "slider");
575 elm_widget_type_set(obj, "slider");
576 elm_widget_sub_object_add(parent, obj);
577 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
578 elm_widget_data_set(obj, wd);
579 elm_widget_del_hook_set(obj, _del_hook);
580 elm_widget_theme_hook_set(obj, _theme_hook);
581 elm_widget_disable_hook_set(obj, _disable_hook);
582 elm_widget_can_focus_set(obj, EINA_TRUE);
583 elm_widget_event_hook_set(obj, _event_hook);
584 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
585 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
587 wd->horizontal = EINA_TRUE;
588 wd->indicator_show = EINA_TRUE;
594 wd->slider = edje_object_add(e);
595 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
596 elm_widget_resize_object_set(obj, wd->slider);
597 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
598 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
599 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
600 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
601 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
602 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
603 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
605 wd->spacer = evas_object_rectangle_add(e);
606 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
607 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
608 elm_widget_sub_object_add(obj, wd->spacer);
609 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
610 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
611 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
613 _mirrored_set(obj, elm_widget_mirrored_get(obj));
616 // TODO: convert Elementary to subclassing of Evas_Smart_Class
617 // TODO: and save some bytes, making descriptions per-class and not instance!
618 evas_object_smart_callbacks_descriptions_set(obj, _signals);
623 * Set the label of the slider
625 * @param obj The slider object
626 * @param label The text label string in UTF-8
631 elm_slider_label_set(Evas_Object *obj, const char *label)
633 _elm_slider_label_set(obj, NULL, label);
637 * Get the label of the slider
639 * @param obj The slider object
640 * @return The text label string in UTF-8
645 elm_slider_label_get(const Evas_Object *obj)
647 return _elm_slider_label_get(obj, NULL);
651 * Set the icon object (leftmost widget) of the slider object.
653 * Once the icon object is set, a previously set one will be deleted.
654 * If you want to keep that old content object, use the
655 * elm_slider_icon_unset() function.
657 * @param obj The slider object
658 * @param icon The icon object
660 * @note If the object being set does not have minimum size hints set,
661 * it won't get properly displayed.
666 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
668 ELM_CHECK_WIDTYPE(obj, widtype);
669 Widget_Data *wd = elm_widget_data_get(obj);
671 if (wd->icon == icon) return;
672 if (wd->icon) evas_object_del(wd->icon);
676 elm_widget_sub_object_add(obj, icon);
677 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
678 _changed_size_hints, obj);
679 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
680 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
681 edje_object_message_signal_process(wd->slider);
687 * Unset the leftmost widget of the slider, unparenting and
690 * @param obj The slider object
691 * @return the previously set icon sub-object of this slider, on
694 * @see elm_slider_icon_set()
699 elm_slider_icon_unset(Evas_Object *obj)
701 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
702 Widget_Data *wd = elm_widget_data_get(obj);
703 Evas_Object *ret = NULL;
704 if (!wd) return NULL;
707 elm_widget_sub_object_del(obj, wd->icon);
709 edje_object_part_unswallow(wd->slider, wd->icon);
710 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
718 * Get the icon object of the slider object. This object is owned by
719 * the scrolled entry and should not be modified.
721 * @param obj The slider object
722 * @return The icon object
727 elm_slider_icon_get(const Evas_Object *obj)
729 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
730 Widget_Data *wd = elm_widget_data_get(obj);
731 if (!wd) return NULL;
736 * Set the length of the dragable region of the slider
738 * This sets the minimum width or height (depending on orientation) of the
739 * area of the slider that allows the slider to be dragged around. This in
740 * turn affects the objects minimum size (along with icon label and unit
741 * text). Note that this will also get multiplied by the scale factor.
743 * @param obj The slider object
744 * @param size The length of the slider area
749 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
751 ELM_CHECK_WIDTYPE(obj, widtype);
752 Widget_Data *wd = elm_widget_data_get(obj);
754 if (wd->size == size) return;
757 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
759 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
760 if (wd->indicator_show)
761 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
763 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
764 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
769 * Get the length of the dragable region of the slider
771 * This gets the minimum width or height (depending on orientation) of
772 * the area of the slider that allows the slider to be dragged
773 * around. Note that this will also get multiplied by the scale
776 * @param obj The slider object
777 * @return The length of the slider area
782 elm_slider_span_size_get(const Evas_Object *obj)
784 ELM_CHECK_WIDTYPE(obj, widtype) 0;
785 Widget_Data *wd = elm_widget_data_get(obj);
791 * Set the format string of the unit area
793 * If NULL, this disabls the unit area display. If not it sets the format
794 * string for the unit text. The unit text is provided a floating point
795 * value, so the unit text can display up to 1 floating point value. Note that
796 * this is optional. Use a format string such as "%1.2f meters" for example.
798 * @param obj The slider object
799 * @param units The format string for the units display
804 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
806 ELM_CHECK_WIDTYPE(obj, widtype);
807 Widget_Data *wd = elm_widget_data_get(obj);
809 eina_stringshare_replace(&wd->units, units);
812 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
813 edje_object_message_signal_process(wd->slider);
817 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
818 edje_object_message_signal_process(wd->slider);
825 * Get the format string for the unit area
827 * The slider may also display a value (the value of the slider) somewhere
828 * (for example above the slider knob that is dragged around). This sets the
829 * format string for this. See elm_slider_unit_format_set() for more
830 * information on how this works.
832 * @param obj The slider object
833 * @return The format string for the unit display.
838 elm_slider_unit_format_get(const Evas_Object *obj)
840 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
841 Widget_Data *wd = elm_widget_data_get(obj);
842 if (!wd) return NULL;
847 * Set the format string for the indicator area
849 * The slider may also display a value (the value of the slider) somewhere
850 * (for example above the slider knob that is dragged around). This sets the
851 * format string for this. See elm_slider_unit_format_set() for more
852 * information on how this works.
854 * @param obj The slider object
855 * @param indicator The format string for the indicator display
860 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
862 ELM_CHECK_WIDTYPE(obj, widtype);
863 Widget_Data *wd = elm_widget_data_get(obj);
865 eina_stringshare_replace(&wd->indicator, indicator);
870 * Get the format string for the indicator area
872 * The slider may also display a value (the value of the slider) somewhere
873 * (for example above the slider knob that is dragged around). This sets the
874 * format string for this. See elm_slider_indicator_format_set() for more
875 * information on how this works.
877 * @param obj The slider object
878 * @return The format string for the indicator display.
883 elm_slider_indicator_format_get(const Evas_Object *obj)
885 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
886 Widget_Data *wd = elm_widget_data_get(obj);
887 if (!wd) return NULL;
888 return wd->indicator;
892 * Set orientation of the slider
894 * @param obj The slider object
895 * @param horizontal If set, the slider will be horizontal
900 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
902 ELM_CHECK_WIDTYPE(obj, widtype);
903 Widget_Data *wd = elm_widget_data_get(obj);
905 horizontal = !!horizontal;
906 if (wd->horizontal == horizontal) return;
907 wd->horizontal = horizontal;
912 * Get orientation of the slider
914 * @param obj The slider object
915 * @return If @c EINA_TRUE the slider will be horizontal, else it is
920 elm_slider_horizontal_get(const Evas_Object *obj)
922 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
923 Widget_Data *wd = elm_widget_data_get(obj);
924 if (!wd) return EINA_FALSE;
925 return wd->horizontal;
929 * Set the minimum and maximum values for the slider
931 * Maximum mut be greater than minimum.
933 * @param obj The slider object
934 * @param min The minimum value
935 * @param max The maximum value
940 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
942 ELM_CHECK_WIDTYPE(obj, widtype);
943 Widget_Data *wd = elm_widget_data_get(obj);
945 if ((wd->val_min == min) && (wd->val_max == max)) return;
948 if (wd->val < wd->val_min) wd->val = wd->val_min;
949 if (wd->val > wd->val_max) wd->val = wd->val_max;
956 * Get the minimum and maximum values for the slider
958 * @param obj The slider object
959 * @param min The pointer to store minimum value, may be @c NULL.
960 * @param max The pointer to store maximum value, may be @c NULL.
965 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
969 ELM_CHECK_WIDTYPE(obj, widtype);
970 Widget_Data *wd = elm_widget_data_get(obj);
972 if (min) *min = wd->val_min;
973 if (max) *max = wd->val_max;
977 * Set the value the slider indicates
979 * @param obj The slider object
980 * @param val The value (must be between min and max for the slider)
985 elm_slider_value_set(Evas_Object *obj, double val)
987 ELM_CHECK_WIDTYPE(obj, widtype);
988 Widget_Data *wd = elm_widget_data_get(obj);
990 if (wd->val == val) return;
992 if (wd->val < wd->val_min) wd->val = wd->val_min;
993 if (wd->val > wd->val_max) wd->val = wd->val_max;
994 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
1001 * Get the value the slider has
1003 * @param obj The slider object
1004 * @return The value of the slider
1009 elm_slider_value_get(const Evas_Object *obj)
1011 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1012 Widget_Data *wd = elm_widget_data_get(obj);
1013 if (!wd) return 0.0;
1018 * Invert the slider display
1020 * Normally the slider will display and interpret values from low to high
1021 * and when horizontal that is left to right. When vertical that is top
1022 * to bottom. This inverts this (so from right to left or bottom to top) if
1023 * inverted is set to 1.
1025 * @param obj The slider object
1026 * @param inverted The inverted flag. 1 == inverted, 0 == normal
1031 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
1033 ELM_CHECK_WIDTYPE(obj, widtype);
1034 Widget_Data *wd = elm_widget_data_get(obj);
1036 inverted = !!inverted;
1037 if (wd->inverted == inverted) return;
1038 wd->inverted = inverted;
1040 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1042 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1043 edje_object_message_signal_process(wd->slider);
1046 _indicator_set(obj);
1050 * Get if the slider display is inverted (backwards)
1052 * @param obj The slider object
1053 * @return If @c EINA_TRUE the slider will be inverted.
1057 elm_slider_inverted_get(const Evas_Object *obj)
1059 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1060 Widget_Data *wd = elm_widget_data_get(obj);
1061 if (!wd) return EINA_FALSE;
1062 return wd->inverted;
1066 * Set the format function pointer for the indicator area
1068 * Set the callback function to format the indicator string.
1069 * See elm_slider_indicator_format_set() for more info on how this works.
1071 * @param obj The slider object
1072 * @param indicator The format string for the indicator display
1073 * @param func The indicator format function
1074 * @param free_func The freeing function for the format string
1079 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
1081 ELM_CHECK_WIDTYPE(obj, widtype);
1082 Widget_Data *wd = elm_widget_data_get(obj);
1084 wd->indicator_format_func = func;
1085 wd->indicator_format_free = free_func;
1086 _indicator_set(obj);
1090 * Set the format function pointer for the units area
1092 * Set the callback function to format the indicator string.
1093 * See elm_slider_units_format_set() for more info on how this works.
1095 * @param obj The slider object
1096 * @param indicator The format string for the units display
1097 * @param func The units format function
1098 * @param free_func The freeing function for the format string
1103 elm_slider_units_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
1105 ELM_CHECK_WIDTYPE(obj, widtype);
1106 Widget_Data *wd = elm_widget_data_get(obj);
1108 wd->units_format_func = func;
1109 wd->units_format_free = free_func;
1110 _indicator_set(obj);
1114 * Set the end object (rightmost widget) of the slider object.
1116 * Once the end object is set, a previously set one will be deleted.
1117 * If you want to keep that old content object, use the
1118 * elm_button_end_unset() function.
1120 * @param obj The slider object
1121 * @param end The end object
1123 * @note If the object being set does not have minimum size hints set,
1124 * it won't get properly displayed.
1129 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
1131 ELM_CHECK_WIDTYPE(obj, widtype);
1132 Widget_Data *wd = elm_widget_data_get(obj);
1134 if (wd->end == end) return;
1135 if (wd->end) evas_object_del(wd->end);
1139 elm_widget_sub_object_add(obj, end);
1140 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1141 _changed_size_hints, obj);
1142 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
1143 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
1144 edje_object_message_signal_process(wd->slider);
1150 * Unset the rightmost widget of the slider, unparenting and
1153 * @param obj The slider object
1154 * @return the previously set end sub-object of this slider, on
1157 * @see elm_slider_end_set()
1162 elm_slider_end_unset(Evas_Object *obj)
1164 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1165 Widget_Data *wd = elm_widget_data_get(obj);
1166 Evas_Object *ret = NULL;
1167 if (!wd) return NULL;
1170 elm_widget_sub_object_del(obj, wd->end);
1172 edje_object_part_unswallow(wd->slider, wd->end);
1173 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
1181 * Get the end icon object of the slider object. This object is owned
1182 * by the scrolled entry and should not be modified.
1184 * @param obj The slider object
1185 * @return The end icon object
1190 elm_slider_end_get(const Evas_Object *obj)
1192 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1193 Widget_Data *wd = elm_widget_data_get(obj);
1194 if (!wd) return NULL;
1199 * Set whether to the slider indicator (augmented knob) at all.
1201 * @param obj The slider object
1202 * @param show @c EINA_TRUE will make it show it, @c EINA_FALSE will
1203 * let the knob alwayes at default size.
1205 * @note It will conflict with elm_slider_indicator_format_set(), if
1206 * you wanted those effects.
1211 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1213 ELM_CHECK_WIDTYPE(obj, widtype);
1214 Widget_Data *wd = elm_widget_data_get(obj);
1216 wd->indicator_show = EINA_TRUE;
1217 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1220 wd->indicator_show = EINA_FALSE;
1221 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1226 * Get the state of indicator in the slider (if it's being shown or
1229 * @param obj The slider object
1230 * @return @c EINA_TRUE if the indicator is being shown, @c EINA_FALSE
1236 elm_slider_indicator_show_get(const Evas_Object *obj)
1238 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1239 Widget_Data *wd = elm_widget_data_get(obj);
1240 if (!wd) return EINA_FALSE;
1241 return wd->indicator_show;