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;
52 const char *indicator;
53 const char *(*indicator_format_func)(double val);
54 Eina_Bool horizontal : 1;
55 Eina_Bool inverted : 1;
56 Eina_Bool indicator_show : 1;
58 double val, val_min, val_max;
63 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
65 static const char *widtype = NULL;
66 static void _del_hook(Evas_Object *obj);
67 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
68 static void _theme_hook(Evas_Object *obj);
69 static void _disable_hook(Evas_Object *obj);
70 static void _sizing_eval(Evas_Object *obj);
71 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
72 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
73 static void _units_set(Evas_Object *obj);
74 static void _val_set(Evas_Object *obj);
75 static void _indicator_set(Evas_Object *obj);
76 static void _on_focus_hook(void *data, Evas_Object *obj);
77 static void _drag_up(void *data, Evas_Object *obj,
78 const char *emission, const char *source);
79 static void _drag_down(void *data, Evas_Object *obj,
80 const char *emission, const char *source);
81 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
82 Evas_Callback_Type type, void *event_info);
83 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
85 static const char SIG_CHANGED[] = "changed";
86 static const char SIG_DELAY_CHANGED[] = "delay,changed";
87 static const char SIG_DRAG_START[] = "slider,drag,start";
88 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
89 static const Evas_Smart_Cb_Description _signals[] = {
91 {SIG_DELAY_CHANGED, ""},
98 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
100 Evas_Event_Mouse_Wheel *mev;
101 Evas_Event_Key_Down *ev;
104 wd = elm_widget_data_get(obj);
105 if (!wd) return EINA_FALSE;
106 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
108 if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
109 else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
112 if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
113 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
115 if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
116 else _drag_down(obj, NULL, NULL, NULL);
117 mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
122 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
123 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
124 if ((!strcmp(ev->keyname, "Left"))
125 || (!strcmp(ev->keyname, "KP_Left")))
127 if (!wd->horizontal) return EINA_FALSE;
128 if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
129 else _drag_up(obj, NULL, NULL, NULL);
130 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
133 else if ((!strcmp(ev->keyname, "Right"))
134 || (!strcmp(ev->keyname, "KP_Right")))
136 if (!wd->horizontal) return EINA_FALSE;
137 if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
138 else _drag_down(obj, NULL, NULL, NULL);
139 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
142 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
144 if (wd->horizontal) return EINA_FALSE;
145 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
146 else _drag_down(obj, NULL, NULL, NULL);
147 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
150 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
152 if (wd->horizontal) return EINA_FALSE;
153 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
154 else _drag_up(obj, NULL, NULL, NULL);
155 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
158 else return EINA_FALSE;
162 _del_hook(Evas_Object *obj)
164 Widget_Data *wd = elm_widget_data_get(obj);
166 if (wd->label) eina_stringshare_del(wd->label);
167 if (wd->indicator) eina_stringshare_del(wd->units);
168 if (wd->delay) ecore_timer_del(wd->delay);
173 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
175 Widget_Data *wd = elm_widget_data_get(obj);
177 if (elm_widget_focus_get(obj))
179 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
180 evas_object_focus_set(wd->slider, EINA_TRUE);
184 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
185 evas_object_focus_set(wd->slider, EINA_FALSE);
190 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
192 Widget_Data *wd = elm_widget_data_get(obj);
194 edje_object_mirrored_set(wd->slider, rtl);
198 _theme_hook(Evas_Object *obj)
200 Widget_Data *wd = elm_widget_data_get(obj);
202 _elm_widget_mirrored_reload(obj);
203 _mirrored_set(obj, elm_widget_mirrored_get(obj));
205 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
207 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
208 if (elm_widget_disabled_get(obj))
209 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
211 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
214 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
215 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
218 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
220 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
223 edje_object_part_text_set(wd->slider, "elm.text", wd->label);
224 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
228 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
231 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
233 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
236 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
238 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
241 edje_object_message_signal_process(wd->slider);
242 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
248 _disable_hook(Evas_Object *obj)
250 Widget_Data *wd = elm_widget_data_get(obj);
252 if (elm_widget_disabled_get(obj))
253 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
255 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
259 _sizing_eval(Evas_Object *obj)
261 Widget_Data *wd = elm_widget_data_get(obj);
262 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
264 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
265 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
266 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
267 evas_object_size_hint_min_set(obj, minw, minh);
268 evas_object_size_hint_max_set(obj, maxw, maxh);
272 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
274 Widget_Data *wd = elm_widget_data_get(data);
276 if ((obj != wd->icon) && (obj != wd->end)) return;
281 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
283 Widget_Data *wd = elm_widget_data_get(obj);
284 Evas_Object *sub = event_info;
288 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
289 evas_object_event_callback_del_full
290 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
292 edje_object_message_signal_process(wd->slider);
297 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
298 evas_object_event_callback_del_full(sub,
299 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
300 _changed_size_hints, obj);
302 edje_object_message_signal_process(wd->slider);
308 _delay_change(void *data)
310 Widget_Data *wd = elm_widget_data_get(data);
311 if (!wd) return ECORE_CALLBACK_CANCEL;
313 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
314 return ECORE_CALLBACK_CANCEL;
318 _val_fetch(Evas_Object *obj)
321 Widget_Data *wd = elm_widget_data_get(obj);
322 double posx = 0.0, posy = 0.0, pos = 0.0, val;
324 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
326 if (wd->horizontal) pos = posx;
329 rtl = elm_widget_mirrored_get(obj);
330 if ((!rtl && wd->inverted) || (rtl &&
331 ((!wd->horizontal && wd->inverted) ||
332 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
333 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
337 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
338 if (wd->delay) ecore_timer_del(wd->delay);
339 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
344 _val_set(Evas_Object *obj)
347 Widget_Data *wd = elm_widget_data_get(obj);
350 if (wd->val_max > wd->val_min)
351 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
354 if (pos < 0.0) pos = 0.0;
355 else if (pos > 1.0) pos = 1.0;
357 rtl = elm_widget_mirrored_get(obj);
358 if ((!rtl && wd->inverted) || (rtl &&
359 ((!wd->horizontal && wd->inverted) ||
360 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
361 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
365 _units_set(Evas_Object *obj)
367 Widget_Data *wd = elm_widget_data_get(obj);
373 snprintf(buf, sizeof(buf), wd->units, wd->val);
374 edje_object_part_text_set(wd->slider, "elm.units", buf);
377 edje_object_part_text_set(wd->slider, "elm.units", NULL);
381 _indicator_set(Evas_Object *obj)
383 Widget_Data *wd = elm_widget_data_get(obj);
385 if (wd->indicator_format_func)
388 buf = wd->indicator_format_func(wd->val);
389 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
391 else if (wd->indicator)
394 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
395 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
398 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
402 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
404 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
405 if (elm_widget_disabled_get(data)) return;
406 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
407 edje_object_message_signal_process(wd->slider);
410 _indicator_set(data);
414 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
416 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
417 if (elm_widget_disabled_get(data)) return;
419 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
420 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
421 edje_object_message_signal_process(wd->slider);
423 _indicator_set(data);
424 elm_widget_scroll_freeze_push(data);
428 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
430 if (elm_widget_disabled_get(data)) return;
432 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
434 _indicator_set(data);
435 elm_widget_scroll_freeze_pop(data);
439 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
441 if (elm_widget_disabled_get(data)) return;
444 _indicator_set(data);
448 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
452 if (elm_widget_disabled_get(data)) return;
454 wd = elm_widget_data_get(data);
457 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
459 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
463 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
467 if (elm_widget_disabled_get(data)) return;
469 wd = elm_widget_data_get(data);
472 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
474 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
478 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
480 Widget_Data *wd = elm_widget_data_get(data);
481 Evas_Event_Mouse_Down *ev = event_info;
482 Evas_Coord x, y, w, h;
483 double button_x, button_y;
484 if (elm_widget_disabled_get(data)) return;
486 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
487 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
490 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
491 if (button_x > 1) button_x = 1;
492 if (button_x < 0) button_x = 0;
496 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
497 if (button_y > 1) button_y = 1;
498 if (button_y < 0) button_y = 0;
500 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
501 evas_event_feed_mouse_cancel(e, 0, NULL);
504 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
509 _elm_slider_label_set(Evas_Object *obj, const char *item, const char *label)
511 ELM_CHECK_WIDTYPE(obj, widtype);
512 Widget_Data *wd = elm_widget_data_get(obj);
515 eina_stringshare_replace(&wd->label, label);
518 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
519 edje_object_message_signal_process(wd->slider);
523 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
524 edje_object_message_signal_process(wd->slider);
526 edje_object_part_text_set(wd->slider, "elm.text", label);
531 _elm_slider_label_get(const Evas_Object *obj, const char *item)
533 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
534 Widget_Data *wd = elm_widget_data_get(obj);
535 if (item) return NULL;
536 if (!wd) return NULL;
541 * Add a new slider to the parent
543 * @param parent The parent object
544 * @return The new object or NULL if it cannot be created
549 elm_slider_add(Evas_Object *parent)
555 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
557 ELM_SET_WIDTYPE(widtype, "slider");
558 elm_widget_type_set(obj, "slider");
559 elm_widget_sub_object_add(parent, obj);
560 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
561 elm_widget_data_set(obj, wd);
562 elm_widget_del_hook_set(obj, _del_hook);
563 elm_widget_theme_hook_set(obj, _theme_hook);
564 elm_widget_disable_hook_set(obj, _disable_hook);
565 elm_widget_can_focus_set(obj, EINA_TRUE);
566 elm_widget_event_hook_set(obj, _event_hook);
567 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
568 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
570 wd->horizontal = EINA_TRUE;
571 wd->indicator_show = EINA_TRUE;
577 wd->slider = edje_object_add(e);
578 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
579 elm_widget_resize_object_set(obj, wd->slider);
580 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
581 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
582 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
583 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
584 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
585 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
586 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
588 wd->spacer = evas_object_rectangle_add(e);
589 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
590 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
591 elm_widget_sub_object_add(obj, wd->spacer);
592 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
593 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
594 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
596 _mirrored_set(obj, elm_widget_mirrored_get(obj));
599 // TODO: convert Elementary to subclassing of Evas_Smart_Class
600 // TODO: and save some bytes, making descriptions per-class and not instance!
601 evas_object_smart_callbacks_descriptions_set(obj, _signals);
606 * Set the label of the slider
608 * @param obj The slider object
609 * @param label The text label string in UTF-8
614 elm_slider_label_set(Evas_Object *obj, const char *label)
616 _elm_slider_label_set(obj, NULL, label);
620 * Get the label of the slider
622 * @param obj The slider object
623 * @return The text label string in UTF-8
628 elm_slider_label_get(const Evas_Object *obj)
630 return _elm_slider_label_get(obj, NULL);
634 * Set the icon object (leftmost widget) of the slider object.
636 * Once the icon object is set, a previously set one will be deleted.
637 * If you want to keep that old content object, use the
638 * elm_slider_icon_unset() function.
640 * @param obj The slider object
641 * @param icon The icon object
643 * @note If the object being set does not have minimum size hints set,
644 * it won't get properly displayed.
649 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
651 ELM_CHECK_WIDTYPE(obj, widtype);
652 Widget_Data *wd = elm_widget_data_get(obj);
654 if (wd->icon == icon) return;
655 if (wd->icon) evas_object_del(wd->icon);
659 elm_widget_sub_object_add(obj, icon);
660 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
661 _changed_size_hints, obj);
662 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
663 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
664 edje_object_message_signal_process(wd->slider);
670 * Unset the leftmost widget of the slider, unparenting and
673 * @param obj The slider object
674 * @return the previously set icon sub-object of this slider, on
677 * @see elm_slider_icon_set()
682 elm_slider_icon_unset(Evas_Object *obj)
684 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
685 Widget_Data *wd = elm_widget_data_get(obj);
686 Evas_Object *ret = NULL;
687 if (!wd) return NULL;
690 elm_widget_sub_object_del(obj, wd->icon);
692 edje_object_part_unswallow(wd->slider, wd->icon);
693 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
701 * Get the icon object of the slider object. This object is owned by
702 * the scrolled entry and should not be modified.
704 * @param obj The slider object
705 * @return The icon object
710 elm_slider_icon_get(const Evas_Object *obj)
712 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
713 Widget_Data *wd = elm_widget_data_get(obj);
714 if (!wd) return NULL;
719 * Set the length of the dragable region of the slider
721 * This sets the minimum width or height (depending on orientation) of the
722 * area of the slider that allows the slider to be dragged around. This in
723 * turn affects the objects minimum size (along with icon label and unit
724 * text). Note that this will also get multiplied by the scale factor.
726 * @param obj The slider object
727 * @param size The length of the slider area
732 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
734 ELM_CHECK_WIDTYPE(obj, widtype);
735 Widget_Data *wd = elm_widget_data_get(obj);
737 if (wd->size == size) return;
740 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
742 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
743 if (wd->indicator_show)
744 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
746 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
747 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
752 * Get the length of the dragable region of the slider
754 * This gets the minimum width or height (depending on orientation) of
755 * the area of the slider that allows the slider to be dragged
756 * around. Note that this will also get multiplied by the scale
759 * @param obj The slider object
760 * @return The length of the slider area
765 elm_slider_span_size_get(const Evas_Object *obj)
767 ELM_CHECK_WIDTYPE(obj, widtype) 0;
768 Widget_Data *wd = elm_widget_data_get(obj);
774 * Set the format string of the unit area
776 * If NULL, this disabls the unit area display. If not it sets the format
777 * string for the unit text. The unit text is provided a floating point
778 * value, so the unit text can display up to 1 floating point value. Note that
779 * this is optional. Use a format string such as "%1.2f meters" for example.
781 * @param obj The slider object
782 * @param units The format string for the units display
787 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
789 ELM_CHECK_WIDTYPE(obj, widtype);
790 Widget_Data *wd = elm_widget_data_get(obj);
792 eina_stringshare_replace(&wd->units, units);
795 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
796 edje_object_message_signal_process(wd->slider);
800 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
801 edje_object_message_signal_process(wd->slider);
808 * Get the format string for the unit area
810 * The slider may also display a value (the value of the slider) somewhere
811 * (for example above the slider knob that is dragged around). This sets the
812 * format string for this. See elm_slider_unit_format_set() for more
813 * information on how this works.
815 * @param obj The slider object
816 * @return The format string for the unit display.
821 elm_slider_unit_format_get(const Evas_Object *obj)
823 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
824 Widget_Data *wd = elm_widget_data_get(obj);
825 if (!wd) return NULL;
830 * Set the format string for the indicator area
832 * The slider may also display a value (the value of the slider) somewhere
833 * (for example above the slider knob that is dragged around). This sets the
834 * format string for this. See elm_slider_unit_format_set() for more
835 * information on how this works.
837 * @param obj The slider object
838 * @param indicator The format string for the indicator display
843 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
845 ELM_CHECK_WIDTYPE(obj, widtype);
846 Widget_Data *wd = elm_widget_data_get(obj);
848 eina_stringshare_replace(&wd->indicator, indicator);
853 * Get the format string for the indicator area
855 * The slider may also display a value (the value of the slider) somewhere
856 * (for example above the slider knob that is dragged around). This sets the
857 * format string for this. See elm_slider_indicator_format_set() for more
858 * information on how this works.
860 * @param obj The slider object
861 * @return The format string for the indicator display.
866 elm_slider_indicator_format_get(const Evas_Object *obj)
868 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
869 Widget_Data *wd = elm_widget_data_get(obj);
870 if (!wd) return NULL;
871 return wd->indicator;
875 * Set orientation of the slider
877 * @param obj The slider object
878 * @param horizontal If set, the slider will be horizontal
883 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
885 ELM_CHECK_WIDTYPE(obj, widtype);
886 Widget_Data *wd = elm_widget_data_get(obj);
888 horizontal = !!horizontal;
889 if (wd->horizontal == horizontal) return;
890 wd->horizontal = horizontal;
895 * Get orientation of the slider
897 * @param obj The slider object
898 * @return If @c EINA_TRUE the slider will be horizontal, else it is
903 elm_slider_horizontal_get(const Evas_Object *obj)
905 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
906 Widget_Data *wd = elm_widget_data_get(obj);
907 if (!wd) return EINA_FALSE;
908 return wd->horizontal;
912 * Set the minimum and maximum values for the slider
914 * Maximum mut be greater than minimum.
916 * @param obj The slider object
917 * @param min The minimum value
918 * @param max The maximum value
923 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
925 ELM_CHECK_WIDTYPE(obj, widtype);
926 Widget_Data *wd = elm_widget_data_get(obj);
928 if ((wd->val_min == min) && (wd->val_max == max)) return;
931 if (wd->val < wd->val_min) wd->val = wd->val_min;
932 if (wd->val > wd->val_max) wd->val = wd->val_max;
939 * Get the minimum and maximum values for the slider
941 * @param obj The slider object
942 * @param min The pointer to store minimum value, may be @c NULL.
943 * @param max The pointer to store maximum value, may be @c NULL.
948 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
952 ELM_CHECK_WIDTYPE(obj, widtype);
953 Widget_Data *wd = elm_widget_data_get(obj);
955 if (min) *min = wd->val_min;
956 if (max) *max = wd->val_max;
960 * Set the value the slider indicates
962 * @param obj The slider object
963 * @param val The value (must be between min and max for the slider)
968 elm_slider_value_set(Evas_Object *obj, double val)
970 ELM_CHECK_WIDTYPE(obj, widtype);
971 Widget_Data *wd = elm_widget_data_get(obj);
973 if (wd->val == val) return;
975 if (wd->val < wd->val_min) wd->val = wd->val_min;
976 if (wd->val > wd->val_max) wd->val = wd->val_max;
977 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
984 * Get the value the slider has
986 * @param obj The slider object
987 * @return The value of the slider
992 elm_slider_value_get(const Evas_Object *obj)
994 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
995 Widget_Data *wd = elm_widget_data_get(obj);
1001 * Invert the slider display
1003 * Normally the slider will display and interpret values from low to high
1004 * and when horizontal that is left to right. When vertical that is top
1005 * to bottom. This inverts this (so from right to left or bottom to top) if
1006 * inverted is set to 1.
1008 * @param obj The slider object
1009 * @param inverted The inverted flag. 1 == inverted, 0 == normal
1014 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
1016 ELM_CHECK_WIDTYPE(obj, widtype);
1017 Widget_Data *wd = elm_widget_data_get(obj);
1019 inverted = !!inverted;
1020 if (wd->inverted == inverted) return;
1021 wd->inverted = inverted;
1023 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1025 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1026 edje_object_message_signal_process(wd->slider);
1029 _indicator_set(obj);
1033 * Get if the slider display is inverted (backwards)
1035 * @param obj The slider object
1036 * @return If @c EINA_TRUE the slider will be inverted.
1040 elm_slider_inverted_get(const Evas_Object *obj)
1042 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1043 Widget_Data *wd = elm_widget_data_get(obj);
1044 if (!wd) return EINA_FALSE;
1045 return wd->inverted;
1049 * Set the format function pointer for the indicator area
1051 * Set the callback function to format the indicator string.
1052 * See elm_slider_indicator_format_set() for more info on how this works.
1054 * @param obj The slider object
1055 * @param indicator The format string for the indicator display
1056 * @param func The indicator format function
1061 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val))
1063 ELM_CHECK_WIDTYPE(obj, widtype);
1064 Widget_Data *wd = elm_widget_data_get(obj);
1066 wd->indicator_format_func = func;
1067 _indicator_set(obj);
1071 * Set the end object (rightmost widget) of the slider object.
1073 * Once the end object is set, a previously set one will be deleted.
1074 * If you want to keep that old content object, use the
1075 * elm_button_end_unset() function.
1077 * @param obj The slider object
1078 * @param end The end object
1080 * @note If the object being set does not have minimum size hints set,
1081 * it won't get properly displayed.
1086 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
1088 ELM_CHECK_WIDTYPE(obj, widtype);
1089 Widget_Data *wd = elm_widget_data_get(obj);
1091 if (wd->end == end) return;
1092 if (wd->end) evas_object_del(wd->end);
1096 elm_widget_sub_object_add(obj, end);
1097 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1098 _changed_size_hints, obj);
1099 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
1100 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
1101 edje_object_message_signal_process(wd->slider);
1107 * Unset the rightmost widget of the slider, unparenting and
1110 * @param obj The slider object
1111 * @return the previously set end sub-object of this slider, on
1114 * @see elm_slider_end_set()
1119 elm_slider_end_unset(Evas_Object *obj)
1121 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1122 Widget_Data *wd = elm_widget_data_get(obj);
1123 Evas_Object *ret = NULL;
1124 if (!wd) return NULL;
1127 elm_widget_sub_object_del(obj, wd->end);
1129 edje_object_part_unswallow(wd->slider, wd->end);
1130 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
1138 * Get the end icon object of the slider object. This object is owned
1139 * by the scrolled entry and should not be modified.
1141 * @param obj The slider object
1142 * @return The end icon object
1147 elm_slider_end_get(const Evas_Object *obj)
1149 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1150 Widget_Data *wd = elm_widget_data_get(obj);
1151 if (!wd) return NULL;
1156 * Set whether to the slider indicator (augmented knob) at all.
1158 * @param obj The slider object
1159 * @param show @c EINA_TRUE will make it show it, @c EINA_FALSE will
1160 * let the knob alwayes at default size.
1162 * @note It will conflict with elm_slider_indicator_format_set(), if
1163 * you wanted those effects.
1168 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1170 ELM_CHECK_WIDTYPE(obj, widtype);
1171 Widget_Data *wd = elm_widget_data_get(obj);
1173 wd->indicator_show = EINA_TRUE;
1174 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1177 wd->indicator_show = EINA_FALSE;
1178 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1183 * Get the state of indicator in the slider (if it's being shown or
1186 * @param obj The slider object
1187 * @return @c EINA_TRUE if the indicator is being shown, @c EINA_FALSE
1193 elm_slider_indicator_show_get(const Evas_Object *obj)
1195 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1196 Widget_Data *wd = elm_widget_data_get(obj);
1197 if (!wd) return EINA_FALSE;
1198 return wd->indicator_show;