From caf98c15c87e1adf6130886fff491f42c1fb12be Mon Sep 17 00:00:00 2001 From: raster Date: Mon, 19 Mar 2012 06:57:39 +0000 Subject: [PATCH] From: cnook Subject: [E-devel] [Patch][elementary_test] test_layout I have attached a patch for test_layout. Please review this and give any feedbacks. Thanks. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@69501 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/test.c | 2 + src/bin/test_layout.c | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) diff --git a/src/bin/test.c b/src/bin/test.c index d967c45..699f6d4 100644 --- a/src/bin/test.c +++ b/src/bin/test.c @@ -37,6 +37,7 @@ void test_check(void *data, Evas_Object *obj, void *event_info); void test_check2(void *data, Evas_Object *obj, void *event_info); void test_radio(void *data, Evas_Object *obj, void *event_info); void test_layout(void *data, Evas_Object *obj, void *event_info); +void test_layout2(void *data, Evas_Object *obj, void *event_info); void test_hover(void *data, Evas_Object *obj, void *event_info); void test_hover2(void *data, Evas_Object *obj, void *event_info); void test_entry(void *data, Evas_Object *obj, void *event_info); @@ -368,6 +369,7 @@ add_tests: ADD_TEST(NULL, "Containers", "Table 6", test_table6); ADD_TEST(NULL, "Containers", "Table 7", test_table7); ADD_TEST(NULL, "Containers", "Layout", test_layout); + ADD_TEST(NULL, "Containers", "Layout 2", test_layout2); ADD_TEST(NULL, "Containers", "Grid", test_grid); //------------------------------// diff --git a/src/bin/test_layout.c b/src/bin/test_layout.c index b4720eb..8b5248d 100644 --- a/src/bin/test_layout.c +++ b/src/bin/test_layout.c @@ -5,6 +5,29 @@ #ifndef ELM_LIB_QUICKLAUNCH #include +struct _api_data +{ + unsigned int state; /* What state we are testing */ + Evas_Object *box_layout; + Evas_Object *table_layout; + Evas_Object *ref; + Evas_Object *ref2; +}; +typedef struct _api_data api_data; + +enum _api_state +{ + LAYOUT_BOX_INSERT_AT, + LAYOUT_BOX_INSERT_BEFORE, + LAYOUT_BOX_PREPEND, + LAYOUT_BOX_REMOVE, + LAYOUT_BOX_REMOVE_ALL, + LAYOUT_TABLE_UNPACK, + LAYOUT_TABLE_CLEAR, + API_STATE_LAST +}; + +typedef enum _api_state api_state; static void _clicked_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__) { @@ -80,4 +103,161 @@ test_layout(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info evas_object_show(win); } + +static void +set_api_state(api_data *api) +{ + Evas_Object *box_layout = api->box_layout; + Evas_Object *table_layout = api->table_layout; + Evas_Object *obj; + + /* use elm_box_children_get() to get list of children */ + switch (api->state) + { /* Put all api-changes under switch */ + case LAYOUT_BOX_INSERT_AT: + { + obj = elm_label_add(box_layout); + elm_object_text_set(obj, "elm_layout_box_insert_at(); is called"); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_layout_box_insert_at(box_layout, "elm.box.content", obj, 0); + evas_object_show(obj); + break; + } + + case LAYOUT_BOX_INSERT_BEFORE: + { + obj = elm_label_add(box_layout); + elm_object_text_set(obj, "elm_layout_box_insert_before(); is called"); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_layout_box_insert_before(box_layout, "elm.box.content", + obj, api->ref); + evas_object_show(obj); + break; + } + + case LAYOUT_BOX_PREPEND: + { + obj = elm_label_add(box_layout); + elm_object_text_set(obj, "elm_layout_box_prepend(); is called"); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_layout_box_prepend(box_layout, "elm.box.content", obj); + evas_object_show(obj); + break; + } + + case LAYOUT_BOX_REMOVE: + { + elm_layout_box_remove(box_layout, "elm.box.content", api->ref); + evas_object_del(api->ref); + break; + } + + case LAYOUT_BOX_REMOVE_ALL: + { + elm_layout_box_remove_all(box_layout, "elm.box.content", EINA_TRUE); + break; + } + + case LAYOUT_TABLE_UNPACK: + { + elm_layout_table_unpack(table_layout, "elm.table.content", api->ref2); + evas_object_del(api->ref2); + break; + } + + case LAYOUT_TABLE_CLEAR: + { + elm_layout_table_clear(table_layout, "elm.table.content", EINA_TRUE); + break; + } + + default: return; + } +} + +static void +_api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__) +{ /* Will add here a SWITCH command containing code to modify test-object */ + /* in accordance a->state value. */ + api_data *a = data; + char str[128]; + + printf("clicked event on API Button: api_state=<%d>\n", a->state); + set_api_state(a); + a->state++; + sprintf(str, "Next API function (%u)", a->state); + elm_object_text_set(obj, str); + elm_object_disabled_set(obj, a->state == API_STATE_LAST); +} + +static void +_cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + free(data); +} + +void +test_layout2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + Evas_Object *win, *box, *bt, *ly, *lb; + api_data *api = calloc(1, sizeof(api_data)); + + win = elm_win_util_standard_add("layout2", "Layout 2"); + elm_win_autodel_set(win, EINA_TRUE); + evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api); + + 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); + + bt = elm_button_add(win); + elm_object_text_set(bt, "Next API function"); + evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, + (void *)api); + elm_box_pack_end(box, bt); + elm_object_disabled_set(bt, api->state == API_STATE_LAST); + evas_object_show(bt); + + /* Layout Box Test */ + api->box_layout = ly = elm_layout_add(win); + elm_layout_theme_set(ly, "layout", "application", "toolbar-vbox"); + evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, ly); + evas_object_show(ly); + + api->ref = lb = elm_label_add(win); + elm_object_text_set(lb, "This is a label for the box content"); + evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(lb); + + elm_layout_box_append(ly, "elm.box.content", lb); + + /* Layout Table Test */ + api->table_layout = ly = elm_layout_add(win); + elm_layout_theme_set(ly, "layout", "application", "toolbar-table"); + evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, ly); + evas_object_show(ly); + + lb = elm_label_add(win); + elm_object_text_set(lb, "This is a label for the table content"); + evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(lb); + elm_layout_table_pack(ly, "elm.table.content", lb, 0, 0, 1, 1); + + api->ref2 = lb = elm_label_add(win); + elm_object_text_set(lb, "col = 0, row = 1"); + evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(lb); + elm_layout_table_pack(ly, "elm.table.content", lb, 0, 1, 1, 1); + + evas_object_resize(win, 320, 320); + evas_object_show(win); +} #endif -- 2.7.4