2 //gcc -g `pkg-config --cflags --libs elementary` layout_example_01.c -o layout_example_01
4 #include <Elementary.h>
5 #define PACKAGE_DATA_DIR "."
7 #define TABLE "example/table"
8 #define BOX "example/box"
9 #define TITLE "example/title"
10 #define SWALLOW "example/custom"
12 static int _box_buttons = 0;
15 _tbl_btn_cb(void *data, Evas_Object *btn, void *event_info)
17 Evas_Object *layout = data;
19 elm_layout_table_unpack(layout, TABLE, btn);
24 _box_btn_cb(void *data, Evas_Object *btn, void *event_info)
26 Evas_Object *layout = data;
30 snprintf(buf, sizeof(buf), "Button %02d", _box_buttons++);
32 item = elm_button_add(elm_object_parent_widget_get(layout));
33 elm_object_text_set(item, buf);
34 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
35 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
36 evas_object_size_hint_min_set(item, 100, 50);
37 elm_layout_box_insert_before(layout, BOX, item, btn);
38 evas_object_smart_callback_add(item, "clicked", _box_btn_cb, layout);
39 evas_object_show(item);
43 _swallow_btn_cb(void *data, Evas_Object *btn, void *event_info)
45 Evas_Object *layout = data;
48 elm_layout_table_clear(layout, TABLE, EINA_TRUE);
49 elm_layout_box_remove_all(layout, BOX, EINA_TRUE);
50 item = elm_object_part_content_unset(layout, SWALLOW);
51 evas_object_del(item);
55 elm_main(int argc, char **argv)
57 Evas_Object *win, *bg, *icon, *icon2, *bt, *bt2, *layout;
61 win = elm_win_add(NULL, "layout", ELM_WIN_BASIC);
62 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
63 elm_win_autodel_set(win, EINA_TRUE);
66 elm_bg_color_set(bg, 255,255 ,255);
67 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
68 elm_win_resize_object_add(win, bg);
71 // Adding layout and filling it with widgets
72 layout = elm_layout_add(win);
73 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
74 elm_win_resize_object_add(win, layout);
76 layout, PACKAGE_DATA_DIR "/examples/layout_example.edj",
78 evas_object_show(layout);
81 const char *title = elm_layout_data_get(layout, "title");
84 elm_win_title_set(win, title);
85 elm_object_part_text_set(layout, TITLE, title);
88 // Add icon, clock and button to the table
89 icon = elm_icon_add(win);
90 elm_icon_standard_set(icon, "home");
91 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
92 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
93 elm_layout_table_pack(layout, TABLE, icon, 0, 0, 1, 1);
94 evas_object_show(icon);
96 icon2 = elm_icon_add(win);
97 elm_icon_standard_set(icon2, "close");
98 evas_object_size_hint_weight_set(icon2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99 evas_object_size_hint_align_set(icon2, EVAS_HINT_FILL, EVAS_HINT_FILL);
100 elm_layout_table_pack(layout, TABLE, icon2, 1, 0, 1, 1);
101 evas_object_show(icon2);
103 clk = elm_clock_add(win);
104 evas_object_size_hint_weight_set(clk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
105 evas_object_size_hint_align_set(clk, EVAS_HINT_FILL, EVAS_HINT_FILL);
106 elm_layout_table_pack(layout, TABLE, clk, 2, 0, 1, 1);
107 evas_object_show(clk);
109 bt = elm_button_add(win);
110 elm_object_text_set(bt, "Click me!");
111 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
112 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
113 elm_layout_table_pack(layout, TABLE, bt, 0, 1, 3, 1);
114 evas_object_smart_callback_add(bt, "clicked", _tbl_btn_cb, layout);
115 evas_object_show(bt);
117 item = elm_button_add(win);
118 elm_object_text_set(item, "Position 0");
119 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
120 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
121 evas_object_size_hint_min_set(item, 100, 50);
122 elm_layout_box_insert_at(layout, BOX, item, 0);
123 evas_object_smart_callback_add(item, "clicked", _box_btn_cb, layout);
124 evas_object_show(item);
126 item = elm_button_add(win);
127 elm_object_text_set(item, "Prepended");
128 evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
129 evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
130 evas_object_size_hint_min_set(item, 100, 50);
131 elm_layout_box_prepend(layout, BOX, item);
132 evas_object_smart_callback_add(item, "clicked", _box_btn_cb, layout);
133 evas_object_show(item);
135 bt2 = elm_button_add(win);
136 elm_object_text_set(bt2, "Delete All");
137 elm_object_part_content_set(layout, SWALLOW, bt2);
138 evas_object_smart_callback_add(bt2, "clicked", _swallow_btn_cb, layout);
140 evas_object_size_hint_min_set(bg, 160, 160);
141 evas_object_size_hint_max_set(bg, 640, 640);
142 evas_object_resize(win, 320, 320);
143 evas_object_show(win);