summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-07-31 14:02:47 -0400
committerCedric BAIL <cedric.bail@free.fr>2019-07-31 14:00:11 -0700
commitdd11dadfefbcc7f8e0bc7475dcd687a3e5cc874a (patch)
treea1479a799e5eaf77476284943496eb1a23a22eb1 /src/lib
parent32cffb4494c46fa3705062c8e43294bf8f5eca87 (diff)
efl_ui/tags: use flow box internally
the existing layout code here is basically just a flow box, so use that instead to avoid mixing legacy widgets in unified ones Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9463
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/elementary/efl_ui_tags.c208
1 files changed, 29 insertions, 179 deletions
diff --git a/src/lib/elementary/efl_ui_tags.c b/src/lib/elementary/efl_ui_tags.c
index a2d3964fa1..eb30e4ddca 100644
--- a/src/lib/elementary/efl_ui_tags.c
+++ b/src/lib/elementary/efl_ui_tags.c
@@ -50,12 +50,12 @@ _shrink_mode_set(Eo *obj,
50 if (shrink == EINA_TRUE) 50 if (shrink == EINA_TRUE)
51 { 51 {
52 Evas_Coord w = 0; 52 Evas_Coord w = 0;
53 Evas_Coord box_inner_item_width_padding = 0; 53 double box_inner_item_width_padding = 0;
54 Eina_Value val; 54 Eina_Value val;
55 55
56 elm_box_padding_get(sd->box, &box_inner_item_width_padding, NULL); 56 efl_gfx_arrangement_content_padding_get(sd->box, &box_inner_item_width_padding, NULL, NULL);
57 // unpack all items and entry 57 // unpack all items and entry
58 elm_box_unpack_all(sd->box); 58 efl_pack_unpack_all(sd->box);
59 EINA_LIST_FOREACH(sd->layouts, l, layout) 59 EINA_LIST_FOREACH(sd->layouts, l, layout)
60 { 60 {
61 evas_object_hide(layout); 61 evas_object_hide(layout);
@@ -65,7 +65,7 @@ _shrink_mode_set(Eo *obj,
65 65
66 if (sd->label && sd->label_packed) 66 if (sd->label && sd->label_packed)
67 { 67 {
68 elm_box_pack_end(sd->box, sd->label); 68 efl_pack(sd->box, sd->label);
69 Eina_Size2D label_min = 69 Eina_Size2D label_min =
70 efl_gfx_hint_size_combined_min_get(sd->label); 70 efl_gfx_hint_size_combined_min_get(sd->label);
71 w -= label_min.w; 71 w -= label_min.w;
@@ -79,7 +79,7 @@ _shrink_mode_set(Eo *obj,
79 { 79 {
80 Evas_Coord w_label_count = 0, h = 0; 80 Evas_Coord w_label_count = 0, h = 0;
81 81
82 elm_box_pack_end(sd->box, layout); 82 efl_pack(sd->box, layout);
83 evas_object_show(layout); 83 evas_object_show(layout);
84 84
85 Eina_Size2D item_min = 85 Eina_Size2D item_min =
@@ -107,7 +107,7 @@ _shrink_mode_set(Eo *obj,
107 if ((w < 0) || (w < w_label_count)) 107 if ((w < 0) || (w < w_label_count))
108 { 108 {
109 Eina_Strbuf *strbuf = eina_strbuf_new(); 109 Eina_Strbuf *strbuf = eina_strbuf_new();
110 elm_box_unpack(sd->box, layout); 110 efl_pack_unpack(sd->box, layout);
111 evas_object_hide(layout); 111 evas_object_hide(layout);
112 count++; 112 count++;
113 113
@@ -120,7 +120,7 @@ _shrink_mode_set(Eo *obj,
120 edje_object_size_min_calc(sd->end, &w_label_count, &h); 120 edje_object_size_min_calc(sd->end, &w_label_count, &h);
121 elm_coords_finger_size_adjust(1, &w_label_count, 1, &h); 121 elm_coords_finger_size_adjust(1, &w_label_count, 1, &h);
122 efl_gfx_hint_size_restricted_min_set(sd->end, EINA_SIZE2D(w_label_count, h)); 122 efl_gfx_hint_size_restricted_min_set(sd->end, EINA_SIZE2D(w_label_count, h));
123 elm_box_pack_end(sd->box, sd->end); 123 efl_pack(sd->box, sd->end);
124 evas_object_show(sd->end); 124 evas_object_show(sd->end);
125 125
126 break; 126 break;
@@ -139,7 +139,7 @@ _shrink_mode_set(Eo *obj,
139 else 139 else
140 { 140 {
141 // unpack all items and entry 141 // unpack all items and entry
142 elm_box_unpack_all(sd->box); 142 efl_pack_unpack_all(sd->box);
143 EINA_LIST_FOREACH(sd->layouts, l, layout) 143 EINA_LIST_FOREACH(sd->layouts, l, layout)
144 { 144 {
145 evas_object_hide(layout); 145 evas_object_hide(layout);
@@ -148,13 +148,13 @@ _shrink_mode_set(Eo *obj,
148 148
149 // pack buttons only 1line 149 // pack buttons only 1line
150 150
151 if (sd->label && sd->label_packed) elm_box_pack_end(sd->box, sd->label); 151 if (sd->label && sd->label_packed) efl_pack(sd->box, sd->label);
152 152
153 // pack remain btns 153 // pack remain btns
154 layout = NULL; 154 layout = NULL;
155 EINA_LIST_FOREACH(sd->layouts, l, layout) 155 EINA_LIST_FOREACH(sd->layouts, l, layout)
156 { 156 {
157 elm_box_pack_end(sd->box, layout); 157 efl_pack(sd->box, layout);
158 evas_object_show(layout); 158 evas_object_show(layout);
159 } 159 }
160 160
@@ -338,7 +338,7 @@ _on_item_deleted(void *data,
338 if (item == obj) 338 if (item == obj)
339 { 339 {
340 sd->layouts = eina_list_remove(sd->layouts, item); 340 sd->layouts = eina_list_remove(sd->layouts, item);
341 elm_box_unpack(sd->box, item); 341 efl_pack_unpack(sd->box, item);
342 342
343 if (sd->selected_it == item) 343 if (sd->selected_it == item)
344 sd->selected_it = NULL; 344 sd->selected_it = NULL;
@@ -440,9 +440,9 @@ _item_new(Efl_Ui_Tags_Data *sd,
440 else 440 else
441 { 441 {
442 if (sd->editable) 442 if (sd->editable)
443 elm_box_pack_before(sd->box, layout, sd->entry); 443 efl_pack_before(sd->box, layout, sd->entry);
444 else 444 else
445 elm_box_pack_end(sd->box, layout); 445 efl_pack(sd->box, layout);
446 } 446 }
447 447
448 if (!efl_ui_focus_object_focus_get(obj) && sd->view_state == TAGS_VIEW_SHRINK && sd->w_box) 448 if (!efl_ui_focus_object_focus_get(obj) && sd->view_state == TAGS_VIEW_SHRINK && sd->w_box)
@@ -487,14 +487,14 @@ _box_resize_cb(void *data,
487 Eina_Rect r; 487 Eina_Rect r;
488 Eina_List *l; 488 Eina_List *l;
489 Eo *layout; 489 Eo *layout;
490 int hpad; 490 double hpad;
491 491
492 Efl_Ui_Tags_Data *sd = efl_data_scope_get(data, EFL_UI_TAGS_CLASS); 492 Efl_Ui_Tags_Data *sd = efl_data_scope_get(data, EFL_UI_TAGS_CLASS);
493 493
494 r = efl_gfx_entity_geometry_get(sd->box); 494 r = efl_gfx_entity_geometry_get(sd->box);
495 if ((r.w <= elm_config_finger_size_get()) || (r.h <= elm_config_finger_size_get())) return; 495 if ((r.w <= elm_config_finger_size_get()) || (r.h <= elm_config_finger_size_get())) return;
496 496
497 elm_box_padding_get(obj, &hpad, NULL); 497 efl_gfx_arrangement_content_padding_get(obj, &hpad, NULL, NULL);
498 498
499 if (sd->h_box < r.h) 499 if (sd->h_box < r.h)
500 efl_event_callback_call 500 efl_event_callback_call
@@ -710,180 +710,35 @@ _label_set(Evas_Object *obj,
710 if (!strlen(str)) 710 if (!strlen(str))
711 { 711 {
712 sd->label_packed = EINA_FALSE; 712 sd->label_packed = EINA_FALSE;
713 elm_box_unpack(sd->box, sd->label); 713 efl_pack_unpack(sd->box, sd->label);
714 evas_object_hide(sd->label); 714 evas_object_hide(sd->label);
715 } 715 }
716 else 716 else
717 { 717 {
718 if (sd->label_packed) 718 if (sd->label_packed)
719 elm_box_unpack(sd->box, sd->label); 719 efl_pack_unpack(sd->box, sd->label);
720 sd->label_packed = EINA_TRUE; 720 sd->label_packed = EINA_TRUE;
721 edje_object_size_min_calc(sd->label, &width, &height); 721 edje_object_size_min_calc(sd->label, &width, &height);
722 evas_object_size_hint_min_set(sd->label, width, height); 722 evas_object_size_hint_min_set(sd->label, width, height);
723 elm_box_pack_start(sd->box, sd->label); 723 efl_pack_begin(sd->box, sd->label);
724 evas_object_show(sd->label); 724 evas_object_show(sd->label);
725 } 725 }
726 726
727 _view_update(sd); 727 _view_update(sd);
728} 728}
729 729
730static Eina_Bool
731_box_min_size_calculate(Evas_Object *box,
732 Evas_Object_Box_Data *priv,
733 int *line_height,
734 void *data EINA_UNUSED)
735{
736 Evas_Coord w, linew = 0, lineh = 0;
737 Eina_Size2D box_min;
738 Eina_Size2D min;
739 int line_num;
740 Eina_List *l;
741 Evas_Object_Box_Option *opt;
742
743 evas_object_geometry_get(box, NULL, NULL, &w, NULL);
744 box_min = efl_gfx_hint_size_combined_min_get(box);
745
746 if (!w) return EINA_FALSE;
747
748 line_num = 1;
749 EINA_LIST_FOREACH(priv->children, l, opt)
750 {
751 min = efl_gfx_hint_size_combined_min_get(opt->obj);
752
753 linew += min.w;
754 if (lineh < min.h) lineh = min.h;
755
756 if (linew > w)
757 {
758 linew = min.w;
759 line_num++;
760 }
761
762 if ((linew != 0) && (l != eina_list_last(priv->children)))
763 linew += priv->pad.h;
764 }
765 box_min.h = lineh * line_num + (line_num - 1) * priv->pad.v;
766
767 efl_gfx_hint_size_restricted_min_set(box, EINA_SIZE2D(box_min.w, box_min.h));
768 *line_height = lineh;
769
770 return EINA_TRUE;
771}
772
773static void
774_box_layout_cb(Evas_Object *o,
775 Evas_Object_Box_Data *priv,
776 void *data)
777{
778 Evas_Coord xx, yy;
779 Eina_Rect r;
780 Evas_Coord linew = 0, lineh = 0;
781 Eina_Size2D min;
782 Evas_Object_Box_Option *opt;
783 const Eina_List *l, *l_next;
784 Evas_Object *obj;
785 double ax, ay;
786 Eina_Bool rtl;
787
788 if (!_box_min_size_calculate(o, priv, &lineh, data)) return;
789
790 r = efl_gfx_entity_geometry_get(o);
791
792 min = efl_gfx_hint_size_combined_min_get(o);
793 efl_gfx_hint_align_get(o, &ax, &ay);
794
795 rtl = efl_ui_mirrored_get(data);
796 if (rtl) ax = 1.0 - ax;
797
798 if (r.w < min.w)
799 {
800 r.x = r.x + ((r.w - min.w) * (1.0 - ax));
801 r.w = min.w;
802 }
803 if (r.h < min.h)
804 {
805 r.y = r.y + ((r.h - min.h) * (1.0 - ay));
806 r.h = min.h;
807 }
808
809 xx = r.x;
810 yy = r.y;
811
812 EINA_LIST_FOREACH_SAFE(priv->children, l, l_next, opt)
813 {
814 Eina_Size2D obj_min;
815 Evas_Coord ww, hh, ow, oh;
816 double wx, wy;
817 Eina_Bool fx, fy;
818
819 obj = opt->obj;
820 evas_object_size_hint_align_get(obj, &ax, &ay);
821 evas_object_size_hint_weight_get(obj, &wx, &wy);
822 efl_gfx_hint_fill_get(obj, &fx, &fy);
823 obj_min = efl_gfx_hint_size_combined_min_get(obj);
824
825 if (EINA_DBL_EQ(ax, -1)) { fx = 1; ax = 0.5; }
826 else if (ax < 0) { ax = 0.0; }
827 if (EINA_DBL_EQ(ay, -1)) { fy = 1; ay = 0.5; }
828 else if (ay < 0) { ay = 0.0; }
829 if (rtl) ax = 1.0 - ax;
830
831 ww = obj_min.w;
832 if (!EINA_DBL_EQ(wx, 0))
833 {
834 if (ww <= r.w - linew) ww = r.w - linew;
835 else ww = r.w;
836 }
837 hh = lineh;
838
839 ow = obj_min.w;
840 if (fx) ow = ww;
841 oh = obj_min.h;
842 if (fy) oh = hh;
843
844 linew += ww;
845 if (linew > r.w && l != priv->children)
846 {
847 xx = r.x;
848 yy += hh;
849 yy += priv->pad.v;
850 linew = ww;
851 }
852
853 evas_object_geometry_set(obj,
854 ((!rtl) ? (xx) : (r.x + (r.w - (xx - r.x) - ww)))
855 + (Evas_Coord)(((double)(ww - ow)) * ax),
856 yy + (Evas_Coord)(((double)(hh - oh)) * ay),
857 ow, oh);
858 xx += ww;
859 xx += priv->pad.h;
860
861 if (linew > r.w)
862 {
863 opt = eina_list_data_get(l_next);
864 if (opt && opt->obj && efl_isa(opt->obj, ELM_ENTRY_CLASS))
865 {
866 xx = r.x;
867 yy += hh;
868 yy += priv->pad.v;
869 linew = 0;
870 }
871 }
872 if ((linew != 0) && (l != eina_list_last(priv->children)))
873 linew += priv->pad.h;
874 }
875}
876
877static void 730static void
878_view_init(Evas_Object *obj, Efl_Ui_Tags_Data *sd) 731_view_init(Evas_Object *obj, Efl_Ui_Tags_Data *sd)
879{ 732{
880 const char *str; 733 const char *str;
881 double pad_scale;
882 int hpad = 0, vpad = 0; 734 int hpad = 0, vpad = 0;
883 735
884 //FIXME: efl_ui_box doesn't support box_layout customizing. 736 //FIXME: efl_ui_box doesn't support box_layout customizing.
885 // So i use legacy box here. 737 // So i use legacy box here.
886 sd->box = elm_box_add(obj); 738 sd->box = efl_add(EFL_UI_BOX_FLOW_CLASS, obj,
739 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
740 efl_gfx_arrangement_content_align_set(efl_added, 0, 0),
741 efl_gfx_hint_align_set(efl_added, 0, 0));
887 742
888 if (!sd->box) return; 743 if (!sd->box) return;
889 744
@@ -891,13 +746,9 @@ _view_init(Evas_Object *obj, Efl_Ui_Tags_Data *sd)
891 if (str) hpad = atoi(str); 746 if (str) hpad = atoi(str);
892 str = elm_layout_data_get(obj, "vertical_pad"); 747 str = elm_layout_data_get(obj, "vertical_pad");
893 if (str) vpad = atoi(str); 748 if (str) vpad = atoi(str);
894 pad_scale = efl_gfx_entity_scale_get(obj) * elm_config_scale_get() 749 efl_gfx_arrangement_content_padding_set(sd->box, hpad, vpad, EINA_TRUE);
895 / edje_object_base_scale_get(elm_layout_edje_get(obj));
896 elm_box_padding_set(sd->box, (hpad * pad_scale), (vpad * pad_scale));
897 750
898 elm_box_layout_set(sd->box, _box_layout_cb, obj, NULL); 751 efl_content_set(efl_part(obj, "efl.box"), sd->box);
899 elm_box_homogeneous_set(sd->box, EINA_FALSE);
900 elm_layout_content_set(obj, "efl.box", sd->box);
901 752
902 sd->label = edje_object_add(evas_object_evas_get(obj)); 753 sd->label = edje_object_add(evas_object_evas_get(obj));
903 if (!sd->label) return; 754 if (!sd->label) return;
@@ -912,11 +763,10 @@ _view_init(Evas_Object *obj, Efl_Ui_Tags_Data *sd)
912 efl_composite_attach(obj, efl_added)); 763 efl_composite_attach(obj, efl_added));
913 764
914 efl_gfx_hint_size_restricted_min_set(sd->entry, EINA_SIZE2D(MIN_W_ENTRY, 0)); 765 efl_gfx_hint_size_restricted_min_set(sd->entry, EINA_SIZE2D(MIN_W_ENTRY, 0));
915 evas_object_size_hint_weight_set 766 efl_gfx_hint_weight_set(sd->entry, EFL_GFX_HINT_EXPAND, 0);
916 (sd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 767 efl_gfx_hint_fill_set(sd->entry, EINA_TRUE, EINA_FALSE);
917 efl_gfx_hint_fill_set(sd->entry, EINA_TRUE, EINA_TRUE);
918 768
919 elm_box_pack_end(sd->box, sd->entry); 769 efl_pack(sd->box, sd->entry);
920 770
921 sd->view_state = TAGS_VIEW_ENTRY; 771 sd->view_state = TAGS_VIEW_ENTRY;
922 772
@@ -1067,12 +917,12 @@ _efl_ui_tags_editable_set(Eo *obj EINA_UNUSED, Efl_Ui_Tags_Data *sd, Eina_Bool e
1067 917
1068 if (sd->editable && (sd->view_state != TAGS_VIEW_SHRINK)) 918 if (sd->editable && (sd->view_state != TAGS_VIEW_SHRINK))
1069 { 919 {
1070 elm_box_pack_end(sd->box, sd->entry); 920 efl_pack(sd->box, sd->entry);
1071 evas_object_show(sd->entry); 921 evas_object_show(sd->entry);
1072 } 922 }
1073 else 923 else
1074 { 924 {
1075 elm_box_unpack(sd->box, sd->entry); 925 efl_pack_unpack(sd->box, sd->entry);
1076 evas_object_hide(sd->entry); 926 evas_object_hide(sd->entry);
1077 } 927 }
1078} 928}