1 #include <Elementary.h>
5 typedef struct _Widget_Data Widget_Data;
9 Evas_Object *as; // actionslider
10 Evas_Object *drag_button_base;
11 Elm_Actionslider_Pos magnet_position, enabled_position;
12 const char *text_left, *text_right, *text_center;
13 const char *indicator_label;
14 Ecore_Animator *button_animator;
15 double final_position;
16 Eina_Bool mouse_down : 1;
19 static const char *widtype = NULL;
21 static const char SIG_CHANGED[] = "pos_changed";
22 static const char SIG_SELECTED[] = "selected";
24 static const Evas_Smart_Cb_Description _signals[] =
33 _del_hook(Evas_Object *obj)
35 Widget_Data *wd = elm_widget_data_get(obj);
37 if (wd->drag_button_base)
39 evas_object_del(wd->drag_button_base);
40 wd->drag_button_base = NULL;
42 if (wd->text_left) eina_stringshare_del(wd->text_left);
43 if (wd->text_right) eina_stringshare_del(wd->text_right);
44 if (wd->text_center) eina_stringshare_del(wd->text_center);
45 if (wd->indicator_label) eina_stringshare_del(wd->indicator_label);
49 static Elm_Actionslider_Pos
50 _get_pos_by_orientation(const Evas_Object *obj, Elm_Actionslider_Pos pos)
52 if (elm_widget_mirrored_get(obj))
56 case ELM_ACTIONSLIDER_LEFT:
57 pos = ELM_ACTIONSLIDER_RIGHT;
59 case ELM_ACTIONSLIDER_RIGHT:
60 pos = ELM_ACTIONSLIDER_LEFT;
70 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
72 Widget_Data *wd = elm_widget_data_get(obj);
76 if (edje_object_mirrored_get(wd->as) == rtl)
79 edje_object_mirrored_set(wd->as, rtl);
80 if (!elm_widget_mirrored_get(obj))
82 edje_object_part_text_set(wd->as, "elm.text.left", wd->text_left);
83 edje_object_part_text_set(wd->as, "elm.text.right", wd->text_right);
87 edje_object_part_text_set(wd->as, "elm.text.left", wd->text_right);
88 edje_object_part_text_set(wd->as, "elm.text.right", wd->text_left);
90 edje_object_part_drag_value_get(wd->as, "elm.drag_button_base", &pos, NULL);
91 edje_object_part_drag_value_set(wd->as, "elm.drag_button_base", 1.0 - pos, 0.5);
95 _sizing_eval(Evas_Object *obj)
97 Widget_Data *wd = elm_widget_data_get(obj);
98 Evas_Coord minw = -1, minh = -1;
101 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
102 evas_object_size_hint_min_set(wd->drag_button_base, minw, minh);
103 evas_object_size_hint_max_set(wd->drag_button_base, -1, -1);
107 elm_coords_finger_size_adjust(3, &minw, 1, &minh);
108 edje_object_size_min_restricted_calc(wd->as, &minw, &minh, minw, minh);
109 evas_object_size_hint_min_set(obj, minw, minh);
110 evas_object_size_hint_max_set(obj, -1, -1);
114 _theme_hook(Evas_Object *obj)
116 Widget_Data *wd = elm_widget_data_get(obj);
118 _elm_widget_mirrored_reload(obj);
119 if (!edje_object_part_swallow_get(wd->as, "elm.drag_button_base"))
120 edje_object_part_unswallow(wd->as, wd->drag_button_base);
122 _elm_theme_object_set(obj, wd->as, "actionslider",
123 "base", elm_widget_style_get(obj));
124 _elm_theme_object_set(obj, wd->drag_button_base, "actionslider",
125 "drag_button", elm_widget_style_get(obj));
126 edje_object_part_swallow(wd->as, "elm.drag_button_base", wd->drag_button_base);
128 _mirrored_set(obj, elm_widget_mirrored_get(obj));
129 edje_object_part_text_set(wd->as, "elm.text.center", wd->text_center);
130 edje_object_part_text_set(wd->as, "elm.text.indicator", wd->indicator_label);
131 edje_object_message_signal_process(wd->as);
136 _drag_button_down_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
138 Widget_Data *wd = elm_widget_data_get((Evas_Object *) data);
140 wd->mouse_down = EINA_TRUE;
144 _drag_button_move_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
146 Evas_Object *obj = (Evas_Object *) data;
147 Widget_Data *wd = elm_widget_data_get(obj);
151 if (!wd->mouse_down) return;
152 edje_object_part_drag_value_get(wd->as, "elm.drag_button_base", &pos, NULL);
154 evas_object_smart_callback_call(obj, SIG_CHANGED,
155 (void *) ((!elm_widget_mirrored_get(obj)) ?
158 evas_object_smart_callback_call(obj, SIG_CHANGED,
159 (void *) ((!elm_widget_mirrored_get(obj)) ?
161 else if (pos >= 0.45 && pos <= 0.55)
162 evas_object_smart_callback_call(obj, SIG_CHANGED, (void *)"center");
166 _button_animation(void *data)
168 Evas_Object *obj = data;
169 Widget_Data *wd = elm_widget_data_get(obj);
170 double cur_position = 0.0, new_position = 0.0;
171 double move_amount = 0.05;
172 Eina_Bool flag_finish_animation = EINA_FALSE;
175 wd->button_animator = NULL;
176 return ECORE_CALLBACK_CANCEL;
179 edje_object_part_drag_value_get(wd->as,
180 "elm.drag_button_base", &cur_position, NULL);
182 double adjusted_final;
183 adjusted_final = (!elm_widget_mirrored_get(obj)) ?
184 wd->final_position : 1.0 - wd->final_position;
185 if ((adjusted_final == 0.0) ||
186 (adjusted_final == 0.5 && cur_position >= adjusted_final))
188 new_position = cur_position - move_amount;
189 if (new_position <= adjusted_final)
191 new_position = adjusted_final;
192 flag_finish_animation = EINA_TRUE;
195 else if ((adjusted_final == 1.0) ||
196 (adjusted_final == 0.5 && cur_position < adjusted_final))
198 new_position = cur_position + move_amount;
199 if (new_position >= adjusted_final)
201 new_position = adjusted_final;
202 flag_finish_animation = EINA_TRUE;
205 edje_object_part_drag_value_set(wd->as,
206 "elm.drag_button_base", new_position, 0.5);
209 if (flag_finish_animation)
211 if ((!wd->final_position) &&
212 (wd->enabled_position & ELM_ACTIONSLIDER_LEFT))
213 evas_object_smart_callback_call(data, SIG_SELECTED,
214 (void *)wd->text_left);
215 else if ((wd->final_position == 0.5) &&
216 (wd->enabled_position & ELM_ACTIONSLIDER_CENTER))
217 evas_object_smart_callback_call(data, SIG_SELECTED,
218 (void *)wd->text_center);
219 else if ((wd->final_position == 1) &&
220 (wd->enabled_position & ELM_ACTIONSLIDER_RIGHT))
221 evas_object_smart_callback_call(data, SIG_SELECTED,
222 (void *)wd->text_right);
223 wd->button_animator = NULL;
224 return ECORE_CALLBACK_CANCEL;
226 return ECORE_CALLBACK_RENEW;
230 _drag_button_up_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
232 Evas_Object *obj = (Evas_Object *) data;
233 Widget_Data *wd = elm_widget_data_get(obj);
234 double position = 0.0;
237 wd->mouse_down = EINA_FALSE;
239 edje_object_part_drag_value_get(wd->as, "elm.drag_button_base",
242 if ((wd->enabled_position & ELM_ACTIONSLIDER_LEFT) &&
243 ((!elm_widget_mirrored_get(obj) && position == 0.0) ||
244 (elm_widget_mirrored_get(obj) && position == 1.0)))
246 wd->final_position = 0;
247 evas_object_smart_callback_call(data, SIG_SELECTED,
248 (void *) wd->text_left);
251 if (position >= 0.45 && position <= 0.55 &&
252 (wd->enabled_position & ELM_ACTIONSLIDER_CENTER))
254 wd->final_position = 0.5;
255 evas_object_smart_callback_call(data, SIG_SELECTED,
256 (void *)wd->text_center);
257 if (wd->button_animator) ecore_animator_del(wd->button_animator);
258 wd->button_animator = ecore_animator_add(_button_animation, data);
261 if ((wd->enabled_position & ELM_ACTIONSLIDER_RIGHT) &&
262 ((!elm_widget_mirrored_get(obj) && position == 1.0) ||
263 (elm_widget_mirrored_get(obj) && position == 0.0)))
265 wd->final_position = 1;
266 evas_object_smart_callback_call(data, SIG_SELECTED,
267 (void *) wd->text_right);
271 if (wd->magnet_position == ELM_ACTIONSLIDER_NONE) return;
273 #define _FINAL_POS_BY_ORIENTATION(x) (x)
274 #define _POS_BY_ORIENTATION(x) \
275 ((!elm_widget_mirrored_get(obj)) ? \
278 position = _POS_BY_ORIENTATION(position);
282 if (wd->magnet_position & ELM_ACTIONSLIDER_LEFT)
283 wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
284 else if (wd->magnet_position & ELM_ACTIONSLIDER_CENTER)
285 wd->final_position = 0.5;
286 else if (wd->magnet_position & ELM_ACTIONSLIDER_RIGHT)
287 wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
289 else if ((position >= 0.3) && (position <= 0.7))
291 if (wd->magnet_position & ELM_ACTIONSLIDER_CENTER)
292 wd->final_position = 0.5;
293 else if (position < 0.5)
295 if (wd->magnet_position & ELM_ACTIONSLIDER_LEFT)
296 wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
298 wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
302 if (wd->magnet_position & ELM_ACTIONSLIDER_RIGHT)
303 wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
305 wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
310 if (wd->magnet_position & ELM_ACTIONSLIDER_RIGHT)
311 wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
312 else if (wd->magnet_position & ELM_ACTIONSLIDER_CENTER)
313 wd->final_position = 0.5;
315 wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
317 if (wd->button_animator) ecore_animator_del(wd->button_animator);
318 wd->button_animator = ecore_animator_add(_button_animation, data);
320 #undef _FINAL_POS_BY_ORIENTATION
324 elm_actionslider_add(Evas_Object *parent)
330 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
332 ELM_SET_WIDTYPE(widtype, "actionslider");
333 elm_widget_type_set(obj, "actionslider");
334 elm_widget_sub_object_add(parent, obj);
335 elm_widget_data_set(obj, wd);
336 elm_widget_del_hook_set(obj, _del_hook);
337 elm_widget_theme_hook_set(obj, _theme_hook);
339 wd->mouse_down = EINA_FALSE;
340 wd->enabled_position = ELM_ACTIONSLIDER_ALL;
342 wd->as = edje_object_add(e);
343 _elm_theme_object_set(obj, wd->as, "actionslider", "base", "default");
344 elm_widget_resize_object_set(obj, wd->as);
346 wd->drag_button_base = evas_object_rectangle_add(e);
347 evas_object_color_set(wd->drag_button_base, 0, 0, 0, 0);
348 edje_object_part_swallow(wd->as, "elm.drag_button_base", wd->drag_button_base);
350 edje_object_signal_callback_add(wd->as,
351 "elm.drag_button,mouse,up", "",
352 _drag_button_up_cb, obj);
353 edje_object_signal_callback_add(wd->as,
354 "elm.drag_button,mouse,down", "",
355 _drag_button_down_cb, obj);
356 edje_object_signal_callback_add(wd->as,
357 "elm.drag_button,mouse,move", "",
358 _drag_button_move_cb, obj);
360 evas_object_smart_callbacks_descriptions_set(obj, _signals);
361 _mirrored_set(obj, elm_widget_mirrored_get(obj));
367 elm_actionslider_indicator_pos_set(Evas_Object *obj, Elm_Actionslider_Pos pos)
369 ELM_CHECK_WIDTYPE(obj, widtype);
370 Widget_Data *wd = elm_widget_data_get(obj);
371 double position = 0.0;
373 pos = _get_pos_by_orientation(obj, pos);
374 if (pos == ELM_ACTIONSLIDER_CENTER) position = 0.5;
375 else if (pos == ELM_ACTIONSLIDER_RIGHT) position = 1.0;
376 edje_object_part_drag_value_set(wd->as, "elm.drag_button_base", position, 0.5);
379 EAPI Elm_Actionslider_Pos
380 elm_actionslider_indicator_pos_get(const Evas_Object *obj)
382 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_NONE;
383 Widget_Data *wd = elm_widget_data_get(obj);
385 if (!wd) return ELM_ACTIONSLIDER_NONE;
387 edje_object_part_drag_value_get(wd->as, "elm.drag_button_base", &position, NULL);
389 return _get_pos_by_orientation(obj, ELM_ACTIONSLIDER_LEFT);
390 else if (position < 0.7)
391 return ELM_ACTIONSLIDER_CENTER;
393 return _get_pos_by_orientation(obj, ELM_ACTIONSLIDER_RIGHT);
397 elm_actionslider_magnet_pos_set(Evas_Object *obj, Elm_Actionslider_Pos pos)
399 ELM_CHECK_WIDTYPE(obj, widtype);
400 Widget_Data *wd = elm_widget_data_get(obj);
402 wd->magnet_position = pos;
405 EAPI Elm_Actionslider_Pos
406 elm_actionslider_magnet_pos_get(const Evas_Object *obj)
408 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_NONE;
409 Widget_Data *wd = elm_widget_data_get(obj);
410 if (!wd) return ELM_ACTIONSLIDER_NONE;
411 return wd->magnet_position;
415 elm_actionslider_enabled_pos_set(Evas_Object *obj, Elm_Actionslider_Pos pos)
417 ELM_CHECK_WIDTYPE(obj, widtype);
418 Widget_Data *wd = elm_widget_data_get(obj);
420 wd->enabled_position = pos;
423 EAPI Elm_Actionslider_Pos
424 elm_actionslider_enabled_pos_get(const Evas_Object *obj)
426 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_NONE;
427 Widget_Data *wd = elm_widget_data_get(obj);
428 if (!wd) return ELM_ACTIONSLIDER_NONE;
429 return wd->enabled_position;
433 elm_actionslider_labels_set(Evas_Object *obj, const char *left_label, const char *center_label, const char *right_label)
435 ELM_CHECK_WIDTYPE(obj, widtype);
436 Widget_Data *wd = elm_widget_data_get(obj);
439 eina_stringshare_replace(&wd->text_left, left_label);
440 eina_stringshare_replace(&wd->text_center, center_label);
441 eina_stringshare_replace(&wd->text_right, right_label);
442 if (!elm_widget_mirrored_get(obj))
444 edje_object_part_text_set(wd->as, "elm.text.left", wd->text_left);
445 edje_object_part_text_set(wd->as, "elm.text.right", wd->text_right);
449 edje_object_part_text_set(wd->as, "elm.text.left", wd->text_right);
450 edje_object_part_text_set(wd->as, "elm.text.right", wd->text_left);
452 edje_object_part_text_set(wd->as, "elm.text.center", center_label);
456 elm_actionslider_labels_get(const Evas_Object *obj, const char **left_label, const char **center_label, const char **right_label)
458 if (left_label) *left_label= NULL;
459 if (center_label) *center_label= NULL;
460 if (right_label) *right_label= NULL;
461 ELM_CHECK_WIDTYPE(obj, widtype);
462 Widget_Data *wd = elm_widget_data_get(obj);
464 if (left_label) *left_label = wd->text_left;
465 if (center_label) *center_label = wd->text_center;
466 if (right_label) *right_label = wd->text_right;
470 elm_actionslider_selected_label_get(const Evas_Object *obj)
472 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
473 Widget_Data *wd = elm_widget_data_get(obj);
474 if (!wd) return NULL;
476 if ((wd->final_position == 0.0) &&
477 (wd->enabled_position & ELM_ACTIONSLIDER_LEFT))
478 return wd->text_left;
480 if ((wd->final_position == 0.5) &&
481 (wd->enabled_position & ELM_ACTIONSLIDER_CENTER))
482 return wd->text_center;
484 if ((wd->final_position == 1.0) &&
485 (wd->enabled_position & ELM_ACTIONSLIDER_RIGHT))
486 return wd->text_right;
492 elm_actionslider_indicator_label_set(Evas_Object *obj, const char *label)
494 ELM_CHECK_WIDTYPE(obj, widtype);
495 Widget_Data *wd = elm_widget_data_get(obj);
498 eina_stringshare_replace(&wd->indicator_label, label);
499 edje_object_part_text_set(wd->as, "elm.text.indicator", wd->indicator_label);
503 elm_actionslider_indicator_label_get(Evas_Object *obj)
505 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
506 Widget_Data *wd = elm_widget_data_get(obj);
507 if (!wd) return NULL;
508 return wd->indicator_label;