1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
//Compile with:
//gcc -g layout_example_01.c -o layout_example_01 `pkg-config --cflags --libs elementary`
#include <Elementary.h>
#define TABLE "example/table"
#define BOX "example/box"
#define TITLE "example/title"
#define SWALLOW "example/custom"
static int _box_buttons = 0;
static void
_tbl_btn_cb(void *data, Evas_Object *btn, void *event_info EINA_UNUSED)
{
Evas_Object *layout = data;
elm_layout_table_unpack(layout, TABLE, btn);
evas_object_del(btn);
}
static void
_box_btn_cb(void *data, Evas_Object *btn, void *event_info EINA_UNUSED)
{
Evas_Object *layout = data;
Evas_Object *item;
char buf[30];
snprintf(buf, sizeof(buf), "Button %02d", _box_buttons++);
item = elm_button_add(elm_object_parent_widget_get(layout));
elm_object_text_set(item, buf);
evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_layout_box_insert_before(layout, BOX, item, btn);
evas_object_smart_callback_add(item, "clicked", _box_btn_cb, layout);
evas_object_show(item);
}
static void
_swallow_btn_cb(void *data, Evas_Object *btn EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *layout = data;
Evas_Object *item;
elm_layout_table_clear(layout, TABLE, EINA_TRUE);
elm_layout_box_remove_all(layout, BOX, EINA_TRUE);
item = elm_object_part_content_unset(layout, SWALLOW);
evas_object_del(item);
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Evas_Object *win, *icon, *icon2, *bt, *bt2, *layout;
Evas_Object *clk;
Evas_Object *item;
char buf[PATH_MAX];
elm_app_info_set(elm_main, "elementary", "examples/layout_example.edj");
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("layout", "Layout");
elm_win_autodel_set(win, EINA_TRUE);
// Adding layout and filling it with widgets
layout = elm_layout_add(win);
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, layout);
snprintf(buf, sizeof(buf), "%s/examples/layout_example.edj", elm_app_data_dir_get());
elm_layout_file_set(layout, buf, "example/mylayout");
evas_object_show(layout);
// Setting title
const char *title = elm_layout_data_get(layout, "title");
if (title)
{
elm_win_title_set(win, title);
elm_object_part_text_set(layout, TITLE, title);
}
// Add icon, clock and button to the table
icon = elm_icon_add(win);
elm_icon_standard_set(icon, "home");
evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_layout_table_pack(layout, TABLE, icon, 0, 0, 1, 1);
evas_object_show(icon);
icon2 = elm_icon_add(win);
elm_icon_standard_set(icon2, "close");
evas_object_size_hint_weight_set(icon2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(icon2, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_layout_table_pack(layout, TABLE, icon2, 1, 0, 1, 1);
evas_object_show(icon2);
clk = elm_clock_add(win);
evas_object_size_hint_weight_set(clk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(clk, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_layout_table_pack(layout, TABLE, clk, 2, 0, 1, 1);
evas_object_show(clk);
bt = elm_button_add(win);
elm_object_text_set(bt, "Click me!");
evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_layout_table_pack(layout, TABLE, bt, 0, 1, 3, 1);
evas_object_smart_callback_add(bt, "clicked", _tbl_btn_cb, layout);
evas_object_show(bt);
item = elm_button_add(win);
elm_object_text_set(item, "Position 0");
evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_layout_box_insert_at(layout, BOX, item, 0);
evas_object_smart_callback_add(item, "clicked", _box_btn_cb, layout);
evas_object_show(item);
item = elm_button_add(win);
elm_object_text_set(item, "Prepended");
evas_object_size_hint_weight_set(item, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(item, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_layout_box_prepend(layout, BOX, item);
evas_object_smart_callback_add(item, "clicked", _box_btn_cb, layout);
evas_object_show(item);
bt2 = elm_button_add(win);
elm_object_text_set(bt2, "Delete All");
elm_object_part_content_set(layout, SWALLOW, bt2);
evas_object_smart_callback_add(bt2, "clicked", _swallow_btn_cb, layout);
evas_object_resize(win, 320, 320);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()
|