1 #include <Elementary.h>
5 * @defgroup Slider Slider
7 * The slider adds a dragable “slider” widget for selecting the value of
8 * something within a range.
11 * A slider can be horizontal or vertical. It can contain an Icon and has a
12 * primary label as well as a units label (that is formatted with floating
13 * point values and thus accepts a printf-style format string, like
14 * “%1.2f units”. There is also an indicator string that may be somewhere
15 * else (like on the slider itself) that also accepts a format string like
16 * units. Label, Icon Unit and Indicator strings/objects are optional.
18 * A slider may be inverted which means values invert, with high vales being
19 * on the left or top and low values on the right or bottom (as opposed to
20 * normally being low on the left or top and high on the bottom and right).
22 * The slider should have its minimum and maximum values set by the
23 * application with elm_slider_min_max_set() and value should also be set by
24 * the application before use with elm_slider_value_set(). The span of the
25 * slider is its length (horizontally or vertically). This will be scaled by
26 * the object or applications scaling factor. At any point code can query the
27 * slider for its value with elm_slider_value_get().
29 * Signals that you can add callbacks for are:
31 * "changed" - Whenever the slider value is changed by the user.
32 * "slider,drag,start" - dragging the slider indicator around has started
33 * "slider,drag,stop" - dragging the slider indicator around has stopped
34 * "delay,changed" - A short time after the value is changed by the user.
35 * This will be called only when the user stops dragging for a very short
36 * period or when they release their finger/mouse, so it avoids possibly
37 * expensive reactions to the value change.
40 typedef struct _Widget_Data Widget_Data;
50 const char *indicator;
51 const char *(*indicator_format_func)(double val);
52 Eina_Bool horizontal : 1;
53 Eina_Bool inverted : 1;
54 Eina_Bool indicator_show : 1;
55 double val, val_min, val_max;
60 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
62 static const char *widtype = NULL;
63 static void _del_hook(Evas_Object *obj);
64 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
65 static void _theme_hook(Evas_Object *obj);
66 static void _disable_hook(Evas_Object *obj);
67 static void _sizing_eval(Evas_Object *obj);
68 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
69 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
70 static void _units_set(Evas_Object *obj);
71 static void _val_set(Evas_Object *obj);
72 static void _indicator_set(Evas_Object *obj);
73 static void _on_focus_hook(void *data, Evas_Object *obj);
74 static void _drag_up(void *data, Evas_Object *obj,
75 const char *emission, const char *source);
76 static void _drag_down(void *data, Evas_Object *obj,
77 const char *emission, const char *source);
78 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
79 Evas_Callback_Type type, void *event_info);
80 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
82 static const char SIG_CHANGED[] = "changed";
83 static const char SIG_DELAY_CHANGED[] = "delay,changed";
84 static const char SIG_DRAG_START[] = "slider,drag,start";
85 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
86 static const Evas_Smart_Cb_Description _signals[] = {
88 {SIG_DELAY_CHANGED, ""},
95 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
97 Evas_Event_Mouse_Wheel *mev;
98 Evas_Event_Key_Down *ev;
101 wd = elm_widget_data_get(obj);
102 if (!wd) return EINA_FALSE;
104 if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
105 else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
108 if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
109 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
111 if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
112 else _drag_down(obj, NULL, NULL, NULL);
113 mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
118 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
119 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
120 if ((!strcmp(ev->keyname, "Left"))
121 || (!strcmp(ev->keyname, "KP_Left")))
123 if (!wd->horizontal) return EINA_FALSE;
124 if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
125 else _drag_up(obj, NULL, NULL, NULL);
126 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
129 else if ((!strcmp(ev->keyname, "Right"))
130 || (!strcmp(ev->keyname, "KP_Right")))
132 if (!wd->horizontal) return EINA_FALSE;
133 if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
134 else _drag_down(obj, NULL, NULL, NULL);
135 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
138 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
140 if (wd->horizontal) return EINA_FALSE;
141 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
142 else _drag_down(obj, NULL, NULL, NULL);
143 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
146 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
148 if (wd->horizontal) return EINA_FALSE;
149 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
150 else _drag_up(obj, NULL, NULL, NULL);
151 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
154 else return EINA_FALSE;
158 _del_hook(Evas_Object *obj)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 if (wd->label) eina_stringshare_del(wd->label);
163 if (wd->indicator) eina_stringshare_del(wd->units);
164 if (wd->delay) ecore_timer_del(wd->delay);
169 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
171 Widget_Data *wd = elm_widget_data_get(obj);
173 if (elm_widget_focus_get(obj))
175 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
176 evas_object_focus_set(wd->slider, EINA_TRUE);
180 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
181 evas_object_focus_set(wd->slider, EINA_FALSE);
186 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
188 Widget_Data *wd = elm_widget_data_get(obj);
190 edje_object_mirrored_set(wd->slider, rtl);
194 _theme_hook(Evas_Object *obj)
196 Widget_Data *wd = elm_widget_data_get(obj);
198 _elm_widget_mirrored_reload(obj);
199 _mirrored_set(obj, elm_widget_mirrored_get(obj));
201 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
203 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
206 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
207 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
210 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
212 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
215 edje_object_part_text_set(wd->slider, "elm.text", wd->label);
216 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
220 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
223 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
225 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
228 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
230 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
233 edje_object_message_signal_process(wd->slider);
234 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
240 _disable_hook(Evas_Object *obj)
242 Widget_Data *wd = elm_widget_data_get(obj);
244 if (elm_widget_disabled_get(obj))
245 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
247 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
251 _sizing_eval(Evas_Object *obj)
253 Widget_Data *wd = elm_widget_data_get(obj);
254 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
256 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
257 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
258 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
259 evas_object_size_hint_min_set(obj, minw, minh);
260 evas_object_size_hint_max_set(obj, maxw, maxh);
264 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
266 Widget_Data *wd = elm_widget_data_get(data);
268 if ((obj != wd->icon) && (obj != wd->end)) return;
273 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
275 Widget_Data *wd = elm_widget_data_get(obj);
276 Evas_Object *sub = event_info;
280 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
281 evas_object_event_callback_del_full
282 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
284 edje_object_message_signal_process(wd->slider);
289 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
290 evas_object_event_callback_del_full(sub,
291 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
292 _changed_size_hints, obj);
294 edje_object_message_signal_process(wd->slider);
300 _delay_change(void *data)
302 Widget_Data *wd = elm_widget_data_get(data);
303 if (!wd) return ECORE_CALLBACK_CANCEL;
305 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
306 return ECORE_CALLBACK_CANCEL;
310 _val_fetch(Evas_Object *obj)
313 Widget_Data *wd = elm_widget_data_get(obj);
314 double posx = 0.0, posy = 0.0, pos = 0.0, val;
316 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
318 if (wd->horizontal) pos = posx;
321 rtl = elm_widget_mirrored_get(obj);
322 if ((!rtl && wd->inverted) || (rtl &&
323 ((!wd->horizontal && wd->inverted) ||
324 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
325 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
329 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
330 if (wd->delay) ecore_timer_del(wd->delay);
331 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
336 _val_set(Evas_Object *obj)
339 Widget_Data *wd = elm_widget_data_get(obj);
342 if (wd->val_max > wd->val_min)
343 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
346 if (pos < 0.0) pos = 0.0;
347 else if (pos > 1.0) pos = 1.0;
349 rtl = elm_widget_mirrored_get(obj);
350 if ((!rtl && wd->inverted) || (rtl &&
351 ((!wd->horizontal && wd->inverted) ||
352 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
353 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
357 _units_set(Evas_Object *obj)
359 Widget_Data *wd = elm_widget_data_get(obj);
365 snprintf(buf, sizeof(buf), wd->units, wd->val);
366 edje_object_part_text_set(wd->slider, "elm.units", buf);
369 edje_object_part_text_set(wd->slider, "elm.units", NULL);
373 _indicator_set(Evas_Object *obj)
375 Widget_Data *wd = elm_widget_data_get(obj);
377 if (wd->indicator_format_func)
380 buf = wd->indicator_format_func(wd->val);
381 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
383 else if (wd->indicator)
386 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
387 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
390 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
394 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
398 _indicator_set(data);
402 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
405 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
407 _indicator_set(data);
408 elm_widget_scroll_freeze_push(data);
412 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
415 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
417 _indicator_set(data);
418 elm_widget_scroll_freeze_pop(data);
422 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
426 _indicator_set(data);
430 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
435 wd = elm_widget_data_get(data);
438 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
440 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
444 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
449 wd = elm_widget_data_get(data);
452 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
454 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
458 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
460 Widget_Data *wd = elm_widget_data_get(data);
461 Evas_Event_Mouse_Down *ev = event_info;
462 Evas_Coord x, y, w, h;
463 double button_x, button_y;
465 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
466 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
469 button_x = ((double)ev->output.x - (double)x) / (double)w;
470 if (button_x > 1) button_x = 1;
471 if (button_x < 0) button_x = 0;
475 button_y = ((double)ev->output.y - (double)y) / (double)h;
476 if (button_y > 1) button_y = 1;
477 if (button_y < 0) button_y = 0;
479 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
480 evas_event_feed_mouse_cancel(e, 0, NULL);
481 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
485 * Add a new slider to the parent
487 * @param parent The parent object
488 * @return The new object or NULL if it cannot be created
493 elm_slider_add(Evas_Object *parent)
499 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
501 ELM_SET_WIDTYPE(widtype, "slider");
502 elm_widget_type_set(obj, "slider");
503 elm_widget_sub_object_add(parent, obj);
504 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
505 elm_widget_data_set(obj, wd);
506 elm_widget_del_hook_set(obj, _del_hook);
507 elm_widget_theme_hook_set(obj, _theme_hook);
508 elm_widget_disable_hook_set(obj, _disable_hook);
509 elm_widget_can_focus_set(obj, EINA_TRUE);
510 elm_widget_event_hook_set(obj, _event_hook);
512 wd->horizontal = EINA_TRUE;
513 wd->indicator_show = EINA_TRUE;
518 wd->slider = edje_object_add(e);
519 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
520 elm_widget_resize_object_set(obj, wd->slider);
521 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
522 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
523 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
524 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
525 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
526 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
527 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
529 wd->spacer = evas_object_rectangle_add(e);
530 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
531 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
532 elm_widget_sub_object_add(obj, wd->spacer);
533 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
534 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
535 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
537 _mirrored_set(obj, elm_widget_mirrored_get(obj));
540 // TODO: convert Elementary to subclassing of Evas_Smart_Class
541 // TODO: and save some bytes, making descriptions per-class and not instance!
542 evas_object_smart_callbacks_descriptions_set(obj, _signals);
547 * Set the label of the slider
549 * @param obj The slider object
550 * @param label The text label string in UTF-8
555 elm_slider_label_set(Evas_Object *obj, const char *label)
557 ELM_CHECK_WIDTYPE(obj, widtype);
558 Widget_Data *wd = elm_widget_data_get(obj);
560 eina_stringshare_replace(&wd->label, label);
563 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
564 edje_object_message_signal_process(wd->slider);
568 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
569 edje_object_message_signal_process(wd->slider);
571 edje_object_part_text_set(wd->slider, "elm.text", label);
576 * Get the label of the slider
578 * @param obj The slider object
579 * @return The text label string in UTF-8
584 elm_slider_label_get(const Evas_Object *obj)
586 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
587 Widget_Data *wd = elm_widget_data_get(obj);
588 if (!wd) return NULL;
593 * Set the icon object (leftmost widget) of the slider object.
595 * Once the icon object is set, a previously set one will be deleted.
596 * If you want to keep that old content object, use the
597 * elm_slider_icon_unset() function.
599 * @param obj The slider object
600 * @param icon The icon object
602 * @note If the object being set does not have minimum size hints set,
603 * it won't get properly displayed.
608 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
610 ELM_CHECK_WIDTYPE(obj, widtype);
611 Widget_Data *wd = elm_widget_data_get(obj);
613 if (wd->icon == icon) return;
614 if (wd->icon) evas_object_del(wd->icon);
618 elm_widget_sub_object_add(obj, icon);
619 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
620 _changed_size_hints, obj);
621 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
622 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
623 edje_object_message_signal_process(wd->slider);
629 * Unset the leftmost widget of the slider, unparenting and
632 * @param obj The slider object
633 * @return the previously set icon sub-object of this slider, on
636 * @see elm_slider_icon_set()
641 elm_slider_icon_unset(Evas_Object *obj)
643 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
644 Widget_Data *wd = elm_widget_data_get(obj);
645 Evas_Object *ret = NULL;
646 if (!wd) return NULL;
649 elm_widget_sub_object_del(obj, wd->icon);
651 edje_object_part_unswallow(wd->slider, wd->icon);
652 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
660 * Get the icon object of the slider object. This object is owned by
661 * the scrolled entry and should not be modified.
663 * @param obj The slider object
664 * @return The icon object
669 elm_slider_icon_get(const Evas_Object *obj)
671 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
672 Widget_Data *wd = elm_widget_data_get(obj);
673 if (!wd) return NULL;
678 * Set the length of the dragable region of the slider
680 * This sets the minimum width or height (depending on orientation) of the
681 * area of the slider that allows the slider to be dragged around. This in
682 * turn affects the objects minimum size (along with icon label and unit
683 * text). Note that this will also get multiplied by the scale factor.
685 * @param obj The slider object
686 * @param size The length of the slider area
691 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
693 ELM_CHECK_WIDTYPE(obj, widtype);
694 Widget_Data *wd = elm_widget_data_get(obj);
696 if (wd->size == size) return;
699 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
701 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
702 if (wd->indicator_show)
703 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
705 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
706 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
711 * Get the length of the dragable region of the slider
713 * This gets the minimum width or height (depending on orientation) of
714 * the area of the slider that allows the slider to be dragged
715 * around. Note that this will also get multiplied by the scale
718 * @param obj The slider object
719 * @return The length of the slider area
724 elm_slider_span_size_get(const Evas_Object *obj)
726 ELM_CHECK_WIDTYPE(obj, widtype) 0;
727 Widget_Data *wd = elm_widget_data_get(obj);
733 * Set the format string of the unit area
735 * If NULL, this disabls the unit area display. If not it sets the format
736 * string for the unit text. The unit text is provided a floating point
737 * value, so the unit text can display up to 1 floating point value. Note that
738 * this is optional. Use a format string such as "%1.2f meters" for example.
740 * @param obj The slider object
741 * @param units The format string for the units display
746 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
748 ELM_CHECK_WIDTYPE(obj, widtype);
749 Widget_Data *wd = elm_widget_data_get(obj);
751 eina_stringshare_replace(&wd->units, units);
754 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
755 edje_object_message_signal_process(wd->slider);
759 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
760 edje_object_message_signal_process(wd->slider);
767 * Get the format string for the unit area
769 * The slider may also display a value (the value of the slider) somewhere
770 * (for example above the slider knob that is dragged around). This sets the
771 * format string for this. See elm_slider_unit_format_set() for more
772 * information on how this works.
774 * @param obj The slider object
775 * @return The format string for the unit display.
780 elm_slider_unit_format_get(const Evas_Object *obj)
782 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
783 Widget_Data *wd = elm_widget_data_get(obj);
784 if (!wd) return NULL;
789 * Set the format string for the indicator area
791 * The slider may also display a value (the value of the slider) somewhere
792 * (for example above the slider knob that is dragged around). This sets the
793 * format string for this. See elm_slider_unit_format_set() for more
794 * information on how this works.
796 * @param obj The slider object
797 * @param indicator The format string for the indicator display
802 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
804 ELM_CHECK_WIDTYPE(obj, widtype);
805 Widget_Data *wd = elm_widget_data_get(obj);
807 eina_stringshare_replace(&wd->indicator, indicator);
812 * Get the format string for the indicator area
814 * The slider may also display a value (the value of the slider) somewhere
815 * (for example above the slider knob that is dragged around). This sets the
816 * format string for this. See elm_slider_indicator_format_set() for more
817 * information on how this works.
819 * @param obj The slider object
820 * @return The format string for the indicator display.
825 elm_slider_indicator_format_get(const Evas_Object *obj)
827 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
828 Widget_Data *wd = elm_widget_data_get(obj);
829 if (!wd) return NULL;
830 return wd->indicator;
834 * Set orientation of the slider
836 * @param obj The slider object
837 * @param horizontal If set, the slider will be horizontal
842 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
844 ELM_CHECK_WIDTYPE(obj, widtype);
845 Widget_Data *wd = elm_widget_data_get(obj);
847 horizontal = !!horizontal;
848 if (wd->horizontal == horizontal) return;
849 wd->horizontal = horizontal;
854 * Get orientation of the slider
856 * @param obj The slider object
857 * @return If @c EINA_TRUE the slider will be horizontal, else it is
862 elm_slider_horizontal_get(const Evas_Object *obj)
864 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
865 Widget_Data *wd = elm_widget_data_get(obj);
866 if (!wd) return EINA_FALSE;
867 return wd->horizontal;
871 * Set the minimum and maximum values for the slider
873 * Maximum mut be greater than minimum.
875 * @param obj The slider object
876 * @param min The minimum value
877 * @param max The maximum value
882 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
884 ELM_CHECK_WIDTYPE(obj, widtype);
885 Widget_Data *wd = elm_widget_data_get(obj);
887 if ((wd->val_min == min) && (wd->val_max == max)) return;
890 if (wd->val < wd->val_min) wd->val = wd->val_min;
891 if (wd->val > wd->val_max) wd->val = wd->val_max;
898 * Get the minimum and maximum values for the slider
900 * @param obj The slider object
901 * @param min The pointer to store minimum value, may be @c NULL.
902 * @param max The pointer to store maximum value, may be @c NULL.
907 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
911 ELM_CHECK_WIDTYPE(obj, widtype);
912 Widget_Data *wd = elm_widget_data_get(obj);
914 if (min) *min = wd->val_min;
915 if (max) *max = wd->val_max;
919 * Set the value the slider indicates
921 * @param obj The slider object
922 * @param val The value (must be between min and max for the slider)
927 elm_slider_value_set(Evas_Object *obj, double val)
929 ELM_CHECK_WIDTYPE(obj, widtype);
930 Widget_Data *wd = elm_widget_data_get(obj);
932 if (wd->val == val) return;
934 if (wd->val < wd->val_min) wd->val = wd->val_min;
935 if (wd->val > wd->val_max) wd->val = wd->val_max;
942 * Get the value the slider has
944 * @param obj The slider object
945 * @return The value of the slider
950 elm_slider_value_get(const Evas_Object *obj)
952 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
953 Widget_Data *wd = elm_widget_data_get(obj);
959 * Invert the slider display
961 * Normally the slider will display and interpret values from low to high
962 * and when horizontal that is left to right. When vertical that is top
963 * to bottom. This inverts this (so from right to left or bottom to top) if
964 * inverted is set to 1.
966 * @param obj The slider object
967 * @param inverted The inverted flag. 1 == inverted, 0 == normal
972 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
974 ELM_CHECK_WIDTYPE(obj, widtype);
975 Widget_Data *wd = elm_widget_data_get(obj);
977 inverted = !!inverted;
978 if (wd->inverted == inverted) return;
979 wd->inverted = inverted;
981 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
983 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
984 edje_object_message_signal_process(wd->slider);
991 * Get if the slider display is inverted (backwards)
993 * @param obj The slider object
994 * @return If @c EINA_TRUE the slider will be inverted.
998 elm_slider_inverted_get(const Evas_Object *obj)
1000 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1001 Widget_Data *wd = elm_widget_data_get(obj);
1002 if (!wd) return EINA_FALSE;
1003 return wd->inverted;
1007 * Set the format function pointer for the inducator area
1009 * Set the callback function to format the indicator string.
1010 * See elm_slider_indicator_format_set() for more info on how this works.
1012 * @param obj The slider object
1013 * @param indicator The format string for the indicator display
1014 * @param func The indicator format function
1019 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val))
1021 ELM_CHECK_WIDTYPE(obj, widtype);
1022 Widget_Data *wd = elm_widget_data_get(obj);
1024 wd->indicator_format_func = func;
1025 _indicator_set(obj);
1029 * Set the end object (rightmost widget) of the slider object.
1031 * Once the end object is set, a previously set one will be deleted.
1032 * If you want to keep that old content object, use the
1033 * elm_button_end_unset() function.
1035 * @param obj The slider object
1036 * @param end The end object
1038 * @note If the object being set does not have minimum size hints set,
1039 * it won't get properly displayed.
1044 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
1046 ELM_CHECK_WIDTYPE(obj, widtype);
1047 Widget_Data *wd = elm_widget_data_get(obj);
1049 if (wd->end == end) return;
1050 if (wd->end) evas_object_del(wd->end);
1054 elm_widget_sub_object_add(obj, end);
1055 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1056 _changed_size_hints, obj);
1057 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
1058 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
1059 edje_object_message_signal_process(wd->slider);
1065 * Unset the rightmost widget of the slider, unparenting and
1068 * @param obj The slider object
1069 * @return the previously set end sub-object of this slider, on
1072 * @see elm_slider_end_set()
1077 elm_slider_end_unset(Evas_Object *obj)
1079 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1080 Widget_Data *wd = elm_widget_data_get(obj);
1081 Evas_Object *ret = NULL;
1082 if (!wd) return NULL;
1085 elm_widget_sub_object_del(obj, wd->end);
1087 edje_object_part_unswallow(wd->slider, wd->end);
1088 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
1096 * Get the end icon object of the slider object. This object is owned
1097 * by the scrolled entry and should not be modified.
1099 * @param obj The slider object
1100 * @return The end icon object
1105 elm_slider_end_get(const Evas_Object *obj)
1107 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1108 Widget_Data *wd = elm_widget_data_get(obj);
1109 if (!wd) return NULL;
1114 * Set whether to the slider indicator (augmented knob) at all.
1116 * @param obj The slider object
1117 * @param show @c EINA_TRUE will make it show it, @c EINA_FALSE will
1118 * let the knob alwayes at default size.
1120 * @note It will conflict with elm_slider_indicator_format_set(), if
1121 * you wanted those effects.
1126 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1128 ELM_CHECK_WIDTYPE(obj, widtype);
1129 Widget_Data *wd = elm_widget_data_get(obj);
1131 wd->indicator_show = EINA_TRUE;
1132 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1135 wd->indicator_show = EINA_FALSE;
1136 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1141 * Get the state of indicator in the slider (if it's being shown or
1144 * @param obj The slider object
1145 * @return @c EINA_TRUE if the indicator is being shown, @c EINA_FALSE
1151 elm_slider_indicator_show_get(const Evas_Object *obj)
1153 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1154 Widget_Data *wd = elm_widget_data_get(obj);
1155 if (!wd) return EINA_FALSE;
1156 return wd->indicator_show;