summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJee-Yong Um <jc9.um@samsung.com>2015-10-04 14:55:21 +0200
committerNicolas Aguirre <aguirre.nicolas@gmail.com>2015-11-12 10:15:03 +0100
commit42d8fda3967c2e13d4b87df28cedcad40ffa878a (patch)
tree292248cb23948554d9b482a459dcc8f9ca81a7f2
parent831b2064c779a85f115822dac8f8bff37e34c0bd (diff)
elm_hoversel: refine hoversel scrollability function
Summary: Some modifications for hoversel scrollability are applied. For example, The logic for generating scroller is changed. (newly added during activation) If hoversel's contents are larger than hover,they will be resized to fit hover. If hoversel is moved (by window rotation etc.), scroller will be resized. Reduandant code are removed from popup for scrollability. Test Plan: You can see the sample for scrollable hoversel in second one of "elementary_test hoversel". Reviewers: Hermet, SanghyeonLee, cedric Reviewed By: cedric Subscribers: godlytalias, Hermet Differential Revision: https://phab.enlightenment.org/D2926 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--data/themes/edc/elm/hover.edc8
-rw-r--r--src/bin/test_hoversel.c2
-rw-r--r--src/lib/elc_hoversel.c271
3 files changed, 191 insertions, 90 deletions
diff --git a/data/themes/edc/elm/hover.edc b/data/themes/edc/elm/hover.edc
index 43fd5c54f..b34d36a50 100644
--- a/data/themes/edc/elm/hover.edc
+++ b/data/themes/edc/elm/hover.edc
@@ -676,11 +676,11 @@ group { name: "elm/hover/base/hoversel_horizontal/default";
676 description { state: "default" 0.0; 676 description { state: "default" 0.0;
677 rel1.to_x: "elm.swallow.slot.left"; 677 rel1.to_x: "elm.swallow.slot.left";
678 rel1.to_y: "elm.swallow.slot.left"; 678 rel1.to_y: "elm.swallow.slot.left";
679 rel1.offset: -6 0; 679 rel1.offset: -10 -10;
680 rel2.to_x: "elm.swallow.slot.middle"; 680 rel2.to_x: "elm.swallow.slot.middle";
681 rel2.to_y: "elm.swallow.slot.left"; 681 rel2.to_y: "elm.swallow.slot.left";
682 rel2.relative: 0.0 1.0; 682 rel2.relative: 0.0 1.0;
683 rel2.offset: 4 1; 683 rel2.offset: 4 9;
684 image { 684 image {
685 normal: "button_normal.png"; 685 normal: "button_normal.png";
686 border: 7 7 7 7; 686 border: 7 7 7 7;
@@ -691,10 +691,10 @@ group { name: "elm/hover/base/hoversel_horizontal/default";
691 rel1.to_x: "elm.swallow.slot.middle"; 691 rel1.to_x: "elm.swallow.slot.middle";
692 rel1.to_y: "elm.swallow.slot.right"; 692 rel1.to_y: "elm.swallow.slot.right";
693 rel1.relative: 1.0 0.0; 693 rel1.relative: 1.0 0.0;
694 rel1.offset: -5 0; 694 rel1.offset: -5 -10;
695 rel2.to_x: "elm.swallow.slot.right"; 695 rel2.to_x: "elm.swallow.slot.right";
696 rel2.to_y: "elm.swallow.slot.right"; 696 rel2.to_y: "elm.swallow.slot.right";
697 rel2.offset: 5 1; 697 rel2.offset: 10 9;
698 image { 698 image {
699 normal: "button_normal.png"; 699 normal: "button_normal.png";
700 border: 7 7 7 7; 700 border: 7 7 7 7;
diff --git a/src/bin/test_hoversel.c b/src/bin/test_hoversel.c
index 8fd234669..87f9e5528 100644
--- a/src/bin/test_hoversel.c
+++ b/src/bin/test_hoversel.c
@@ -190,6 +190,8 @@ test_hoversel(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_
190 NULL); 190 NULL);
191 elm_hoversel_item_add(hoversel, "Item 4", "close", ELM_ICON_STANDARD, NULL, 191 elm_hoversel_item_add(hoversel, "Item 4", "close", ELM_ICON_STANDARD, NULL,
192 NULL); 192 NULL);
193 elm_hoversel_item_add(hoversel, "Item 5 - Long Label Here", NULL, ELM_ICON_NONE, NULL,
194 NULL);
193 elm_box_pack_end(bx, hoversel); 195 elm_box_pack_end(bx, hoversel);
194 evas_object_show(hoversel); 196 evas_object_show(hoversel);
195 197
diff --git a/src/lib/elc_hoversel.c b/src/lib/elc_hoversel.c
index 82f595785..5f7d0a83e 100644
--- a/src/lib/elc_hoversel.c
+++ b/src/lib/elc_hoversel.c
@@ -142,15 +142,168 @@ _item_unfocused_cb(void *data EINA_UNUSED,
142} 142}
143 143
144static void 144static void
145_create_scroller(Evas_Object *obj, Elm_Hoversel_Data *sd)
146{
147 //table
148 sd->tbl = elm_table_add(obj);
149
150 //spacer
151 sd->spacer = evas_object_rectangle_add(evas_object_evas_get(obj));
152 evas_object_color_set(sd->spacer, 0, 0, 0, 0);
153 elm_table_pack(sd->tbl, sd->spacer, 0, 0, 1, 1);
154
155 //Scroller
156 sd->scr = elm_scroller_add(sd->tbl);
157 elm_object_style_set(sd->scr, "popup/no_inset_shadow");
158 evas_object_size_hint_weight_set(sd->scr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
159 evas_object_size_hint_align_set(sd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
160 if (sd->horizontal)
161 {
162 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
163 elm_scroller_content_min_limit(sd->scr, EINA_FALSE, EINA_TRUE);
164 elm_scroller_bounce_set(sd->scr, EINA_TRUE, EINA_FALSE);
165 }
166 else
167 {
168 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
169 elm_scroller_content_min_limit(sd->scr, EINA_TRUE, EINA_FALSE);
170 elm_scroller_bounce_set(sd->scr, EINA_FALSE, EINA_TRUE);
171 }
172 elm_table_pack(sd->tbl, sd->scr, 0, 0, 1, 1);
173 evas_object_show(sd->scr);
174}
175
176static void
177_resizing_eval(Evas_Object *obj, Elm_Hoversel_Data *sd)
178{
179 Evas_Object *bx = NULL;
180 const char *max_size_str;
181 int max_size = 0;
182 char buf[128];
183 Evas_Coord box_w = -1, box_h = -1;
184 Evas_Coord x, y, w, h, xx, yy, ww, hh, vw = 0, vh = 0;
185 double align_x;
186 Eina_List *l;
187 Evas_Object *it;
188 Evas_Coord obj_x, obj_y, obj_w, obj_h, it_w, it_h;
189
190 if (sd->scr)
191 bx = elm_object_content_get(sd->scr);
192
193 if ((!sd->expanded) || (!bx)) return;
194
195 edje_object_size_min_calc(elm_layout_edje_get(sd->scr), &vw, &vh);
196 evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h);
197
198 evas_object_size_hint_align_get(obj, &align_x, NULL);
199 if (!sd->horizontal && align_x == EVAS_HINT_FILL)
200 {
201 l = elm_box_children_get(bx);
202 EINA_LIST_FREE(l, it)
203 {
204 edje_object_size_min_calc(elm_layout_edje_get(it), &it_w, &it_h);
205 if ((obj_w - vw) > it_w)
206 evas_object_size_hint_min_set(it, (obj_w - vw), it_h);
207 else
208 evas_object_size_hint_min_set(it, it_w, it_h);
209 }
210 }
211
212 elm_box_recalculate(bx);
213 evas_object_size_hint_min_get(bx, &box_w, &box_h);
214
215 box_w += vw;
216 box_h += vh;
217
218 max_size_str = edje_object_data_get(elm_layout_edje_get(sd->hover), "max_size");
219 if (max_size_str)
220 max_size = (int)(atoi(max_size_str)
221 * elm_config_scale_get()
222 * elm_object_scale_get(obj))
223 / edje_object_base_scale_get(elm_layout_edje_get(sd->hover));
224
225 if (sd->horizontal)
226 {
227 ww = MIN(box_w, max_size);
228 hh = box_h;
229
230 evas_object_size_hint_min_set(sd->spacer, ww, hh);
231 evas_object_size_hint_max_set(sd->spacer, max_size, -1);
232
233 if (!sd->last_location)
234 sd->last_location = elm_hover_best_content_location_get(sd->hover, ELM_HOVER_AXIS_HORIZONTAL);
235 }
236 else
237 {
238 ww = box_w;
239 hh = MIN(box_h, max_size);
240
241 evas_object_size_hint_min_set(sd->spacer, ww, hh);
242 evas_object_size_hint_max_set(sd->spacer, -1, max_size);
243
244 if (!sd->last_location)
245 sd->last_location = elm_hover_best_content_location_get(sd->hover, ELM_HOVER_AXIS_VERTICAL);
246 }
247
248 evas_object_geometry_get(sd->hover_parent, &x, &y, &w, &h);
249 if (eo_isa(sd->hover_parent, ELM_WIN_CLASS))
250 {
251 x = 0;
252 y = 0;
253 }
254
255 snprintf(buf, sizeof(buf), "elm.swallow.slot.%s", sd->last_location);
256 edje_object_part_geometry_get(elm_layout_edje_get(sd->hover), buf, &xx, &yy, NULL, NULL);
257 xx += x;
258 yy += y;
259
260 if (sd->horizontal)
261 {
262 if (xx < obj_x)
263 {
264 xx = x;
265 if ((xx + ww) > obj_x)
266 ww = obj_x - xx;
267 }
268 else
269 {
270 if ((xx + ww) > (x + w))
271 ww = (x + w) - xx;
272 }
273
274 if (yy < 0) yy = y;
275 if ((yy + hh) > (y + h))
276 hh = (y + h) - yy;
277 }
278 else
279 {
280 if (yy < obj_y)
281 {
282 yy = y;
283 if ((yy + hh) > obj_y)
284 hh = obj_y - yy;
285 }
286 else
287 {
288 if ((yy + hh) > (y + h))
289 hh = (y + h) - yy;
290 }
291
292 if (xx < 0) xx = x;
293 if ((xx + ww) > (x + w))
294 ww = (x + w) - xx;
295 }
296
297 evas_object_size_hint_min_set(sd->spacer, ww, hh);
298}
299
300static void
145_activate(Evas_Object *obj) 301_activate(Evas_Object *obj)
146{ 302{
147 Elm_Object_Item *eo_item; 303 Elm_Object_Item *eo_item;
148 Evas_Object *bt, *bx, *ic; 304 Evas_Object *bt, *bx, *ic;
149 const Eina_List *l; 305 const Eina_List *l;
150 char buf[4096]; 306 char buf[4096];
151 const char *max_size_str;
152 int max_size = 0;
153 Evas_Coord box_w = -1, box_h = -1;
154 307
155 ELM_HOVERSEL_DATA_GET(obj, sd); 308 ELM_HOVERSEL_DATA_GET(obj, sd);
156 309
@@ -221,38 +374,13 @@ _activate(Evas_Object *obj)
221 eo_event_callback_add(ELM_WIDGET_EVENT_UNFOCUSED, _item_unfocused_cb, item)); 374 eo_event_callback_add(ELM_WIDGET_EVENT_UNFOCUSED, _item_unfocused_cb, item));
222 } 375 }
223 376
224 elm_box_recalculate(bx);
225
226 if (sd->scroll_enabled) 377 if (sd->scroll_enabled)
227 { 378 {
228 max_size_str = edje_object_data_get(elm_layout_edje_get(sd->hover), "max_size"); 379 _create_scroller(obj, sd);
229 if (max_size_str)
230 max_size = (int)(atoi(max_size_str)
231 * elm_config_scale_get() * elm_object_scale_get(obj));
232
233 elm_object_content_set(sd->scr, bx); 380 elm_object_content_set(sd->scr, bx);
234 evas_object_show(sd->scr);
235 381
236 if (sd->horizontal) 382 _resizing_eval(obj, sd);
237 { 383 elm_object_part_content_set(sd->hover, sd->last_location, sd->tbl);
238 evas_object_size_hint_min_get(bx, &box_w, NULL);
239
240 evas_object_size_hint_min_set(sd->spacer, MIN(box_w, max_size), 0);
241 evas_object_size_hint_max_set(sd->spacer, max_size, -1);
242
243 sd->last_location = elm_hover_best_content_location_get(sd->hover, ELM_HOVER_AXIS_HORIZONTAL);
244 elm_object_part_content_set(sd->hover, sd->last_location, sd->tbl);
245 }
246 else
247 {
248 evas_object_size_hint_min_get(bx, NULL, &box_h);
249
250 evas_object_size_hint_min_set(sd->spacer, 0, MIN(box_h, max_size));
251 evas_object_size_hint_max_set(sd->spacer, -1, max_size);
252
253 sd->last_location = elm_hover_best_content_location_get(sd->hover, ELM_HOVER_AXIS_VERTICAL);
254 elm_object_part_content_set(sd->hover, sd->last_location, sd->tbl);
255 }
256 } 384 }
257 else 385 else
258 { 386 {
@@ -386,45 +514,19 @@ _elm_hoversel_item_eo_base_destructor(Eo *eo_item, Elm_Hoversel_Item_Data *item)
386} 514}
387 515
388static void 516static void
389_create_scroller(Evas_Object *obj) 517_on_move_resize(void * data,
518 Evas *e EINA_UNUSED,
519 Evas_Object *obj,
520 void *event_info EINA_UNUSED)
390{ 521{
391 ELM_HOVERSEL_DATA_GET(obj, sd); 522 Elm_Hoversel_Data *sd = data;
392 523
393 //table 524 if (sd->scroll_enabled)
394 sd->tbl = elm_table_add(obj); 525 _resizing_eval(obj, sd);
395 evas_object_event_callback_add(sd->tbl, EVAS_CALLBACK_DEL,
396 _on_table_del, obj);
397
398 //spacer
399 sd->spacer = evas_object_rectangle_add(evas_object_evas_get(obj));
400 evas_object_color_set(sd->spacer, 0, 0, 0, 0);
401 elm_table_pack(sd->tbl, sd->spacer, 0, 0, 1, 1);
402
403 //Scroller
404 sd->scr = elm_scroller_add(sd->tbl);
405 elm_object_style_set(sd->scr, "popup/no_inset_shadow");
406 evas_object_size_hint_weight_set(sd->scr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
407 evas_object_size_hint_align_set(sd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
408 if (sd->horizontal)
409 {
410 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
411 elm_scroller_content_min_limit(sd->scr, EINA_FALSE, EINA_TRUE);
412 elm_scroller_bounce_set(sd->scr, EINA_TRUE, EINA_FALSE);
413 }
414 else
415 {
416 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
417 elm_scroller_content_min_limit(sd->scr, EINA_TRUE, EINA_FALSE);
418 elm_scroller_bounce_set(sd->scr, EINA_FALSE, EINA_TRUE);
419 }
420 evas_object_event_callback_add(sd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
421 _size_hints_changed_cb, obj);
422 elm_table_pack(sd->tbl, sd->scr, 0, 0, 1, 1);
423 evas_object_show(sd->scr);
424} 526}
425 527
426EOLIAN static void 528EOLIAN static void
427_elm_hoversel_evas_object_smart_add(Eo *obj, Elm_Hoversel_Data *_pd EINA_UNUSED) 529_elm_hoversel_evas_object_smart_add(Eo *obj, Elm_Hoversel_Data *priv)
428{ 530{
429 eo_do_super(obj, MY_CLASS, evas_obj_smart_add()); 531 eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
430 elm_widget_sub_object_parent_add(obj); 532 elm_widget_sub_object_parent_add(obj);
@@ -432,10 +534,11 @@ _elm_hoversel_evas_object_smart_add(Eo *obj, Elm_Hoversel_Data *_pd EINA_UNUSED)
432 eo_do(obj, eo_event_callback_add( 534 eo_do(obj, eo_event_callback_add(
433 EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _on_clicked, obj)); 535 EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _on_clicked, obj));
434 536
435 _create_scroller(obj);
436
437 //What are you doing here? 537 //What are you doing here?
438 eo_do(obj, elm_obj_widget_theme_apply()); 538 eo_do(obj, elm_obj_widget_theme_apply());
539
540 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _on_move_resize, priv);
541 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_move_resize, priv);
439} 542}
440 543
441EOLIAN static void 544EOLIAN static void
@@ -529,17 +632,20 @@ _elm_hoversel_horizontal_set(Eo *obj, Elm_Hoversel_Data *sd, Eina_Bool horizonta
529{ 632{
530 sd->horizontal = !!horizontal; 633 sd->horizontal = !!horizontal;
531 634
532 if (sd->horizontal) 635 if (sd->scr)
533 {
534 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
535 elm_scroller_content_min_limit(sd->scr, EINA_FALSE, EINA_TRUE);
536 elm_scroller_bounce_set(sd->scr, EINA_TRUE, EINA_FALSE);
537 }
538 else
539 { 636 {
540 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO); 637 if (sd->horizontal)
541 elm_scroller_content_min_limit(sd->scr, EINA_TRUE, EINA_FALSE); 638 {
542 elm_scroller_bounce_set(sd->scr, EINA_FALSE, EINA_TRUE); 639 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
640 elm_scroller_content_min_limit(sd->scr, EINA_FALSE, EINA_TRUE);
641 elm_scroller_bounce_set(sd->scr, EINA_TRUE, EINA_FALSE);
642 }
643 else
644 {
645 elm_scroller_policy_set(sd->scr, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
646 elm_scroller_content_min_limit(sd->scr, EINA_TRUE, EINA_FALSE);
647 elm_scroller_bounce_set(sd->scr, EINA_FALSE, EINA_TRUE);
648 }
543 } 649 }
544 650
545 eo_do(obj, elm_obj_widget_theme_apply()); 651 eo_do(obj, elm_obj_widget_theme_apply());
@@ -562,7 +668,6 @@ _elm_hoversel_hover_begin(Eo *obj, Elm_Hoversel_Data *sd)
562EOLIAN static void 668EOLIAN static void
563_elm_hoversel_hover_end(Eo *obj, Elm_Hoversel_Data *sd) 669_elm_hoversel_hover_end(Eo *obj, Elm_Hoversel_Data *sd)
564{ 670{
565 Evas_Object *bx;
566 Elm_Object_Item *eo_item; 671 Elm_Object_Item *eo_item;
567 Eina_List *l; 672 Eina_List *l;
568 673
@@ -570,20 +675,14 @@ _elm_hoversel_hover_end(Eo *obj, Elm_Hoversel_Data *sd)
570 675
571 sd->expanded = EINA_FALSE; 676 sd->expanded = EINA_FALSE;
572 677
573 if (sd->scroll_enabled)
574 {
575 bx = elm_object_content_unset(sd->scr);
576 evas_object_hide(sd->scr);
577 elm_object_part_content_unset(sd->hover, sd->last_location);
578 elm_object_part_content_set(sd->hover, sd->last_location, bx);
579 }
580
581 EINA_LIST_FOREACH(sd->items, l, eo_item) 678 EINA_LIST_FOREACH(sd->items, l, eo_item)
582 { 679 {
583 ELM_HOVERSEL_ITEM_DATA_GET(eo_item, it); 680 ELM_HOVERSEL_ITEM_DATA_GET(eo_item, it);
584 VIEW(it) = NULL; 681 VIEW(it) = NULL;
585 } 682 }
586 ELM_SAFE_FREE(sd->hover, evas_object_del); 683 ELM_SAFE_FREE(sd->hover, evas_object_del);
684 sd->scr = NULL;
685 sd->last_location = NULL;
587 686
588 eo_do(obj, eo_event_callback_call(ELM_HOVERSEL_EVENT_DISMISSED, NULL)); 687 eo_do(obj, eo_event_callback_call(ELM_HOVERSEL_EVENT_DISMISSED, NULL));
589} 688}