summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2017-07-26 16:23:09 +0900
committerThiep Ha <thiepha@gmail.com>2017-07-26 16:23:09 +0900
commit746e0f62c48510885ce8b9fd52337542a26d478d (patch)
tree27f139d3cedf2cc2993e50723382e9871e6757ba
parent2330d4fec110cb94043547e4979308283e442350 (diff)
add aspect size hint to ui.box: on going
-rw-r--r--src/bin/elementary/test_ui_box.c1
-rw-r--r--src/examples/elementary/button_example_00.c12
-rw-r--r--src/examples/elementary/layout_example_01.c34
-rw-r--r--src/lib/elementary/efl_ui_box_layout.c139
4 files changed, 182 insertions, 4 deletions
diff --git a/src/bin/elementary/test_ui_box.c b/src/bin/elementary/test_ui_box.c
index beeb7318c0..6f3ac05f09 100644
--- a/src/bin/elementary/test_ui_box.c
+++ b/src/bin/elementary/test_ui_box.c
@@ -499,6 +499,7 @@ test_ui_box(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
499 objects[i++] = o = elm_button_add(win); 499 objects[i++] = o = elm_button_add(win);
500 elm_object_text_set(o, "Button 2"); 500 elm_object_text_set(o, "Button 2");
501 efl_gfx_size_hint_align_set(o, -1, -1); 501 efl_gfx_size_hint_align_set(o, -1, -1);
502 efl_gfx_size_hint_aspect_set(o, EFL_GFX_SIZE_HINT_ASPECT_BOTH, 2, 1);
502 efl_pack(bx, o); 503 efl_pack(bx, o);
503 efl_gfx_visible_set(o, 1); 504 efl_gfx_visible_set(o, 1);
504 505
diff --git a/src/examples/elementary/button_example_00.c b/src/examples/elementary/button_example_00.c
index 7ac2df69e7..3bf443bd52 100644
--- a/src/examples/elementary/button_example_00.c
+++ b/src/examples/elementary/button_example_00.c
@@ -7,7 +7,13 @@ static void
7on_click(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 7on_click(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
8 void *event_info EINA_UNUSED) 8 void *event_info EINA_UNUSED)
9{ 9{
10 elm_exit(); 10 //elm_exit();
11}
12
13static void
14_button_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
15{
16 printf("%s %d: clicked by edje\n\n", __func__, __LINE__);
11} 17}
12 18
13EAPI_MAIN int 19EAPI_MAIN int
@@ -32,6 +38,10 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
32 evas_object_move(btn, 60, 15); 38 evas_object_move(btn, 60, 15);
33 evas_object_show(btn); 39 evas_object_show(btn);
34 40
41 //elm_object_signal_callback_add(btn, "elm,action,click", "*",
42 edje_object_signal_callback_add(elm_layout_edje_get(btn), "elm,action,click", "*",
43 _button_clicked_cb, btn);
44
35 evas_object_resize(win, 240, 60); 45 evas_object_resize(win, 240, 60);
36 evas_object_show(win); 46 evas_object_show(win);
37 47
diff --git a/src/examples/elementary/layout_example_01.c b/src/examples/elementary/layout_example_01.c
index 48bd3ad5a6..543f0f25e0 100644
--- a/src/examples/elementary/layout_example_01.c
+++ b/src/examples/elementary/layout_example_01.c
@@ -66,8 +66,12 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
66 // Adding layout and filling it with widgets 66 // Adding layout and filling it with widgets
67 layout = elm_layout_add(win); 67 layout = elm_layout_add(win);
68 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 68 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69 elm_win_resize_object_add(win, layout); 69 //elm_win_resize_object_add(win, layout);
70 snprintf(buf, sizeof(buf), "%s/examples/layout_example.edj", elm_app_data_dir_get()); 70 //evas_object_resize(layout, 100, 100);
71 evas_object_size_hint_min_set(layout, 100, 100);
72 evas_object_move(layout, 0, 0);
73 //snprintf(buf, sizeof(buf), "%s/examples/layout_example.edj", elm_app_data_dir_get());
74 snprintf(buf, sizeof(buf), "%s/layout_example.edj", ".");
71 elm_layout_file_set(layout, buf, "example/mylayout"); 75 elm_layout_file_set(layout, buf, "example/mylayout");
72 evas_object_show(layout); 76 evas_object_show(layout);
73 77
@@ -129,6 +133,32 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
129 elm_object_part_content_set(layout, SWALLOW, bt2); 133 elm_object_part_content_set(layout, SWALLOW, bt2);
130 evas_object_smart_callback_add(bt2, "clicked", _swallow_btn_cb, layout); 134 evas_object_smart_callback_add(bt2, "clicked", _swallow_btn_cb, layout);
131 135
136
137 //proxy of layout: OK
138 //proxy of mapped object: No
139 Evas_Object *proxy = evas_object_image_filled_add(evas_object_evas_get(layout));
140 //Evas_Object *proxy = evas_object_image_add(evas_object_evas_get(layout)); //must be filled image
141 evas_object_image_source_set(proxy, layout);
142 evas_object_resize(proxy, 100, 100);
143 evas_object_move(proxy, 200, 200);
144 evas_object_show(proxy);
145
146 //map of layout: OK
147 Evas_Coord x, y, w, h;
148 evas_object_geometry_get(layout, &x, &y, &w, &h);
149 printf("layout geo: %d %d %d %d\n", x, y, w, h);
150 Evas_Map *m = evas_map_new(4);
151 evas_map_point_coord_set(m, 0, 100, 100, 0);
152 evas_map_point_coord_set(m, 1, 200, 100, 0);
153 evas_map_point_coord_set(m, 2, 100, 200, 0);
154 evas_map_point_coord_set(m, 3, 0, 200, 0);
155 evas_map_point_image_uv_set(m, 0, 0, 0);
156 evas_map_point_image_uv_set(m, 1, 100, 0);
157 evas_map_point_image_uv_set(m, 2, 100, 100);
158 evas_map_point_image_uv_set(m, 3, 0, 100);
159 evas_object_map_enable_set(layout, EINA_TRUE);
160 evas_object_map_set(layout, m);
161
132 evas_object_resize(win, 320, 320); 162 evas_object_resize(win, 320, 320);
133 evas_object_show(win); 163 evas_object_show(win);
134 164
diff --git a/src/lib/elementary/efl_ui_box_layout.c b/src/lib/elementary/efl_ui_box_layout.c
index bb41a8d268..cdd1a50353 100644
--- a/src/lib/elementary/efl_ui_box_layout.c
+++ b/src/lib/elementary/efl_ui_box_layout.c
@@ -15,6 +15,9 @@ struct _Item_Calc
15 int max[2]; 15 int max[2];
16 int pad[4]; 16 int pad[4];
17 int want[2]; 17 int want[2];
18 Efl_Gfx_Size_Hint_Aspect aspect;
19 int aw, ah;
20 int min[2];
18 int id; 21 int id;
19}; 22};
20 23
@@ -77,6 +80,23 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
77 efl_gfx_size_hint_margin_get(o, &item->pad[0], &item->pad[1], &item->pad[2], &item->pad[3]); 80 efl_gfx_size_hint_margin_get(o, &item->pad[0], &item->pad[1], &item->pad[2], &item->pad[3]);
78 efl_gfx_size_hint_max_get(o, &item->max[0], &item->max[1]); 81 efl_gfx_size_hint_max_get(o, &item->max[0], &item->max[1]);
79 efl_gfx_size_hint_combined_min_get(o, &item->want[0], &item->want[1]); 82 efl_gfx_size_hint_combined_min_get(o, &item->want[0], &item->want[1]);
83 efl_gfx_size_hint_aspect_get(o, &item->aspect, &item->aw, &item->ah);
84 efl_gfx_size_hint_min_get(0, &item->min[0], &item->min[1]);
85 if (item->aw == 0 || item->ah == 0)
86 {
87 item->aw = item->ah = 0;
88 item->aspect = EFL_GFX_SIZE_HINT_ASPECT_NONE;
89 }
90
91 //aspect ratio support
92 //lam sao de tinh chi tinh min + van support aspect ratio???
93 //if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL ||
94 // item->aspect == EFL_GFX_SIZE_HINT_ASPECT_BOTH)
95 {
96 int minh = item->want[0] * item->ah / item->aw;
97 if (item->want[1] < minh)
98 item->want[1] = minh;
99 }
80 100
81 if (item->weight[0] < 0) item->weight[0] = 0; 101 if (item->weight[0] < 0) item->weight[0] = 0;
82 if (item->weight[1] < 0) item->weight[1] = 0; 102 if (item->weight[1] < 0) item->weight[1] = 0;
@@ -121,6 +141,60 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
121 boxx += boxl; 141 boxx += boxl;
122 boxy += boxt; 142 boxy += boxt;
123 143
144
145 //support aspect ratio
146 /*id = 0;
147 WRN("before: wantw: %d, wanth: %d", wantw, wanth);
148 EINA_LIST_FOREACH(bd->children, li, opt)
149 {
150 item = &items[id];
151 if (horiz)
152 {
153 wantw -= item->want[0];
154 if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL)
155 {
156 //item->want[0] = item->min[0];
157 item->want[1] = item->want[0] * item->aw / item->ah;
158 }
159 else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_VERTICAL)
160 {
161 item->want[1] = wanth;
162 item->want[0] = wanth * item->aw / item->ah;
163 }
164 else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_BOTH)
165 {
166 item->want[1] = wanth;
167 item->want[0] = wanth * item->aw / item->ah;
168 }
169 wantw += item->want[0];
170 }
171 else
172 {
173 wanth -= item->want[1];
174 if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL)
175 {
176 item->want[0] = wantw;
177 item->want[1] = wantw * item->ah / item->aw;
178 }
179 else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_VERTICAL)
180 {
181 //item->want[1] = item->min[1];
182 item->want[0] = item->want[1] * item->aw / item->ah;
183 }
184 else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_BOTH)
185 {
186 item->want[0] = wantw;
187 item->want[1] = wantw * item->ah / item->ah;
188 }
189 wanth += item->want[1];
190 }
191
192 id++;
193 }
194 WRN("after: wantw: %d, wanth: %d", wantw, wanth);
195 */
196 //////
197
124 // total space & available space 198 // total space & available space
125 if (horiz) 199 if (horiz)
126 { 200 {
@@ -141,6 +215,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
141 // available space. if <0 we overflow 215 // available space. if <0 we overflow
142 extra = length - want; 216 extra = length - want;
143 217
218 /*
144 if (horiz) 219 if (horiz)
145 { 220 {
146 evas_object_size_hint_min_set(ui_box, 221 evas_object_size_hint_min_set(ui_box,
@@ -152,7 +227,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
152 evas_object_size_hint_min_set(ui_box, 227 evas_object_size_hint_min_set(ui_box,
153 wantw + boxl + boxr, 228 wantw + boxl + boxr,
154 wanth + pad * (count - 1) + boxt + boxb); 229 wanth + pad * (count - 1) + boxt + boxb);
155 } 230 }*/
156 231
157 if (extra < 0) extra = 0; 232 if (extra < 0) extra = 0;
158 233
@@ -171,6 +246,40 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
171 weight[!horiz] = count; 246 weight[!horiz] = count;
172 } 247 }
173 248
249 double cx, cy, cw, ch, x, y, w, h;
250 //work on items having aspect ratio first
251 for (id = 0; id < count; id++)
252 {
253 item = &items[id];
254 if (item->aspect)
255 {
256 if (horiz)
257 {
258 ch = boxh;
259 if (ch > item->max[1])
260 ch = item->max[1];
261 cw = ch * item->aw / item->ah;
262 if (cw > item->max[0])
263 {
264 cw = item->max[0];
265 ch = cw * item->ah / item->aw;
266 }
267 }
268 else
269 {
270 cw = boxw;
271 if (cw > item->max[0])
272 cw = item->max[0];
273 ch = cw * item->ah / item->aw;
274 if (ch > item->max[1])
275 {
276 ch = item->max[1];
277 cw = ch * item->aw / item->ah;
278 }
279 }
280 }
281 }
282
174 for (id = 0; id < count; id++) 283 for (id = 0; id < count; id++)
175 { 284 {
176 double cx, cy, cw, ch, x, y, w, h; 285 double cx, cy, cw, ch, x, y, w, h;
@@ -220,6 +329,14 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
220 w = item->want[0] - item->pad[0] - item->pad[1]; 329 w = item->want[0] - item->pad[0] - item->pad[1];
221 x = cx + ((cw - w) * item->align[0]) + item->pad[0]; 330 x = cx + ((cw - w) * item->align[0]) + item->pad[0];
222 } 331 }
332 //aspect ratio
333 if (item->aspect)
334 {
335 h = w * item->ah / item->aw;
336 if (h > wanth)
337 wanth = h;
338 }
339 /////
223 340
224 // vertically 341 // vertically
225 if (item->max[1] < INT_MAX) 342 if (item->max[1] < INT_MAX)
@@ -244,9 +361,29 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd)
244 h = item->want[1] - item->pad[2] - item->pad[3]; 361 h = item->want[1] - item->pad[2] - item->pad[3];
245 y = cy + ((ch - h) * item->align[1]) + item->pad[2]; 362 y = cy + ((ch - h) * item->align[1]) + item->pad[2];
246 } 363 }
364 if (item->aspect)
365 {
366 w = h * item->aw / item->ah;
367 cur_pos = cur_pos - cw + w;
368 if (w > wantw)
369 wantw = w;
370 }
247 371
248 //DBG("[%2d/%2d] cell: %.0f,%.0f %.0fx%.0f item: %.0f,%.0f %.0fx%.0f", 372 //DBG("[%2d/%2d] cell: %.0f,%.0f %.0fx%.0f item: %.0f,%.0f %.0fx%.0f",
249 // id, count, cx, cy, cw, ch, x, y, w, h); 373 // id, count, cx, cy, cw, ch, x, y, w, h);
250 evas_object_geometry_set(item->obj, x, y, w, h); 374 evas_object_geometry_set(item->obj, x, y, w, h);
251 } 375 }
376
377 if (horiz)
378 {
379 evas_object_size_hint_min_set(ui_box,
380 wantw + boxl + boxr + pad * (count - 1),
381 wanth + boxt + boxb);
382 }
383 else
384 {
385 evas_object_size_hint_min_set(ui_box,
386 wantw + boxl + boxr,
387 wanth + pad * (count - 1) + boxt + boxb);
388 }
252} 389}