From 40e23ca4593358574b2d9cfb62873fda7dce1c1c Mon Sep 17 00:00:00 2001 From: Sungtaek Hong Date: Tue, 19 Sep 2017 17:32:09 +0900 Subject: [PATCH] efl_ui_image: add new scale type: EFL_UI_IMAGE_SCALE_TYPE_TILE Summary: Tile is common type which can be used eg: background. This is added to scale type which can be set/get by efl_ui_image_scale_type_set/get() @feature Test Plan: Run elementary test Run Image Scale Type Check radio "Tile". Reviewers: jpeg, cedric, woohyun Differential Revision: https://phab.enlightenment.org/D5119 --- src/bin/elementary/test.c | 2 + src/bin/elementary/test_image.c | 75 ++++++++++++++++++++++++++++++ src/lib/elementary/efl_ui_image.c | 31 +++++++----- src/lib/elementary/efl_ui_image.eo | 1 + 4 files changed, 97 insertions(+), 12 deletions(-) diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c index 93282b5b02..87bd979330 100644 --- a/src/bin/elementary/test.c +++ b/src/bin/elementary/test.c @@ -272,6 +272,7 @@ void test_ui_clock(void *data, Evas_Object *obj, void *event_info); void test_popup(void *data, Evas_Object *obj, void *event_info); void test_dayselector(void *data, Evas_Object *obj, void *event_info); void test_image(void *data, Evas_Object *obj, void *event_info); +void test_image_scale_type(void *data, Evas_Object *obj, void *event_info); void test_image_swallow_align(void *data, Evas_Object *obj, void *event_info); void test_remote_image(void *data, Evas_Object *obj, void *event_info); void test_click_image(void *data, Evas_Object *obj, void *event_info); @@ -688,6 +689,7 @@ add_tests: ADD_TEST(NULL, "Images", "Photo", test_photo); ADD_TEST(NULL, "Images", "Thumb", test_thumb); ADD_TEST(NULL, "Images", "Image", test_image); + ADD_TEST(NULL, "Images", "Image Scale Type", test_image_scale_type); ADD_TEST(NULL, "Images", "Image Align", test_image_swallow_align); ADD_TEST(NULL, "Images", "Image Remote", test_remote_image); ADD_TEST(NULL, "Images", "Image Click", test_click_image); diff --git a/src/bin/elementary/test_image.c b/src/bin/elementary/test_image.c index 922a8a98fe..8f4f2e9c4b 100644 --- a/src/bin/elementary/test_image.c +++ b/src/bin/elementary/test_image.c @@ -98,6 +98,81 @@ im_align_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUS printf("align %.3f %.3f\n", h, v); } +static const struct { + Efl_Ui_Image_Scale_Type scale_type; + const char *name; +} images_scale_type[] = { + { EFL_UI_IMAGE_SCALE_TYPE_NONE, "None" }, + { EFL_UI_IMAGE_SCALE_TYPE_FILL, "Fill" }, + { EFL_UI_IMAGE_SCALE_TYPE_FIT_INSIDE, "Fit Inside" }, + { EFL_UI_IMAGE_SCALE_TYPE_FIT_OUTSIDE, "Fit Outside" }, + { EFL_UI_IMAGE_SCALE_TYPE_TILE, "Tile" }, + { 0, NULL } +}; + +static void +my_im_scale_ch(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *win = data; + Evas_Object *im = evas_object_data_get(win, "im"); + Evas_Object *rdg = evas_object_data_get(win, "rdg"); + int v = elm_radio_value_get(rdg); + + efl_ui_image_scale_type_set(im, images_scale_type[v].scale_type); + fprintf(stderr, "Set %d[%s] and got %d\n", + images_scale_type[v].scale_type, images_scale_type[v].name, efl_ui_image_scale_type_get(im)); +} + +void +test_image_scale_type(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *win, *box, *im, *rd, *rdg = NULL; + int i; + + win = elm_win_util_standard_add("image test scale type", "Image Test Scale Type"); + elm_win_autodel_set(win, EINA_TRUE); + + box = elm_box_add(win); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, box); + evas_object_show(box); + + im = efl_add(EFL_UI_IMAGE_CLASS, win); + char buf[PATH_MAX]; + snprintf(buf, sizeof(buf), "%s/images/logo.png", elm_app_data_dir_get()); + elm_image_file_set(im, buf, NULL); + evas_object_size_hint_weight_set(im, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(im, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, im); + evas_object_show(im); + + evas_object_data_set(win, "im", im); + + for (i = 0; images_scale_type[i].name; ++i) + { + rd = elm_radio_add(win); + evas_object_size_hint_align_set(rd, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, 0.0); + elm_radio_state_value_set(rd, i); + elm_object_text_set(rd, images_scale_type[i].name); + elm_box_pack_end(box, rd); + evas_object_show(rd); + evas_object_smart_callback_add(rd, "changed", my_im_scale_ch, win); + if (!rdg) + { + rdg = rd; + evas_object_data_set(win, "rdg", rdg); + } + else + { + elm_radio_group_add(rd, rdg); + } + } + + evas_object_resize(win, 320, 480); + evas_object_show(win); +} + void test_image_swallow_align(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { diff --git a/src/lib/elementary/efl_ui_image.c b/src/lib/elementary/efl_ui_image.c index f27daba6db..c68b52aff7 100644 --- a/src/lib/elementary/efl_ui_image.c +++ b/src/lib/elementary/efl_ui_image.c @@ -153,18 +153,18 @@ _img_new(Evas_Object *obj) static void _image_sizing_eval(Efl_Ui_Image_Data *sd, Evas_Object *img) { + Evas_Coord x = 0, y = 0, w = 1, h = 1; if (efl_isa(img, EDJE_OBJECT_CLASS)) { - evas_object_move(img, sd->img_x, sd->img_y); - evas_object_resize(img, sd->img_w, sd->img_h); - - evas_object_move(sd->hit_rect, sd->img_x, sd->img_y); - evas_object_resize(sd->hit_rect, sd->img_w, sd->img_h); + x = sd->img_x; + y = sd->img_y; + w = sd->img_w; + h = sd->img_h; + goto done; } else { - Evas_Coord x = 0, y = 0, w = 1, h = 1; double alignh = 0.5, alignv = 0.5; int iw = 0, ih = 0, offset_x = 0, offset_y = 0; @@ -222,6 +222,13 @@ _image_sizing_eval(Efl_Ui_Image_Data *sd, Evas_Object *img) h = ih; } break; + case EFL_UI_IMAGE_SCALE_TYPE_TILE: + x = sd->img_x; + y = sd->img_y; + w = sd->img_w; + h = sd->img_h; + evas_object_image_fill_set(img, x, y, iw, ih); + goto done; } //3. Calculate offset according to align value @@ -259,13 +266,13 @@ _image_sizing_eval(Efl_Ui_Image_Data *sd, Evas_Object *img) y = sd->img_y; h = sd->img_h; } - - evas_object_move(img, x, y); - evas_object_resize(img, w, h); - - evas_object_move(sd->hit_rect, x, y); - evas_object_resize(sd->hit_rect, w, h); } +done: + evas_object_move(img, x, y); + evas_object_resize(img, w, h); + + evas_object_move(sd->hit_rect, x, y); + evas_object_resize(sd->hit_rect, w, h); } static void diff --git a/src/lib/elementary/efl_ui_image.eo b/src/lib/elementary/efl_ui_image.eo index 5810e5508a..124c51854c 100644 --- a/src/lib/elementary/efl_ui_image.eo +++ b/src/lib/elementary/efl_ui_image.eo @@ -19,6 +19,7 @@ enum Efl.Ui.Image.Scale_Type At least one of the dimensions of the image should be equal to the corresponding dimension of the object.]] + tile, [[Tile image at its original size.]] none [[Not scale the internal image]] }