1 #include <Elementary.h>
5 * @defgroup Scroller Scroller
7 * A scroller holds a single object and "scrolls it around". This means that
8 * it allows the user to use a scrollbar (or a finger) to drag the viewable
9 * region around, allowing to move through a much larger object that is
10 * contained in the scroller. The scroiller will always have a small minimum
11 * size by default as it won't be limited by the contents of the scroller.
13 * Signals that you can add callbacks for are:
15 * edge,left - the left edge of the content has been reached
17 * edge,right - the right edge of the content has been reached
19 * edge,top - the top edge of the content has been reached
21 * edge,bottom - the bottom edge of the content has been reached
23 * scroll - the content has been scrolled (moved)
25 * scroll,anim,start - scrolling animation has started
27 * scroll,anim,stop - scrolling animation has stopped
29 * scroll,drag,start - dragging the contents around has started
31 * scroll,drag,stop - dragging the contents around has stopped
33 typedef struct _Widget_Data Widget_Data;
39 const char *widget_name, *widget_base;
42 double pagerel_h, pagerel_v;
43 Evas_Coord pagesize_h, pagesize_v;
46 static const char *widtype = NULL;
47 static void _del_hook(Evas_Object *obj);
48 static void _theme_hook(Evas_Object *obj);
49 static void _show_region_hook(void *data, Evas_Object *obj);
50 static void _sizing_eval(Evas_Object *obj);
51 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
53 static const char SIG_SCROLL[] = "scroll";
54 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
55 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
56 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
57 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
58 static const char SIG_EDGE_LEFT[] = "edge,left";
59 static const char SIG_EDGE_RIGHT[] = "edge,right";
60 static const char SIG_EDGE_TOP[] = "edge,top";
61 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
62 static const Evas_Smart_Cb_Description _signals[] = {
64 {SIG_SCROLL_ANIM_START, ""},
65 {SIG_SCROLL_ANIM_STOP, ""},
66 {SIG_SCROLL_DRAG_START, ""},
67 {SIG_SCROLL_DRAG_STOP, ""},
71 {SIG_EDGE_BOTTOM, ""},
76 _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 _show_region_hook(void *data, Evas_Object *obj)
103 Widget_Data *wd = elm_widget_data_get(data);
104 Evas_Coord x, y, w, h;
106 elm_widget_show_region_get(obj, &x, &y, &w, &h);
108 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
112 _sizing_eval(Evas_Object *obj)
115 Widget_Data *wd = elm_widget_data_get(obj);
116 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
120 evas_object_size_hint_min_get(wd->content, &minw, &minh);
121 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
122 evas_object_size_hint_weight_get(wd->content, &xw, &yw);
125 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
128 if ((minw > 0) && (vw < minw)) vw = minw;
129 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
131 else if (minw > 0) vw = minw;
134 if ((minh > 0) && (vh < minh)) vh = minh;
135 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
137 else if (minh > 0) vh = minh;
138 evas_object_resize(wd->content, vw, vh);
141 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
142 if (wd->min_w) w = vmw + minw;
143 if (wd->min_h) h = vmh + minh;
144 evas_object_size_hint_min_set(obj, w, h);
149 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
155 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
158 Widget_Data *wd = elm_widget_data_get(obj);
159 Evas_Object *sub = event_info;
162 if (sub == wd->content)
164 elm_widget_on_show_region_hook_set(wd->content, NULL, NULL);
165 evas_object_event_callback_del_full (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
166 _changed_size_hints, obj);
170 else if (sub == wd->scr)
175 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
178 Widget_Data *wd = elm_widget_data_get(obj);
182 elm_smart_scroller_hold_set(wd->scr, 1);
186 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
189 Widget_Data *wd = elm_widget_data_get(obj);
193 elm_smart_scroller_hold_set(wd->scr, 0);
197 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
200 Widget_Data *wd = elm_widget_data_get(obj);
204 elm_smart_scroller_freeze_set(wd->scr, 1);
208 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
211 Widget_Data *wd = elm_widget_data_get(obj);
215 elm_smart_scroller_freeze_set(wd->scr, 0);
219 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
225 _edge_left(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
227 evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
231 _edge_right(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
233 evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
237 _edge_top(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
239 evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
243 _edge_bottom(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
245 evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
249 _scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
251 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
255 _scroll_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
257 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
261 _scroll_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
263 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
267 _scroll_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
269 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
273 _scroll_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
275 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
279 * Add a new scroller to the parent
281 * @param parent The parent object
282 * @return The new object or NULL if it cannot be created
287 elm_scroller_add(Evas_Object *parent)
292 Evas_Coord minw, minh;
294 wd = ELM_NEW(Widget_Data);
295 e = evas_object_evas_get(parent);
296 obj = elm_widget_add(e);
297 ELM_SET_WIDTYPE(widtype, "scroller");
298 elm_widget_type_set(obj, "scroller");
299 elm_widget_sub_object_add(parent, obj);
300 elm_widget_data_set(obj, wd);
301 elm_widget_del_hook_set(obj, _del_hook);
302 elm_widget_theme_hook_set(obj, _theme_hook);
304 wd->widget_name = eina_stringshare_add("scroller");
305 wd->widget_base = eina_stringshare_add("base");
307 wd->scr = elm_smart_scroller_add(e);
308 elm_smart_scroller_widget_set(wd->scr, obj);
309 elm_smart_scroller_object_theme_set(obj, wd->scr,
310 wd->widget_name, wd->widget_base,
311 elm_widget_style_get(obj));
312 elm_widget_resize_object_set(obj, wd->scr);
313 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
314 _changed_size_hints, obj);
316 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
317 evas_object_size_hint_min_set(obj, minw, minh);
318 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
320 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
321 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
322 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
323 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
324 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
326 evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
327 evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
328 evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
329 evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
330 evas_object_smart_callback_add(wd->scr, "scroll", _scroll, obj);
331 evas_object_smart_callback_add(wd->scr, "animate,start", _scroll_anim_start, obj);
332 evas_object_smart_callback_add(wd->scr, "animate,stop", _scroll_anim_stop, obj);
333 evas_object_smart_callback_add(wd->scr, "drag,start", _scroll_drag_start, obj);
334 evas_object_smart_callback_add(wd->scr, "drag,stop", _scroll_drag_stop, obj);
338 // TODO: convert Elementary to subclassing of Evas_Smart_Class
339 // TODO: and save some bytes, making descriptions per-class and not instance!
340 evas_object_smart_callbacks_descriptions_set(obj, _signals);
346 * Set the content object
348 * Sets the content of the scroller (the object to be scrolled around)
350 * @param obj The scroller object
351 * @param content The new content object
356 elm_scroller_content_set(Evas_Object *obj, Evas_Object *content)
358 ELM_CHECK_WIDTYPE(obj, widtype);
359 Widget_Data *wd = elm_widget_data_get(obj);
361 if ((wd->content != content) && (wd->content))
362 elm_widget_sub_object_del(obj, wd->content);
363 wd->content = content;
366 elm_widget_on_show_region_hook_set(content, _show_region_hook, obj);
367 elm_widget_sub_object_add(obj, content);
369 elm_smart_scroller_child_set(wd->scr, content);
370 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
371 _changed_size_hints, obj);
377 * Set custom theme elements for the scroller
379 * @param obj The scroller object
380 * @param widget The widget name to use (default is "scroller")
381 * @param base The base name to use (default is "base")
384 elm_scroller_custom_widget_base_theme_set(Evas_Object *obj, const char *widget, const char *base)
386 ELM_CHECK_WIDTYPE(obj, widtype);
387 Widget_Data *wd = elm_widget_data_get(obj);
389 if ((!widget) || (!base)) return;
390 if (eina_stringshare_replace(&wd->widget_name, widget) |
391 eina_stringshare_replace(&wd->widget_base, base))
396 * Make the scroller minimum size limited to the minimum size of the content
398 * By default the scroller will be as small as its design allows, irrespective
399 * of its content. This will make the scroller minimum size the right size
400 * horizontally and/or vertically to perfectly fit its content.
402 * @param obj The scroller object
403 * @param w Enable limiting minimum size horizontally
404 * @param h Enable limiting minimum size vertically
409 elm_scroller_content_min_limit(Evas_Object *obj, Eina_Bool w, Eina_Bool h)
411 ELM_CHECK_WIDTYPE(obj, widtype);
412 Widget_Data *wd = elm_widget_data_get(obj);
420 * Show a specific virtual region within the scroller content object
422 * This will ensure all (or part if it does not fit) of the designated
423 * region in the virtual content object (0, 0 starting at the top-left of the
424 * virtual content object) is shown within the scroller.
426 * @param obj The scroller object
427 * @param x X coordinate of the region
428 * @param y Y coordinate of the region
429 * @param w Width of the region
430 * @param h Height of the region
435 elm_scroller_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
437 ELM_CHECK_WIDTYPE(obj, widtype);
438 Widget_Data *wd = elm_widget_data_get(obj);
441 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
445 * Set the scroller scrollbar policy
447 * This sets the scrollbar visibility policy for the given scroller.
448 * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
449 * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
450 * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
451 * This applies respectively for the horizontal and vertical scrollbars.
453 * @param obj The scroller object
454 * @param policy_h Horizontal scrollbar policy
455 * @param policy_v Vertical scrollbar policy
460 elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
462 ELM_CHECK_WIDTYPE(obj, widtype);
463 Widget_Data *wd = elm_widget_data_get(obj);
464 const Elm_Scroller_Policy map[3] =
466 ELM_SMART_SCROLLER_POLICY_AUTO,
467 ELM_SMART_SCROLLER_POLICY_ON,
468 ELM_SMART_SCROLLER_POLICY_OFF
471 if ((policy_h >= 3) || (policy_v >= 3)) return;
473 elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
477 elm_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
479 ELM_CHECK_WIDTYPE(obj, widtype);
480 Widget_Data *wd = elm_widget_data_get(obj);
481 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
484 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
485 *policy_h = (Elm_Scroller_Policy) s_policy_h;
486 *policy_v = (Elm_Scroller_Policy) s_policy_v;
490 * Get the currently visible content region
492 * This gets the current region in the content object that is visible through
493 * the scroller. Also see elm_scroller_region_show(). The region co-ordinates
494 * are returned in the @p x, @p y, @p w, @p h values pointed to.
496 * @param obj The scroller object
497 * @param x X coordinate of the region
498 * @param y Y coordinate of the region
499 * @param w Width of the region
500 * @param h Height of the region
505 elm_scroller_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
507 ELM_CHECK_WIDTYPE(obj, widtype);
508 Widget_Data *wd = elm_widget_data_get(obj);
512 if ((x) && (y)) elm_smart_scroller_child_pos_get(wd->scr, x, y);
513 if ((w) && (h)) elm_smart_scroller_child_viewport_size_get(wd->scr, w, h);
518 * Get the size of the content child object
520 * This gets the size of the child object of the scroller. Actually the
521 * content of a scroller doesn't specifically need to be an actual object
522 * as it can be virtual and defined purely by callbacks.
524 * @param obj The scroller object
525 * @param w Width return
526 * @param h Height return
531 elm_scroller_child_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
533 ELM_CHECK_WIDTYPE(obj, widtype);
534 Widget_Data *wd = elm_widget_data_get(obj);
536 evas_object_geometry_get(wd->content, NULL, NULL, w, h);
540 * Set bouncing behavior
542 * When scrolling, the scroller may "bounce" when reaching an edge of the child
543 * object. This is a visual way to indicate the end has been reached. This is
544 * enabled by default for both axes. This will set if it is enabled for that
545 * axis with the boolean parameers for each axis.
547 * @param obj The scroller object
548 * @param h_bounce Will the scroller bounce horizontally or not
549 y Y coordinate of the region
550 w Width of the region
551 h Height of the region
553 EAPI void elm_scroller_region_show ( Evas_Object * obj, * @param v_bounce Will the scroller bounce vertically or not
558 elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
560 ELM_CHECK_WIDTYPE(obj, widtype);
561 Widget_Data *wd = elm_widget_data_get(obj);
564 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
568 * Set scroll page size relative to viewport size
570 * The scroller is sapale of limiting scrolling by the user to "pages". That
571 * is to jump by and only show a "whole page" at a time as if the continuous
572 * area of the scroller conent is split into page sized pieces. This sets
573 * the size of a page relative to the viewport of the scroller. 1.0 is "1
574 * viewport" is size (horizontally or vertically). 0.0 turns it off in that
575 * axis. This is mutually exclusive with page size
576 * (see elm_scroller_page_size_set() for more information). likewise 0.5
577 * is "half a viewport". Sane usable valus are normally between 0.0 and 1.0
578 * including 1.0. If you only want 1 axis to be page "limited", use 0.0 for
581 * @param obj The scroller object
582 * @param h_pagerel The horizontal page relative size
583 * @param v_pagerel The vertical page relative size
588 elm_scroller_page_relative_set(Evas_Object *obj, double h_pagerel, double v_pagerel)
590 ELM_CHECK_WIDTYPE(obj, widtype);
591 Widget_Data *wd = elm_widget_data_get(obj);
593 wd->pagerel_h = h_pagerel;
594 wd->pagerel_v = v_pagerel;
596 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
597 wd->pagesize_h, wd->pagesize_v);
601 * Set scroll page size
603 * See also elm_scroller_page_relative_set(). This, instead of a page size
604 * being relaive to the viewport, sets it to an absolute fixed value, with
605 * 0 turning it off for that axis.
607 * @param obj The scroller object
608 * @param h_pagesize The horizontal page size
609 * @param v_pagesize The vertical page size
614 elm_scroller_page_size_set(Evas_Object *obj, Evas_Coord h_pagesize, Evas_Coord v_pagesize)
616 ELM_CHECK_WIDTYPE(obj, widtype);
617 Widget_Data *wd = elm_widget_data_get(obj);
619 wd->pagesize_h = h_pagesize;
620 wd->pagesize_v = v_pagesize;
622 elm_smart_scroller_paging_set(wd->scr, wd->pagerel_h, wd->pagerel_v,
623 wd->pagesize_h, wd->pagesize_v);
627 * Show a specific virtual region within the scroller content object
629 * This will ensure all (or part if it does not fit) of the designated
630 * region in the virtual content object (0, 0 starting at the top-left of the
631 * virtual content object) is shown within the scroller. Unlike
632 * elm_scroller_region_show(), this allow the scroller to "smoothly slide"
633 * to this location (if configuration in general calls for transitions). It
634 * may not jump immediately to the new location and make take a while and
635 * show other content along the way.
637 * @param obj The scroller object
638 * @param x X coordinate of the region
639 * @param y Y coordinate of the region
640 * @param w Width of the region
641 * @param h Height of the region
646 elm_scroller_region_bring_in(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
648 ELM_CHECK_WIDTYPE(obj, widtype);
649 Widget_Data *wd = elm_widget_data_get(obj);
652 elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);