1 #include <Elementary.h>
5 * @defgroup Scroller Scroller
8 * A scroller holds a single object and "scrolls it around". This means that
9 * it allows the user to use a scrollbar (or a finger) to drag the viewable
10 * region around, allowing to move through a much larger object that is
11 * contained in the scroller. The scroiller will always have a small minimum
12 * size by default as it won't be limited by the contents of the scroller.
14 * Signals that you can add callbacks for are:
16 * edge,left - the left edge of the content has been reached
18 * edge,right - the right edge of the content has been reached
20 * edge,top - the top edge of the content has been reached
22 * edge,bottom - the bottom edge of the content has been reached
24 * scroll - the content has been scrolled (moved)
26 * scroll,anim,start - scrolling animation has started
28 * scroll,anim,stop - scrolling animation has stopped
30 * scroll,drag,start - dragging the contents around has started
32 * scroll,drag,stop - dragging the contents around has stopped
34 typedef struct _Widget_Data Widget_Data;
40 const char *widget_name, *widget_base;
43 double pagerel_h, pagerel_v;
44 Evas_Coord pagesize_h, pagesize_v;
47 static const char *widtype = NULL;
48 static void _del_hook(Evas_Object *obj);
49 static void _theme_hook(Evas_Object *obj);
50 static void _show_region_hook(void *data, Evas_Object *obj);
51 static void _sizing_eval(Evas_Object *obj);
52 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
54 static const char SIG_SCROLL[] = "scroll";
55 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
56 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
57 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
58 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
59 static const char SIG_EDGE_LEFT[] = "edge,left";
60 static const char SIG_EDGE_RIGHT[] = "edge,right";
61 static const char SIG_EDGE_TOP[] = "edge,top";
62 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
63 static const Evas_Smart_Cb_Description _signals[] = {
65 {SIG_SCROLL_ANIM_START, ""},
66 {SIG_SCROLL_ANIM_STOP, ""},
67 {SIG_SCROLL_DRAG_START, ""},
68 {SIG_SCROLL_DRAG_STOP, ""},
72 {SIG_EDGE_BOTTOM, ""},
77 _del_hook(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
86 _theme_hook(Evas_Object *obj)
88 Widget_Data *wd = elm_widget_data_get(obj);
92 elm_smart_scroller_object_theme_set(obj, wd->scr,
93 wd->widget_name, wd->widget_base,
94 elm_widget_style_get(obj));
95 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
101 _show_region_hook(void *data, Evas_Object *obj)
104 Widget_Data *wd = elm_widget_data_get(data);
105 Evas_Coord x, y, w, h;
107 elm_widget_show_region_get(obj, &x, &y, &w, &h);
109 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
113 _sizing_eval(Evas_Object *obj)
116 Widget_Data *wd = elm_widget_data_get(obj);
117 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
121 evas_object_size_hint_min_get(wd->content, &minw, &minh);
122 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
123 evas_object_size_hint_weight_get(wd->content, &xw, &yw);
126 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
129 if ((minw > 0) && (vw < minw)) vw = minw;
130 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
132 else if (minw > 0) vw = minw;
135 if ((minh > 0) && (vh < minh)) vh = minh;
136 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
138 else if (minh > 0) vh = minh;
139 evas_object_resize(wd->content, vw, vh);
142 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
143 if (wd->min_w) w = vmw + minw;
144 if (wd->min_h) h = vmh + minh;
145 evas_object_size_hint_min_set(obj, w, h);
150 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
156 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
159 Widget_Data *wd = elm_widget_data_get(obj);
160 Evas_Object *sub = event_info;
163 if (sub == wd->content)
165 elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
166 evas_object_event_callback_del_full (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
167 _changed_size_hints, obj);
171 else if (sub == wd->scr)
176 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
179 Widget_Data *wd = elm_widget_data_get(obj);
183 elm_smart_scroller_hold_set(wd->scr, 1);
187 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
190 Widget_Data *wd = elm_widget_data_get(obj);
194 elm_smart_scroller_hold_set(wd->scr, 0);
198 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
201 Widget_Data *wd = elm_widget_data_get(obj);
205 elm_smart_scroller_freeze_set(wd->scr, 1);
209 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
212 Widget_Data *wd = elm_widget_data_get(obj);
216 elm_smart_scroller_freeze_set(wd->scr, 0);
220 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
226 _edge_left(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
228 evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
232 _edge_right(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
234 evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
238 _edge_top(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
240 evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
244 _edge_bottom(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
246 evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
250 _scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
252 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
256 _scroll_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
258 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
262 _scroll_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
264 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
268 _scroll_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
270 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
274 _scroll_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
276 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
280 * Add a new scroller to the parent
282 * @param parent The parent object
283 * @return The new object or NULL if it cannot be created
288 elm_scroller_add(Evas_Object *parent)
293 Evas_Coord minw, minh;
295 wd = ELM_NEW(Widget_Data);
296 e = evas_object_evas_get(parent);
297 obj = elm_widget_add(e);
298 ELM_SET_WIDTYPE(widtype, "scroller");
299 elm_widget_type_set(obj, "scroller");
300 elm_widget_sub_object_add(parent, obj);
301 elm_widget_data_set(obj, wd);
302 elm_widget_del_hook_set(obj, _del_hook);
303 elm_widget_theme_hook_set(obj, _theme_hook);
305 wd->widget_name = eina_stringshare_add("scroller");
306 wd->widget_base = eina_stringshare_add("base");
308 wd->scr = elm_smart_scroller_add(e);
309 elm_smart_scroller_widget_set(wd->scr, obj);
310 elm_smart_scroller_object_theme_set(obj, wd->scr,
311 wd->widget_name, wd->widget_base,
312 elm_widget_style_get(obj));
313 elm_widget_resize_object_set(obj, wd->scr);
314 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
315 _changed_size_hints, obj);
317 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
318 evas_object_size_hint_min_set(obj, minw, minh);
319 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
321 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
322 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
323 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
324 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
325 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
327 evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
328 evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
329 evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
330 evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
331 evas_object_smart_callback_add(wd->scr, "scroll", _scroll, obj);
332 evas_object_smart_callback_add(wd->scr, "animate,start", _scroll_anim_start, obj);
333 evas_object_smart_callback_add(wd->scr, "animate,stop", _scroll_anim_stop, obj);
334 evas_object_smart_callback_add(wd->scr, "drag,start", _scroll_drag_start, obj);
335 evas_object_smart_callback_add(wd->scr, "drag,stop", _scroll_drag_stop, obj);
339 // TODO: convert Elementary to subclassing of Evas_Smart_Class
340 // TODO: and save some bytes, making descriptions per-class and not instance!
341 evas_object_smart_callbacks_descriptions_set(obj, _signals);
347 * Set the content object
349 * Sets the content of the scroller (the object to be scrolled around)
351 * @param obj The scroller object
352 * @param content The new content object
357 elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
359 ELM_CHECK_WIDTYPE(obj, widtype);
360 Widget_Data *wd = elm_widget_data_get(obj);
362 if ((wd->content != content) && (wd->content))
363 elm_widget_sub_object_del(obj, wd->content);
364 wd->content = content;
367 elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
368 elm_widget_sub_object_add(obj, content);
370 elm_smart_scroller_child_set(wd->scr, content);
371 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
372 _changed_size_hints, obj);
378 * Set custom theme elements for the scroller
380 * @param obj The scroller object
381 * @param widget The widget name to use (default is "scroller")
382 * @param base The base name to use (default is "base")
385 elm_scroller_custom_widget_base_theme_set(Evas_Object *obj, const char *widget, const char *base)
387 ELM_CHECK_WIDTYPE(obj, widtype);
388 Widget_Data *wd = elm_widget_data_get(obj);
390 if ((!widget) || (!base)) return;
391 if (eina_stringshare_replace(&wd->widget_name, widget) |
392 eina_stringshare_replace(&wd->widget_base, base))
397 * Make the scroller minimum size limited to the minimum size of the content
399 * By default the scroller will be as small as its design allows, irrespective
400 * of its content. This will make the scroller minimum size the right size
401 * horizontally and/or vertically to perfectly fit its content.
403 * @param obj The scroller object
404 * @param w Enable limiting minimum size horizontally
405 * @param h Enable limiting minimum size vertically
410 elm_scroller_content_min_limit(Evas_Object *obj, Eina_Bool w, Eina_Bool h)
412 ELM_CHECK_WIDTYPE(obj, widtype);
413 Widget_Data *wd = elm_widget_data_get(obj);
421 * Show a specific virtual region within the scroller content object
423 * This will ensure all (or part if it does not fit) of the designated
424 * region in the virtual content object (0, 0 starting at the top-left of the
425 * virtual content object) is shown within the scroller.
427 * @param obj The scroller object
428 * @param x X coordinate of the region
429 * @param y Y coordinate of the region
430 * @param w Width of the region
431 * @param h Height of the region
436 elm_scroller_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
438 ELM_CHECK_WIDTYPE(obj, widtype);
439 Widget_Data *wd = elm_widget_data_get(obj);
442 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
446 * Set the scroller scrollbar policy
448 * This sets the scrollbar visibility policy for the given scroller.
449 * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
450 * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
451 * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
452 * This applies respectively for the horizontal and vertical scrollbars.
454 * @param obj The scroller object
455 * @param policy_h Horizontal scrollbar policy
456 * @param policy_v Vertical scrollbar policy
461 elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
463 ELM_CHECK_WIDTYPE(obj, widtype);
464 Widget_Data *wd = elm_widget_data_get(obj);
465 const Elm_Scroller_Policy map[3] =
467 ELM_SMART_SCROLLER_POLICY_AUTO,
468 ELM_SMART_SCROLLER_POLICY_ON,
469 ELM_SMART_SCROLLER_POLICY_OFF
472 if ((policy_h >= 3) || (policy_v >= 3)) return;
474 elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
478 elm_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
480 ELM_CHECK_WIDTYPE(obj, widtype);
481 Widget_Data *wd = elm_widget_data_get(obj);
482 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
485 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
486 *policy_h = (Elm_Scroller_Policy) s_policy_h;
487 *policy_v = (Elm_Scroller_Policy) s_policy_v;
491 * Get the currently visible content region
493 * This gets the current region in the content object that is visible through
494 * the scroller. Also see elm_scroller_region_show(). The region co-ordinates
495 * are returned in the @p x, @p y, @p w, @p h values pointed to.
497 * @param obj The scroller object
498 * @param x X coordinate of the region
499 * @param y Y coordinate of the region
500 * @param w Width of the region
501 * @param h Height of the region
506 elm_scroller_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
508 ELM_CHECK_WIDTYPE(obj, widtype);
509 Widget_Data *wd = elm_widget_data_get(obj);
513 if ((x) && (y)) elm_smart_scroller_child_pos_get(wd->scr, x, y);
514 if ((w) && (h)) elm_smart_scroller_child_viewport_size_get(wd->scr, w, h);
519 * Get the size of the content child object
521 * This gets the size of the child object of the scroller. Actually the
522 * content of a scroller doesn't specifically need to be an actual object
523 * as it can be virtual and defined purely by callbacks.
525 * @param obj The scroller object
526 * @param w Width return
527 * @param h Height return
532 elm_scroller_child_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
534 ELM_CHECK_WIDTYPE(obj, widtype);
535 Widget_Data *wd = elm_widget_data_get(obj);
537 evas_object_geometry_get(wd->content, NULL, NULL, w, h);
541 * Set bouncing behavior
543 * When scrolling, the scroller may "bounce" when reaching an edge of the child
544 * object. This is a visual way to indicate the end has been reached. This is
545 * enabled by default for both axes. This will set if it is enabled for that
546 * axis with the boolean parameers for each axis.
548 * @param obj The scroller object
549 * @param h_bounce Will the scroller bounce horizontally or not
550 y Y coordinate of the region
551 w Width of the region
552 h Height of the region
554 EAPI void elm_scroller_region_show ( Evas_Object * obj, * @param v_bounce Will the scroller bounce vertically or not
559 elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
561 ELM_CHECK_WIDTYPE(obj, widtype);
562 Widget_Data *wd = elm_widget_data_get(obj);
565 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
569 * Set scroll page size relative to viewport size
571 * The scroller is sapale of limiting scrolling by the user to "pages". That
572 * is to jump by and only show a "whole page" at a time as if the continuous
573 * area of the scroller conent is split into page sized pieces. This sets
574 * the size of a page relative to the viewport of the scroller. 1.0 is "1
575 * viewport" is size (horizontally or vertically). 0.0 turns it off in that
576 * axis. This is mutually exclusive with page size
577 * (see elm_scroller_page_size_set() for more information). likewise 0.5
578 * is "half a viewport". Sane usable valus are normally between 0.0 and 1.0
579 * including 1.0. If you only want 1 axis to be page "limited", use 0.0 for
582 * @param obj The scroller object
583 * @param h_pagerel The horizontal page relative size
584 * @param v_pagerel The vertical page relative size
589 elm_scroller_page_relative_set(Evas_Object *obj, double h_pagerel, double v_pagerel)
591 ELM_CHECK_WIDTYPE(obj, widtype);
592 Widget_Data *wd = elm_widget_data_get(obj);
594 wd->pagerel_h = h_pagerel;
595 wd->pagerel_v = v_pagerel;
597 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
598 wd->pagesize_h, wd->pagesize_v);
602 * Set scroll page size
604 * See also elm_scroller_page_relative_set(). This, instead of a page size
605 * being relaive to the viewport, sets it to an absolute fixed value, with
606 * 0 turning it off for that axis.
608 * @param obj The scroller object
609 * @param h_pagesize The horizontal page size
610 * @param v_pagesize The vertical page size
615 elm_scroller_page_size_set(Evas_Object *obj, Evas_Coord h_pagesize, Evas_Coord v_pagesize)
617 ELM_CHECK_WIDTYPE(obj, widtype);
618 Widget_Data *wd = elm_widget_data_get(obj);
620 wd->pagesize_h = h_pagesize;
621 wd->pagesize_v = v_pagesize;
623 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
624 wd->pagesize_h, wd->pagesize_v);
628 * Show a specific virtual region within the scroller content object
630 * This will ensure all (or part if it does not fit) of the designated
631 * region in the virtual content object (0, 0 starting at the top-left of the
632 * virtual content object) is shown within the scroller. Unlike
633 * elm_scroller_region_show(), this allow the scroller to "smoothly slide"
634 * to this location (if configuration in general calls for transitions). It
635 * may not jump immediately to the new location and make take a while and
636 * show other content along the way.
638 * @param obj The scroller object
639 * @param x X coordinate of the region
640 * @param y Y coordinate of the region
641 * @param w Width of the region
642 * @param h Height of the region
647 elm_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
649 ELM_CHECK_WIDTYPE(obj, widtype);
650 Widget_Data *wd = elm_widget_data_get(obj);
653 elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
657 * Set scroll only one page
659 * @param obj The scroller object
665 elm_scroller_page_move_set(Evas_Object *obj, Eina_Bool set)
667 Widget_Data *wd = elm_widget_data_get(obj);
670 elm_smart_scroller_page_move_set(wd->scr, set);
674 * Set events propagation
676 * @param obj The scroller object
682 elm_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool set)
684 Widget_Data *wd = elm_widget_data_get(obj);
687 evas_object_propagate_events_set(wd->scr, set);