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;
70 double val, val_min, val_max;
75 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
77 static const char *widtype = NULL;
78 static void _del_hook(Evas_Object *obj);
79 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
80 static void _theme_hook(Evas_Object *obj);
81 static void _disable_hook(Evas_Object *obj);
82 static void _sizing_eval(Evas_Object *obj);
83 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
84 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
85 static void _units_set(Evas_Object *obj);
86 static void _val_set(Evas_Object *obj);
87 static void _indicator_set(Evas_Object *obj);
88 static void _on_focus_hook(void *data, Evas_Object *obj);
89 static void _drag_up(void *data, Evas_Object *obj,
90 const char *emission, const char *source);
91 static void _drag_down(void *data, Evas_Object *obj,
92 const char *emission, const char *source);
93 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
94 Evas_Callback_Type type, void *event_info);
95 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
97 static const char SIG_CHANGED[] = "changed";
98 static const char SIG_DELAY_CHANGED[] = "delay,changed";
99 static const char SIG_DRAG_START[] = "slider,drag,start";
100 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
101 static const Evas_Smart_Cb_Description _signals[] = {
103 {SIG_DELAY_CHANGED, ""},
104 {SIG_DRAG_START, ""},
110 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
112 Evas_Event_Mouse_Wheel *mev;
113 Evas_Event_Key_Down *ev;
116 wd = elm_widget_data_get(obj);
117 if (!wd) return EINA_FALSE;
118 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
120 if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
121 else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
124 if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
125 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
127 if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
128 else _drag_down(obj, NULL, NULL, NULL);
129 mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
134 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
135 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
136 if ((!strcmp(ev->keyname, "Left"))
137 || (!strcmp(ev->keyname, "KP_Left")))
139 if (!wd->horizontal) return EINA_FALSE;
140 if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
141 else _drag_up(obj, NULL, NULL, NULL);
142 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
145 else if ((!strcmp(ev->keyname, "Right"))
146 || (!strcmp(ev->keyname, "KP_Right")))
148 if (!wd->horizontal) return EINA_FALSE;
149 if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
150 else _drag_down(obj, NULL, NULL, NULL);
151 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
154 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
156 if (wd->horizontal) return EINA_FALSE;
157 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
158 else _drag_down(obj, NULL, NULL, NULL);
159 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
162 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
164 if (wd->horizontal) return EINA_FALSE;
165 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
166 else _drag_up(obj, NULL, NULL, NULL);
167 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
170 else return EINA_FALSE;
174 _del_hook(Evas_Object *obj)
176 Widget_Data *wd = elm_widget_data_get(obj);
178 if (wd->label) eina_stringshare_del(wd->label);
179 if (wd->indicator) eina_stringshare_del(wd->units);
180 if (wd->delay) ecore_timer_del(wd->delay);
185 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
187 Widget_Data *wd = elm_widget_data_get(obj);
189 if (elm_widget_focus_get(obj))
191 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
192 evas_object_focus_set(wd->slider, EINA_TRUE);
196 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
197 evas_object_focus_set(wd->slider, EINA_FALSE);
202 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
204 Widget_Data *wd = elm_widget_data_get(obj);
206 edje_object_mirrored_set(wd->slider, rtl);
210 _theme_hook(Evas_Object *obj)
212 Widget_Data *wd = elm_widget_data_get(obj);
214 _elm_widget_mirrored_reload(obj);
215 _mirrored_set(obj, elm_widget_mirrored_get(obj));
217 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
219 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
220 if (elm_widget_disabled_get(obj))
221 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
223 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
226 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
227 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
230 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
232 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
235 edje_object_part_text_set(wd->slider, "elm.text", wd->label);
236 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
240 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
243 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
245 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
248 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
250 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
253 edje_object_message_signal_process(wd->slider);
254 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
260 _disable_hook(Evas_Object *obj)
262 Widget_Data *wd = elm_widget_data_get(obj);
264 if (elm_widget_disabled_get(obj))
265 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
267 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
271 _sizing_eval(Evas_Object *obj)
273 Widget_Data *wd = elm_widget_data_get(obj);
274 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
276 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
277 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
278 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
279 evas_object_size_hint_min_set(obj, minw, minh);
280 evas_object_size_hint_max_set(obj, maxw, maxh);
284 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
286 Widget_Data *wd = elm_widget_data_get(data);
288 if ((obj != wd->icon) && (obj != wd->end)) return;
293 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
295 Widget_Data *wd = elm_widget_data_get(obj);
296 Evas_Object *sub = event_info;
300 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
301 evas_object_event_callback_del_full
302 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
304 edje_object_message_signal_process(wd->slider);
309 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
310 evas_object_event_callback_del_full(sub,
311 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
312 _changed_size_hints, obj);
314 edje_object_message_signal_process(wd->slider);
320 _delay_change(void *data)
322 Widget_Data *wd = elm_widget_data_get(data);
323 if (!wd) return ECORE_CALLBACK_CANCEL;
325 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
326 return ECORE_CALLBACK_CANCEL;
330 _val_fetch(Evas_Object *obj)
333 Widget_Data *wd = elm_widget_data_get(obj);
334 double posx = 0.0, posy = 0.0, pos = 0.0, val;
336 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
338 if (wd->horizontal) pos = posx;
341 rtl = elm_widget_mirrored_get(obj);
342 if ((!rtl && wd->inverted) || (rtl &&
343 ((!wd->horizontal && wd->inverted) ||
344 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
345 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
349 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
350 if (wd->delay) ecore_timer_del(wd->delay);
351 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
356 _val_set(Evas_Object *obj)
359 Widget_Data *wd = elm_widget_data_get(obj);
362 if (wd->val_max > wd->val_min)
363 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
366 if (pos < 0.0) pos = 0.0;
367 else if (pos > 1.0) pos = 1.0;
369 rtl = elm_widget_mirrored_get(obj);
370 if ((!rtl && wd->inverted) || (rtl &&
371 ((!wd->horizontal && wd->inverted) ||
372 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
373 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
377 _units_set(Evas_Object *obj)
379 Widget_Data *wd = elm_widget_data_get(obj);
381 if (wd->units_format_func)
384 buf = wd->units_format_func(wd->val);
385 edje_object_part_text_set(wd->slider, "elm.units", buf);
386 if (wd->units_format_free) wd->units_format_free(buf);
392 snprintf(buf, sizeof(buf), wd->units, wd->val);
393 edje_object_part_text_set(wd->slider, "elm.units", buf);
396 edje_object_part_text_set(wd->slider, "elm.units", NULL);
400 _indicator_set(Evas_Object *obj)
402 Widget_Data *wd = elm_widget_data_get(obj);
404 if (wd->indicator_format_func)
407 buf = wd->indicator_format_func(wd->val);
408 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
409 if (wd->indicator_format_free) wd->indicator_format_free(buf);
411 else if (wd->indicator)
414 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
415 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
418 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
422 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
424 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
425 if (elm_widget_disabled_get(data)) return;
426 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
427 edje_object_message_signal_process(wd->slider);
430 _indicator_set(data);
434 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
436 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
437 if (elm_widget_disabled_get(data)) return;
439 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
440 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
441 edje_object_message_signal_process(wd->slider);
443 _indicator_set(data);
444 elm_widget_scroll_freeze_push(data);
448 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
450 if (elm_widget_disabled_get(data)) return;
452 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
454 _indicator_set(data);
455 elm_widget_scroll_freeze_pop(data);
459 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
461 if (elm_widget_disabled_get(data)) return;
464 _indicator_set(data);
468 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
472 if (elm_widget_disabled_get(data)) return;
474 wd = elm_widget_data_get(data);
477 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
479 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
483 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
487 if (elm_widget_disabled_get(data)) return;
489 wd = elm_widget_data_get(data);
492 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
494 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
498 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
500 Widget_Data *wd = elm_widget_data_get(data);
501 Evas_Event_Mouse_Down *ev = event_info;
502 Evas_Coord x, y, w, h;
503 double button_x, button_y;
504 if (elm_widget_disabled_get(data)) return;
506 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
507 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
510 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
511 if (button_x > 1) button_x = 1;
512 if (button_x < 0) button_x = 0;
516 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
517 if (button_y > 1) button_y = 1;
518 if (button_y < 0) button_y = 0;
520 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
521 evas_event_feed_mouse_cancel(e, 0, NULL);
524 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
529 _elm_slider_label_set(Evas_Object *obj, const char *item, const char *label)
531 ELM_CHECK_WIDTYPE(obj, widtype);
532 Widget_Data *wd = elm_widget_data_get(obj);
533 if (item && strcmp(item, "default")) return;
535 eina_stringshare_replace(&wd->label, label);
538 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
539 edje_object_message_signal_process(wd->slider);
543 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
544 edje_object_message_signal_process(wd->slider);
546 edje_object_part_text_set(wd->slider, "elm.text", label);
551 _elm_slider_label_get(const Evas_Object *obj, const char *item)
553 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
554 Widget_Data *wd = elm_widget_data_get(obj);
555 if (item && strcmp(item, "default")) return NULL;
556 if (!wd) return NULL;
561 * Add a new slider to the parent
563 * @param parent The parent object
564 * @return The new object or NULL if it cannot be created
569 elm_slider_add(Evas_Object *parent)
575 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
577 ELM_SET_WIDTYPE(widtype, "slider");
578 elm_widget_type_set(obj, "slider");
579 elm_widget_sub_object_add(parent, obj);
580 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
581 elm_widget_data_set(obj, wd);
582 elm_widget_del_hook_set(obj, _del_hook);
583 elm_widget_theme_hook_set(obj, _theme_hook);
584 elm_widget_disable_hook_set(obj, _disable_hook);
585 elm_widget_can_focus_set(obj, EINA_TRUE);
586 elm_widget_event_hook_set(obj, _event_hook);
587 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
588 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
590 wd->horizontal = EINA_TRUE;
591 wd->indicator_show = EINA_TRUE;
597 wd->slider = edje_object_add(e);
598 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
599 elm_widget_resize_object_set(obj, wd->slider);
600 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
601 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
602 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
603 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
604 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
605 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
606 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
608 wd->spacer = evas_object_rectangle_add(e);
609 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
610 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
611 elm_widget_sub_object_add(obj, wd->spacer);
612 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
613 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
614 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
616 _mirrored_set(obj, elm_widget_mirrored_get(obj));
619 // TODO: convert Elementary to subclassing of Evas_Smart_Class
620 // TODO: and save some bytes, making descriptions per-class and not instance!
621 evas_object_smart_callbacks_descriptions_set(obj, _signals);
626 * Set the label of the slider
628 * @param obj The slider object
629 * @param label The text label string in UTF-8
634 elm_slider_label_set(Evas_Object *obj, const char *label)
636 _elm_slider_label_set(obj, NULL, label);
640 * Get the label of the slider
642 * @param obj The slider object
643 * @return The text label string in UTF-8
648 elm_slider_label_get(const Evas_Object *obj)
650 return _elm_slider_label_get(obj, NULL);
654 * Set the icon object (leftmost widget) of the slider object.
656 * Once the icon object is set, a previously set one will be deleted.
657 * If you want to keep that old content object, use the
658 * elm_slider_icon_unset() function.
660 * @param obj The slider object
661 * @param icon The icon object
663 * @note If the object being set does not have minimum size hints set,
664 * it won't get properly displayed.
669 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
671 ELM_CHECK_WIDTYPE(obj, widtype);
672 Widget_Data *wd = elm_widget_data_get(obj);
674 if (wd->icon == icon) return;
675 if (wd->icon) evas_object_del(wd->icon);
679 elm_widget_sub_object_add(obj, icon);
680 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
681 _changed_size_hints, obj);
682 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
683 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
684 edje_object_message_signal_process(wd->slider);
690 * Unset the leftmost widget of the slider, unparenting and
693 * @param obj The slider object
694 * @return the previously set icon sub-object of this slider, on
697 * @see elm_slider_icon_set()
702 elm_slider_icon_unset(Evas_Object *obj)
704 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
705 Widget_Data *wd = elm_widget_data_get(obj);
706 Evas_Object *ret = NULL;
707 if (!wd) return NULL;
710 elm_widget_sub_object_del(obj, wd->icon);
712 edje_object_part_unswallow(wd->slider, wd->icon);
713 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
721 * Get the icon object of the slider object. This object is owned by
722 * the scrolled entry and should not be modified.
724 * @param obj The slider object
725 * @return The icon object
730 elm_slider_icon_get(const Evas_Object *obj)
732 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
733 Widget_Data *wd = elm_widget_data_get(obj);
734 if (!wd) return NULL;
739 * Set the length of the dragable region of the slider
741 * This sets the minimum width or height (depending on orientation) of the
742 * area of the slider that allows the slider to be dragged around. This in
743 * turn affects the objects minimum size (along with icon label and unit
744 * text). Note that this will also get multiplied by the scale factor.
746 * @param obj The slider object
747 * @param size The length of the slider area
752 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
754 ELM_CHECK_WIDTYPE(obj, widtype);
755 Widget_Data *wd = elm_widget_data_get(obj);
757 if (wd->size == size) return;
760 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
762 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
763 if (wd->indicator_show)
764 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
766 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
767 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
772 * Get the length of the dragable region of the slider
774 * This gets the minimum width or height (depending on orientation) of
775 * the area of the slider that allows the slider to be dragged
776 * around. Note that this will also get multiplied by the scale
779 * @param obj The slider object
780 * @return The length of the slider area
785 elm_slider_span_size_get(const Evas_Object *obj)
787 ELM_CHECK_WIDTYPE(obj, widtype) 0;
788 Widget_Data *wd = elm_widget_data_get(obj);
794 * Set the format string of the unit area
796 * If NULL, this disabls the unit area display. If not it sets the format
797 * string for the unit text. The unit text is provided a floating point
798 * value, so the unit text can display up to 1 floating point value. Note that
799 * this is optional. Use a format string such as "%1.2f meters" for example.
801 * @param obj The slider object
802 * @param units The format string for the units display
807 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
809 ELM_CHECK_WIDTYPE(obj, widtype);
810 Widget_Data *wd = elm_widget_data_get(obj);
812 eina_stringshare_replace(&wd->units, units);
815 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
816 edje_object_message_signal_process(wd->slider);
820 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
821 edje_object_message_signal_process(wd->slider);
828 * Get the format string for the unit area
830 * The slider may also display a value (the value of the slider) somewhere
831 * (for example above the slider knob that is dragged around). This sets the
832 * format string for this. See elm_slider_unit_format_set() for more
833 * information on how this works.
835 * @param obj The slider object
836 * @return The format string for the unit display.
841 elm_slider_unit_format_get(const Evas_Object *obj)
843 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
844 Widget_Data *wd = elm_widget_data_get(obj);
845 if (!wd) return NULL;
850 * Set the format string for the indicator area
852 * The slider may also display a value (the value of the slider) somewhere
853 * (for example above the slider knob that is dragged around). This sets the
854 * format string for this. See elm_slider_unit_format_set() for more
855 * information on how this works.
857 * @param obj The slider object
858 * @param indicator The format string for the indicator display
863 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
865 ELM_CHECK_WIDTYPE(obj, widtype);
866 Widget_Data *wd = elm_widget_data_get(obj);
868 eina_stringshare_replace(&wd->indicator, indicator);
873 * Get the format string for the indicator area
875 * The slider may also display a value (the value of the slider) somewhere
876 * (for example above the slider knob that is dragged around). This sets the
877 * format string for this. See elm_slider_indicator_format_set() for more
878 * information on how this works.
880 * @param obj The slider object
881 * @return The format string for the indicator display.
886 elm_slider_indicator_format_get(const Evas_Object *obj)
888 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
889 Widget_Data *wd = elm_widget_data_get(obj);
890 if (!wd) return NULL;
891 return wd->indicator;
895 * Set orientation of the slider
897 * @param obj The slider object
898 * @param horizontal If set, the slider will be horizontal
903 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
905 ELM_CHECK_WIDTYPE(obj, widtype);
906 Widget_Data *wd = elm_widget_data_get(obj);
908 horizontal = !!horizontal;
909 if (wd->horizontal == horizontal) return;
910 wd->horizontal = horizontal;
915 * Get orientation of the slider
917 * @param obj The slider object
918 * @return If @c EINA_TRUE the slider will be horizontal, else it is
923 elm_slider_horizontal_get(const Evas_Object *obj)
925 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
926 Widget_Data *wd = elm_widget_data_get(obj);
927 if (!wd) return EINA_FALSE;
928 return wd->horizontal;
932 * Set the minimum and maximum values for the slider
934 * Maximum mut be greater than minimum.
936 * @param obj The slider object
937 * @param min The minimum value
938 * @param max The maximum value
943 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
945 ELM_CHECK_WIDTYPE(obj, widtype);
946 Widget_Data *wd = elm_widget_data_get(obj);
948 if ((wd->val_min == min) && (wd->val_max == max)) 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 minimum and maximum values for the slider
961 * @param obj The slider object
962 * @param min The pointer to store minimum value, may be @c NULL.
963 * @param max The pointer to store maximum value, may be @c NULL.
968 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
972 ELM_CHECK_WIDTYPE(obj, widtype);
973 Widget_Data *wd = elm_widget_data_get(obj);
975 if (min) *min = wd->val_min;
976 if (max) *max = wd->val_max;
980 * Set the value the slider indicates
982 * @param obj The slider object
983 * @param val The value (must be between min and max for the slider)
988 elm_slider_value_set(Evas_Object *obj, double val)
990 ELM_CHECK_WIDTYPE(obj, widtype);
991 Widget_Data *wd = elm_widget_data_get(obj);
993 if (wd->val == val) return;
995 if (wd->val < wd->val_min) wd->val = wd->val_min;
996 if (wd->val > wd->val_max) wd->val = wd->val_max;
997 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
1000 _indicator_set(obj);
1004 * Get the value the slider has
1006 * @param obj The slider object
1007 * @return The value of the slider
1012 elm_slider_value_get(const Evas_Object *obj)
1014 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1015 Widget_Data *wd = elm_widget_data_get(obj);
1016 if (!wd) return 0.0;
1021 * Invert the slider display
1023 * Normally the slider will display and interpret values from low to high
1024 * and when horizontal that is left to right. When vertical that is top
1025 * to bottom. This inverts this (so from right to left or bottom to top) if
1026 * inverted is set to 1.
1028 * @param obj The slider object
1029 * @param inverted The inverted flag. 1 == inverted, 0 == normal
1034 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
1036 ELM_CHECK_WIDTYPE(obj, widtype);
1037 Widget_Data *wd = elm_widget_data_get(obj);
1039 inverted = !!inverted;
1040 if (wd->inverted == inverted) return;
1041 wd->inverted = inverted;
1043 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1045 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1046 edje_object_message_signal_process(wd->slider);
1049 _indicator_set(obj);
1053 * Get if the slider display is inverted (backwards)
1055 * @param obj The slider object
1056 * @return If @c EINA_TRUE the slider will be inverted.
1060 elm_slider_inverted_get(const Evas_Object *obj)
1062 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1063 Widget_Data *wd = elm_widget_data_get(obj);
1064 if (!wd) return EINA_FALSE;
1065 return wd->inverted;
1069 * Set the format function pointer for the indicator area
1071 * Set the callback function to format the indicator string.
1072 * See elm_slider_indicator_format_set() for more info on how this works.
1074 * @param obj The slider object
1075 * @param indicator The format string for the indicator display
1076 * @param func The indicator format function
1077 * @param free_func The freeing function for the format string
1082 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
1084 ELM_CHECK_WIDTYPE(obj, widtype);
1085 Widget_Data *wd = elm_widget_data_get(obj);
1087 wd->indicator_format_func = func;
1088 wd->indicator_format_free = free_func;
1089 _indicator_set(obj);
1093 * Set the format function pointer for the units area
1095 * Set the callback function to format the indicator string.
1096 * See elm_slider_units_format_set() for more info on how this works.
1098 * @param obj The slider object
1099 * @param indicator The format string for the units display
1100 * @param func The units format function
1101 * @param free_func The freeing function for the format string
1106 elm_slider_units_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
1108 ELM_CHECK_WIDTYPE(obj, widtype);
1109 Widget_Data *wd = elm_widget_data_get(obj);
1111 wd->units_format_func = func;
1112 wd->units_format_free = free_func;
1113 _indicator_set(obj);
1117 * Set the end object (rightmost widget) of the slider object.
1119 * Once the end object is set, a previously set one will be deleted.
1120 * If you want to keep that old content object, use the
1121 * elm_button_end_unset() function.
1123 * @param obj The slider object
1124 * @param end The end object
1126 * @note If the object being set does not have minimum size hints set,
1127 * it won't get properly displayed.
1132 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
1134 ELM_CHECK_WIDTYPE(obj, widtype);
1135 Widget_Data *wd = elm_widget_data_get(obj);
1137 if (wd->end == end) return;
1138 if (wd->end) evas_object_del(wd->end);
1142 elm_widget_sub_object_add(obj, end);
1143 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1144 _changed_size_hints, obj);
1145 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
1146 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
1147 edje_object_message_signal_process(wd->slider);
1153 * Unset the rightmost widget of the slider, unparenting and
1156 * @param obj The slider object
1157 * @return the previously set end sub-object of this slider, on
1160 * @see elm_slider_end_set()
1165 elm_slider_end_unset(Evas_Object *obj)
1167 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1168 Widget_Data *wd = elm_widget_data_get(obj);
1169 Evas_Object *ret = NULL;
1170 if (!wd) return NULL;
1173 elm_widget_sub_object_del(obj, wd->end);
1175 edje_object_part_unswallow(wd->slider, wd->end);
1176 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
1184 * Get the end icon object of the slider object. This object is owned
1185 * by the scrolled entry and should not be modified.
1187 * @param obj The slider object
1188 * @return The end icon object
1193 elm_slider_end_get(const Evas_Object *obj)
1195 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1196 Widget_Data *wd = elm_widget_data_get(obj);
1197 if (!wd) return NULL;
1202 * Set whether to the slider indicator (augmented knob) at all.
1204 * @param obj The slider object
1205 * @param show @c EINA_TRUE will make it show it, @c EINA_FALSE will
1206 * let the knob alwayes at default size.
1208 * @note It will conflict with elm_slider_indicator_format_set(), if
1209 * you wanted those effects.
1214 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1216 ELM_CHECK_WIDTYPE(obj, widtype);
1217 Widget_Data *wd = elm_widget_data_get(obj);
1219 wd->indicator_show = EINA_TRUE;
1220 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1223 wd->indicator_show = EINA_FALSE;
1224 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1229 * Get the state of indicator in the slider (if it's being shown or
1232 * @param obj The slider object
1233 * @return @c EINA_TRUE if the indicator is being shown, @c EINA_FALSE
1239 elm_slider_indicator_show_get(const Evas_Object *obj)
1241 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1242 Widget_Data *wd = elm_widget_data_get(obj);
1243 if (!wd) return EINA_FALSE;
1244 return wd->indicator_show;