8165d56507a0e3c8a95a893a7a4817cf1b66b7bd
[framework/uifw/elementary.git] / src / examples / layout_example_01.c
1 //Compile with:
2 //gcc -g `pkg-config --cflags --libs elementary` layout_example_01.c -o layout_example_01
3
4 #include <Elementary.h>
5 #define PACKAGE_DATA_DIR "."
6
7 #define TABLE "example/table"
8 #define BOX "example/box"
9 #define TITLE "example/title"
10 #define SWALLOW "example/custom"
11
12 static int _box_buttons = 0;
13
14 static void
15 _tbl_btn_cb(void *data, Evas_Object *btn, void *event_info)
16 {
17    Evas_Object *layout = data;
18
19    elm_layout_table_unpack(layout, TABLE, btn);
20    evas_object_del(btn);
21 }
22
23 static void
24 _box_btn_cb(void *data, Evas_Object *btn, void *event_info)
25 {
26    Evas_Object *layout = data;
27    Evas_Object *item;
28    char buf[30];
29
30    snprintf(buf, sizeof(buf), "Button %02d", _box_buttons++);
31
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);
40 }
41
42 static void
43 _swallow_btn_cb(void *data, Evas_Object *btn, void *event_info)
44 {
45    Evas_Object *layout = data;
46    Evas_Object *item;
47
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);
52 }
53
54 EAPI_MAIN int
55 elm_main(int argc, char **argv)
56 {
57    Evas_Object *win, *bg, *icon, *icon2, *bt, *bt2, *layout;
58    Evas_Object *clk;
59    Evas_Object *item;
60
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);
64
65    bg = elm_bg_add(win);
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);
69    evas_object_show(bg);
70
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);
75    elm_layout_file_set(
76        layout, PACKAGE_DATA_DIR "/examples/layout_example.edj",
77        "example/mylayout");
78    evas_object_show(layout);
79
80    // Setting title
81    const char *title = elm_layout_data_get(layout, "title");
82    if (title)
83      {
84         elm_win_title_set(win, title);
85         elm_object_part_text_set(layout, TITLE, title);
86      }
87
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);
95
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);
102
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);
108
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);
116
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);
125
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);
134
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);
139
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);
144
145    elm_run();
146    elm_shutdown();
147
148    return 0;
149 }
150 ELM_MAIN()