The elm_toolbar_iteams_count have to return only the number of manually added items.
[framework/uifw/elementary.git] / src / examples / layout_example_01.c
1 //Compile with:
2 //gcc -g layout_example_01.c -o layout_example_01 `pkg-config --cflags --libs elementary`
3
4 #include <Elementary.h>
5
6 #define TABLE "example/table"
7 #define BOX "example/box"
8 #define TITLE "example/title"
9 #define SWALLOW "example/custom"
10
11 static int _box_buttons = 0;
12
13 static void
14 _tbl_btn_cb(void *data, Evas_Object *btn, void *event_info)
15 {
16    Evas_Object *layout = data;
17
18    elm_layout_table_unpack(layout, TABLE, btn);
19    evas_object_del(btn);
20 }
21
22 static void
23 _box_btn_cb(void *data, Evas_Object *btn, void *event_info)
24 {
25    Evas_Object *layout = data;
26    Evas_Object *item;
27    char buf[30];
28
29    snprintf(buf, sizeof(buf), "Button %02d", _box_buttons++);
30
31    item = elm_button_add(elm_object_parent_widget_get(layout));
32    elm_object_text_set(item, buf);
33    evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
34    evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
35    evas_object_size_hint_min_set(item, 100, 50);
36    elm_layout_box_insert_before(layout, BOX, item, btn);
37    evas_object_smart_callback_add(item, "clicked", _box_btn_cb, layout);
38    evas_object_show(item);
39 }
40
41 static void
42 _swallow_btn_cb(void *data, Evas_Object *btn, void *event_info)
43 {
44    Evas_Object *layout = data;
45    Evas_Object *item;
46
47    elm_layout_table_clear(layout, TABLE, EINA_TRUE);
48    elm_layout_box_remove_all(layout, BOX, EINA_TRUE);
49    item = elm_object_part_content_unset(layout, SWALLOW);
50    evas_object_del(item);
51 }
52
53 EAPI_MAIN int
54 elm_main(int argc, char **argv)
55 {
56    Evas_Object *win, *bg, *icon, *icon2, *bt, *bt2, *layout;
57    Evas_Object *clk;
58    Evas_Object *item;
59    char buf[PATH_MAX];
60
61    elm_app_info_set(elm_main, "elementary", "examples/layout_example.edj");
62    win = elm_win_add(NULL, "layout", ELM_WIN_BASIC);
63    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
64    elm_win_autodel_set(win, EINA_TRUE);
65
66    bg = elm_bg_add(win);
67    elm_bg_color_set(bg, 255,255 ,255);
68    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69    elm_win_resize_object_add(win, bg);
70    evas_object_show(bg);
71
72    // Adding layout and filling it with widgets
73    layout = elm_layout_add(win);
74    evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
75    elm_win_resize_object_add(win, layout);
76    snprintf(buf, sizeof(buf), "%s/examples/layout_example.edj", elm_app_data_dir_get());
77    elm_layout_file_set(layout, buf, "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()