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)
79 Widget_Data *wd = elm_widget_data_get(obj);
85 _theme_hook(Evas_Object *obj)
87 Widget_Data *wd = elm_widget_data_get(obj);
91 elm_smart_scroller_object_theme_set(obj, wd->scr,
92 wd->widget_name, wd->widget_base,
93 elm_widget_style_get(obj));
94 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
100 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
102 Widget_Data *wd = elm_widget_data_get(obj);
104 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
109 _show_region_hook(void *data, Evas_Object *obj)
112 Widget_Data *wd = elm_widget_data_get(data);
113 Evas_Coord x, y, w, h;
115 elm_widget_show_region_get(obj, &x, &y, &w, &h);
117 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
121 _sizing_eval(Evas_Object *obj)
124 Widget_Data *wd = elm_widget_data_get(obj);
125 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
129 evas_object_size_hint_min_get(wd->content, &minw, &minh);
130 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
131 evas_object_size_hint_weight_get(wd->content, &xw, &yw);
132 //evas_object_geometry_get(wd->content, NULL, NULL, &w, &h);
136 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
139 // if(w > vw) vw = w;
140 if ((minw > 0) && (vw < minw)) vw = minw;
141 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
143 else if (minw > 0) vw = minw;
147 // if(h > vh) vh = h;
148 if ((minh > 0) && (vh < minh)) vh = minh;
149 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
151 else if (minh > 0) vh = minh;
153 evas_object_resize(wd->content, vw, vh);
156 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
157 if (wd->min_w) w = vmw + minw;
158 if (wd->min_h) h = vmh + minh;
160 evas_object_size_hint_max_get(obj, &maxw, &maxh);
161 if ((maxw > 0) && (w > maxw)) w = maxw;
162 if ((maxh > 0) && (h > maxh)) h = maxh;
164 evas_object_size_hint_min_set(obj, w, h);
169 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
175 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
178 Widget_Data *wd = elm_widget_data_get(obj);
179 Evas_Object *sub = event_info;
182 if (sub == wd->content)
184 elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
185 evas_object_event_callback_del_full (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
186 _changed_size_hints, obj);
190 else if (sub == wd->scr)
195 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
198 Widget_Data *wd = elm_widget_data_get(obj);
202 elm_smart_scroller_hold_set(wd->scr, 1);
206 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
209 Widget_Data *wd = elm_widget_data_get(obj);
213 elm_smart_scroller_hold_set(wd->scr, 0);
217 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
220 Widget_Data *wd = elm_widget_data_get(obj);
224 elm_smart_scroller_freeze_set(wd->scr, 1);
228 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
231 Widget_Data *wd = elm_widget_data_get(obj);
235 elm_smart_scroller_freeze_set(wd->scr, 0);
239 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
245 _edge_left(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
247 evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
251 _edge_right(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
253 evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
257 _edge_top(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
259 evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
263 _edge_bottom(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
265 evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
269 _scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
271 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
275 _scroll_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
277 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
281 _scroll_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
283 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
287 _scroll_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
289 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
293 _scroll_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
295 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
299 * Add a new scroller to the parent
301 * @param parent The parent object
302 * @return The new object or NULL if it cannot be created
307 elm_scroller_add(Evas_Object *parent)
312 Evas_Coord minw, minh;
314 wd = ELM_NEW(Widget_Data);
315 e = evas_object_evas_get(parent);
316 obj = elm_widget_add(e);
317 ELM_SET_WIDTYPE(widtype, "scroller");
318 elm_widget_type_set(obj, "scroller");
319 elm_widget_sub_object_add(parent, obj);
320 elm_widget_data_set(obj, wd);
321 elm_widget_del_hook_set(obj, _del_hook);
322 elm_widget_theme_hook_set(obj, _theme_hook);
323 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
325 wd->widget_name = eina_stringshare_add("scroller");
326 wd->widget_base = eina_stringshare_add("base");
328 wd->scr = elm_smart_scroller_add(e);
329 elm_smart_scroller_widget_set(wd->scr, obj);
330 elm_smart_scroller_object_theme_set(obj, wd->scr,
331 wd->widget_name, wd->widget_base,
332 elm_widget_style_get(obj));
333 elm_widget_resize_object_set(obj, wd->scr);
334 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
335 _changed_size_hints, obj);
337 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
338 evas_object_size_hint_min_set(obj, minw, minh);
339 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
341 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
342 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
343 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
344 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
345 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
347 evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
348 evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
349 evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
350 evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
351 evas_object_smart_callback_add(wd->scr, "scroll", _scroll, obj);
352 evas_object_smart_callback_add(wd->scr, "animate,start", _scroll_anim_start, obj);
353 evas_object_smart_callback_add(wd->scr, "animate,stop", _scroll_anim_stop, obj);
354 evas_object_smart_callback_add(wd->scr, "drag,start", _scroll_drag_start, obj);
355 evas_object_smart_callback_add(wd->scr, "drag,stop", _scroll_drag_stop, obj);
359 // TODO: convert Elementary to subclassing of Evas_Smart_Class
360 // TODO: and save some bytes, making descriptions per-class and not instance!
361 evas_object_smart_callbacks_descriptions_set(obj, _signals);
367 * Set the content of the scroller widget (the object to be scrolled around).
369 * Once the content object is set, a previously set one will be deleted.
370 * If you want to keep that old content object, use the
371 * elm_scroller_content_unset() function.
373 * @param obj The scroller object
374 * @param content The new content object
379 elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
381 ELM_CHECK_WIDTYPE(obj, widtype);
382 Widget_Data *wd = elm_widget_data_get(obj);
384 if (wd->content == content) return;
385 if (wd->content) evas_object_del(wd->content);
386 wd->content = content;
389 elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
390 elm_widget_sub_object_add(obj, content);
392 elm_smart_scroller_child_set(wd->scr, content);
393 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
394 _changed_size_hints, obj);
400 * Get the content of the scroller widget
402 * Return the content object which is set for this widget
404 * @param obj The slider object
405 * @return The content that is being used
410 elm_scroller_content_get(const Evas_Object *obj)
412 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
413 Widget_Data *wd = elm_widget_data_get(obj);
414 if (!wd) return NULL;
419 * Unset the content of the scroller widget
421 * Unparent and return the content object which was set for this widget
423 * @param obj The slider objecet
424 * @return The content that was being used
429 elm_scroller_content_unset(Evas_Object *obj)
431 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
432 Widget_Data *wd = elm_widget_data_get(obj);
433 Evas_Object *content;
434 if (!wd) return NULL;
435 if (!wd->content) return NULL;
436 content = wd->content;
437 elm_widget_sub_object_del(obj, wd->content);
438 edje_object_part_unswallow(wd->scr, wd->content);
444 * Set custom theme elements for the scroller
446 * @param obj The scroller object
447 * @param widget The widget name to use (default is "scroller")
448 * @param base The base name to use (default is "base")
453 elm_scroller_custom_widget_base_theme_set(Evas_Object *obj, const char *widget, const char *base)
455 ELM_CHECK_WIDTYPE(obj, widtype);
456 Widget_Data *wd = elm_widget_data_get(obj);
458 if ((!widget) || (!base)) return;
459 if (eina_stringshare_replace(&wd->widget_name, widget) |
460 eina_stringshare_replace(&wd->widget_base, base))
465 * Make the scroller minimum size limited to the minimum size of the content
467 * By default the scroller will be as small as its design allows, irrespective
468 * of its content. This will make the scroller minimum size the right size
469 * horizontally and/or vertically to perfectly fit its content.
471 * @param obj The scroller object
472 * @param w Enable limiting minimum size horizontally
473 * @param h Enable limiting minimum size vertically
478 elm_scroller_content_min_limit(Evas_Object *obj, Eina_Bool w, Eina_Bool h)
480 ELM_CHECK_WIDTYPE(obj, widtype);
481 Widget_Data *wd = elm_widget_data_get(obj);
489 * Show a specific virtual region within the scroller content object
491 * This will ensure all (or part if it does not fit) of the designated
492 * region in the virtual content object (0, 0 starting at the top-left of the
493 * virtual content object) is shown within the scroller.
495 * @param obj The scroller object
496 * @param x X coordinate of the region
497 * @param y Y coordinate of the region
498 * @param w Width of the region
499 * @param h Height of the region
504 elm_scroller_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
506 ELM_CHECK_WIDTYPE(obj, widtype);
507 Widget_Data *wd = elm_widget_data_get(obj);
510 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
514 * Set the scroller scrollbar policy
516 * This sets the scrollbar visibility policy for the given scroller.
517 * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
518 * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
519 * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
520 * This applies respectively for the horizontal and vertical scrollbars.
522 * @param obj The scroller object
523 * @param policy_h Horizontal scrollbar policy
524 * @param policy_v Vertical scrollbar policy
529 elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
531 ELM_CHECK_WIDTYPE(obj, widtype);
532 Widget_Data *wd = elm_widget_data_get(obj);
533 const Elm_Scroller_Policy map[3] =
535 ELM_SMART_SCROLLER_POLICY_AUTO,
536 ELM_SMART_SCROLLER_POLICY_ON,
537 ELM_SMART_SCROLLER_POLICY_OFF
540 if ((policy_h >= 3) || (policy_v >= 3)) return;
542 elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
546 elm_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
548 ELM_CHECK_WIDTYPE(obj, widtype);
549 Widget_Data *wd = elm_widget_data_get(obj);
550 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
553 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
554 *policy_h = (Elm_Scroller_Policy) s_policy_h;
555 *policy_v = (Elm_Scroller_Policy) s_policy_v;
559 * Get the currently visible content region
561 * This gets the current region in the content object that is visible through
562 * the scroller. Also see elm_scroller_region_show(). The region co-ordinates
563 * are returned in the @p x, @p y, @p w, @p h values pointed to.
565 * @param obj The scroller object
566 * @param x X coordinate of the region
567 * @param y Y coordinate of the region
568 * @param w Width of the region
569 * @param h Height of the region
574 elm_scroller_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
576 ELM_CHECK_WIDTYPE(obj, widtype);
577 Widget_Data *wd = elm_widget_data_get(obj);
581 if ((x) && (y)) elm_smart_scroller_child_pos_get(wd->scr, x, y);
582 if ((w) && (h)) elm_smart_scroller_child_viewport_size_get(wd->scr, w, h);
587 * Get the size of the content child object
589 * This gets the size of the child object of the scroller. Actually the
590 * content of a scroller doesn't specifically need to be an actual object
591 * as it can be virtual and defined purely by callbacks.
593 * @param obj The scroller object
594 * @param w Width return
595 * @param h Height return
600 elm_scroller_child_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
602 ELM_CHECK_WIDTYPE(obj, widtype);
603 Widget_Data *wd = elm_widget_data_get(obj);
605 evas_object_geometry_get(wd->content, NULL, NULL, w, h);
609 * Set bouncing behavior
611 * When scrolling, the scroller may "bounce" when reaching an edge of the child
612 * object. This is a visual way to indicate the end has been reached. This is
613 * enabled by default for both axes. This will set if it is enabled for that
614 * axis with the boolean parameers for each axis.
616 * @param obj The scroller object
617 * @param h_bounce Will the scroller bounce horizontally or not
618 * @param v_bounce Will the scroller bounce vertically or not
623 elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
625 ELM_CHECK_WIDTYPE(obj, widtype);
626 Widget_Data *wd = elm_widget_data_get(obj);
629 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
633 * Get the bounce mode
635 * @param obj The Scroller object
636 * @param h_bounce Allow bounce horizontally
637 * @param v_bounce Allow bounce vertically
642 elm_scroller_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
644 ELM_CHECK_WIDTYPE(obj, widtype);
645 Widget_Data *wd = elm_widget_data_get(obj);
647 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
651 * Set scroll page size relative to viewport size
653 * The scroller is sapale of limiting scrolling by the user to "pages". That
654 * is to jump by and only show a "whole page" at a time as if the continuous
655 * area of the scroller conent is split into page sized pieces. This sets
656 * the size of a page relative to the viewport of the scroller. 1.0 is "1
657 * viewport" is size (horizontally or vertically). 0.0 turns it off in that
658 * axis. This is mutually exclusive with page size
659 * (see elm_scroller_page_size_set() for more information). likewise 0.5
660 * is "half a viewport". Sane usable valus are normally between 0.0 and 1.0
661 * including 1.0. If you only want 1 axis to be page "limited", use 0.0 for
664 * @param obj The scroller object
665 * @param h_pagerel The horizontal page relative size
666 * @param v_pagerel The vertical page relative size
671 elm_scroller_page_relative_set(Evas_Object *obj, double h_pagerel, double v_pagerel)
673 ELM_CHECK_WIDTYPE(obj, widtype);
674 Widget_Data *wd = elm_widget_data_get(obj);
676 wd->pagerel_h = h_pagerel;
677 wd->pagerel_v = v_pagerel;
679 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
680 wd->pagesize_h, wd->pagesize_v);
684 * Set scroll page size
686 * See also elm_scroller_page_relative_set(). This, instead of a page size
687 * being relaive to the viewport, sets it to an absolute fixed value, with
688 * 0 turning it off for that axis.
690 * @param obj The scroller object
691 * @param h_pagesize The horizontal page size
692 * @param v_pagesize The vertical page size
697 elm_scroller_page_size_set(Evas_Object *obj, Evas_Coord h_pagesize, Evas_Coord v_pagesize)
699 ELM_CHECK_WIDTYPE(obj, widtype);
700 Widget_Data *wd = elm_widget_data_get(obj);
702 wd->pagesize_h = h_pagesize;
703 wd->pagesize_v = v_pagesize;
705 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
706 wd->pagesize_h, wd->pagesize_v);
710 * Show a specific virtual region within the scroller content object
712 * This will ensure all (or part if it does not fit) of the designated
713 * region in the virtual content object (0, 0 starting at the top-left of the
714 * virtual content object) is shown within the scroller. Unlike
715 * elm_scroller_region_show(), this allow the scroller to "smoothly slide"
716 * to this location (if configuration in general calls for transitions). It
717 * may not jump immediately to the new location and make take a while and
718 * show other content along the way.
720 * @param obj The scroller object
721 * @param x X coordinate of the region
722 * @param y Y coordinate of the region
723 * @param w Width of the region
724 * @param h Height of the region
729 elm_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
731 ELM_CHECK_WIDTYPE(obj, widtype);
732 Widget_Data *wd = elm_widget_data_get(obj);
735 elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
739 * Set scroll only one page
741 * @param obj The scroller object
747 elm_scroller_page_move_set(Evas_Object *obj, Eina_Bool set)
749 Widget_Data *wd = elm_widget_data_get(obj);
752 elm_smart_scroller_page_move_set(wd->scr, set);
756 * Set events propagation
758 * @param obj The scroller object
764 elm_scroller_propagate_events_set(Evas_Object *obj, Eina_Bool set)
766 Widget_Data *wd = elm_widget_data_get(obj);
769 evas_object_propagate_events_set(wd->scr, set);