diff options
author | Thiep Ha <thiepha@gmail.com> | 2017-07-26 16:23:09 +0900 |
---|---|---|
committer | Thiep Ha <thiepha@gmail.com> | 2017-07-26 16:23:09 +0900 |
commit | 746e0f62c48510885ce8b9fd52337542a26d478d (patch) | |
tree | 27f139d3cedf2cc2993e50723382e9871e6757ba | |
parent | 2330d4fec110cb94043547e4979308283e442350 (diff) | |
download | efl-746e0f62c48510885ce8b9fd52337542a26d478d.tar.gz |
add aspect size hint to ui.box: on going
-rw-r--r-- | src/bin/elementary/test_ui_box.c | 1 | ||||
-rw-r--r-- | src/examples/elementary/button_example_00.c | 12 | ||||
-rw-r--r-- | src/examples/elementary/layout_example_01.c | 34 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_box_layout.c | 139 |
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 objects[i++] = o = elm_button_add(win); elm_object_text_set(o, "Button 2"); efl_gfx_size_hint_align_set(o, -1, -1); + efl_gfx_size_hint_aspect_set(o, EFL_GFX_SIZE_HINT_ASPECT_BOTH, 2, 1); efl_pack(bx, o); efl_gfx_visible_set(o, 1); 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 on_click(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - elm_exit(); + //elm_exit(); +} + +static void +_button_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source) +{ + printf("%s %d: clicked by edje\n\n", __func__, __LINE__); } EAPI_MAIN int @@ -32,6 +38,10 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) evas_object_move(btn, 60, 15); evas_object_show(btn); + //elm_object_signal_callback_add(btn, "elm,action,click", "*", + edje_object_signal_callback_add(elm_layout_edje_get(btn), "elm,action,click", "*", + _button_clicked_cb, btn); + evas_object_resize(win, 240, 60); evas_object_show(win); 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) // Adding layout and filling it with widgets layout = elm_layout_add(win); evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, layout); - snprintf(buf, sizeof(buf), "%s/examples/layout_example.edj", elm_app_data_dir_get()); + //elm_win_resize_object_add(win, layout); + //evas_object_resize(layout, 100, 100); + evas_object_size_hint_min_set(layout, 100, 100); + evas_object_move(layout, 0, 0); + //snprintf(buf, sizeof(buf), "%s/examples/layout_example.edj", elm_app_data_dir_get()); + snprintf(buf, sizeof(buf), "%s/layout_example.edj", "."); elm_layout_file_set(layout, buf, "example/mylayout"); evas_object_show(layout); @@ -129,6 +133,32 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) elm_object_part_content_set(layout, SWALLOW, bt2); evas_object_smart_callback_add(bt2, "clicked", _swallow_btn_cb, layout); + + //proxy of layout: OK + //proxy of mapped object: No + Evas_Object *proxy = evas_object_image_filled_add(evas_object_evas_get(layout)); + //Evas_Object *proxy = evas_object_image_add(evas_object_evas_get(layout)); //must be filled image + evas_object_image_source_set(proxy, layout); + evas_object_resize(proxy, 100, 100); + evas_object_move(proxy, 200, 200); + evas_object_show(proxy); + + //map of layout: OK + Evas_Coord x, y, w, h; + evas_object_geometry_get(layout, &x, &y, &w, &h); + printf("layout geo: %d %d %d %d\n", x, y, w, h); + Evas_Map *m = evas_map_new(4); + evas_map_point_coord_set(m, 0, 100, 100, 0); + evas_map_point_coord_set(m, 1, 200, 100, 0); + evas_map_point_coord_set(m, 2, 100, 200, 0); + evas_map_point_coord_set(m, 3, 0, 200, 0); + evas_map_point_image_uv_set(m, 0, 0, 0); + evas_map_point_image_uv_set(m, 1, 100, 0); + evas_map_point_image_uv_set(m, 2, 100, 100); + evas_map_point_image_uv_set(m, 3, 0, 100); + evas_object_map_enable_set(layout, EINA_TRUE); + evas_object_map_set(layout, m); + evas_object_resize(win, 320, 320); evas_object_show(win); 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 int max[2]; int pad[4]; int want[2]; + Efl_Gfx_Size_Hint_Aspect aspect; + int aw, ah; + int min[2]; int id; }; @@ -77,6 +80,23 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd) efl_gfx_size_hint_margin_get(o, &item->pad[0], &item->pad[1], &item->pad[2], &item->pad[3]); efl_gfx_size_hint_max_get(o, &item->max[0], &item->max[1]); efl_gfx_size_hint_combined_min_get(o, &item->want[0], &item->want[1]); + efl_gfx_size_hint_aspect_get(o, &item->aspect, &item->aw, &item->ah); + efl_gfx_size_hint_min_get(0, &item->min[0], &item->min[1]); + if (item->aw == 0 || item->ah == 0) + { + item->aw = item->ah = 0; + item->aspect = EFL_GFX_SIZE_HINT_ASPECT_NONE; + } + + //aspect ratio support + //lam sao de tinh chi tinh min + van support aspect ratio??? + //if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL || + // item->aspect == EFL_GFX_SIZE_HINT_ASPECT_BOTH) + { + int minh = item->want[0] * item->ah / item->aw; + if (item->want[1] < minh) + item->want[1] = minh; + } if (item->weight[0] < 0) item->weight[0] = 0; 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) boxx += boxl; boxy += boxt; + + //support aspect ratio + /*id = 0; + WRN("before: wantw: %d, wanth: %d", wantw, wanth); + EINA_LIST_FOREACH(bd->children, li, opt) + { + item = &items[id]; + if (horiz) + { + wantw -= item->want[0]; + if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL) + { + //item->want[0] = item->min[0]; + item->want[1] = item->want[0] * item->aw / item->ah; + } + else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_VERTICAL) + { + item->want[1] = wanth; + item->want[0] = wanth * item->aw / item->ah; + } + else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_BOTH) + { + item->want[1] = wanth; + item->want[0] = wanth * item->aw / item->ah; + } + wantw += item->want[0]; + } + else + { + wanth -= item->want[1]; + if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL) + { + item->want[0] = wantw; + item->want[1] = wantw * item->ah / item->aw; + } + else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_VERTICAL) + { + //item->want[1] = item->min[1]; + item->want[0] = item->want[1] * item->aw / item->ah; + } + else if (item->aspect == EFL_GFX_SIZE_HINT_ASPECT_BOTH) + { + item->want[0] = wantw; + item->want[1] = wantw * item->ah / item->ah; + } + wanth += item->want[1]; + } + + id++; + } + WRN("after: wantw: %d, wanth: %d", wantw, wanth); + */ + ////// + // total space & available space if (horiz) { @@ -141,6 +215,7 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd) // available space. if <0 we overflow extra = length - want; + /* if (horiz) { 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) evas_object_size_hint_min_set(ui_box, wantw + boxl + boxr, wanth + pad * (count - 1) + boxt + boxb); - } + }*/ if (extra < 0) extra = 0; @@ -171,6 +246,40 @@ _efl_ui_box_custom_layout(Efl_Ui_Box *ui_box, Evas_Object_Box_Data *bd) weight[!horiz] = count; } + double cx, cy, cw, ch, x, y, w, h; + //work on items having aspect ratio first + for (id = 0; id < count; id++) + { + item = &items[id]; + if (item->aspect) + { + if (horiz) + { + ch = boxh; + if (ch > item->max[1]) + ch = item->max[1]; + cw = ch * item->aw / item->ah; + if (cw > item->max[0]) + { + cw = item->max[0]; + ch = cw * item->ah / item->aw; + } + } + else + { + cw = boxw; + if (cw > item->max[0]) + cw = item->max[0]; + ch = cw * item->ah / item->aw; + if (ch > item->max[1]) + { + ch = item->max[1]; + cw = ch * item->aw / item->ah; + } + } + } + } + for (id = 0; id < count; id++) { 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) w = item->want[0] - item->pad[0] - item->pad[1]; x = cx + ((cw - w) * item->align[0]) + item->pad[0]; } + //aspect ratio + if (item->aspect) + { + h = w * item->ah / item->aw; + if (h > wanth) + wanth = h; + } + ///// // vertically 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) h = item->want[1] - item->pad[2] - item->pad[3]; y = cy + ((ch - h) * item->align[1]) + item->pad[2]; } + if (item->aspect) + { + w = h * item->aw / item->ah; + cur_pos = cur_pos - cw + w; + if (w > wantw) + wantw = w; + } //DBG("[%2d/%2d] cell: %.0f,%.0f %.0fx%.0f item: %.0f,%.0f %.0fx%.0f", // id, count, cx, cy, cw, ch, x, y, w, h); evas_object_geometry_set(item->obj, x, y, w, h); } + + if (horiz) + { + evas_object_size_hint_min_set(ui_box, + wantw + boxl + boxr + pad * (count - 1), + wanth + boxt + boxb); + } + else + { + evas_object_size_hint_min_set(ui_box, + wantw + boxl + boxr, + wanth + pad * (count - 1) + boxt + boxb); + } } |