aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/elementary/src/bin/test_layout.c
blob: 736a70080a453a037c4b8f3ee36bf1ff4a6b69af (plain) (blame)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
#ifndef ELM_LIB_QUICKLAUNCH
#include <Elementary_Cursor.h>

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__)
{
   elm_object_part_text_set(data, "text", elm_object_text_get(obj));
}

void
test_layout(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
{
   Evas_Object *win, *bg, *box, *ly, *bt;
   char buf[PATH_MAX];

   win = elm_win_add(NULL, "layout", ELM_WIN_BASIC);
   elm_win_title_set(win, "Layout");
   elm_win_autodel_set(win, EINA_TRUE);

   bg = elm_bg_add(win);
   elm_win_resize_object_add(win, bg);
   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_show(bg);

   box = elm_box_add(win);
   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_win_resize_object_add(win, box);
   evas_object_show(box);

   ly = elm_layout_add(win);
   elm_layout_theme_set(ly, "layout", "application", "titlebar");
   elm_object_text_set(ly, "Some title");
   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);

   bt = elm_icon_add(win);
   elm_icon_standard_set(bt, "chat");
   evas_object_size_hint_min_set(bt, 20, 20);
   elm_layout_icon_set(ly, bt);

   bt = elm_icon_add(win);
   elm_icon_standard_set(bt, "close");
   evas_object_size_hint_min_set(bt, 20, 20);
   elm_layout_end_set(ly, bt);

   ly = elm_layout_add(win);
   snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
   elm_layout_file_set(ly, buf, "layout");
   evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_box_pack_end(box, ly);
   //elm_win_resize_object_add(win, ly);
   evas_object_show(ly);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Button 1");
   elm_object_part_content_set(ly, "element1", bt);
   evas_object_smart_callback_add(bt, "clicked", _clicked_cb, ly);
   evas_object_show(bt);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Button 2");
   elm_object_part_content_set(ly, "element2", bt);
   evas_object_smart_callback_add(bt, "clicked", _clicked_cb, ly);
   evas_object_show(bt);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Button 3");
   elm_object_part_content_set(ly, "element3", bt);
   evas_object_smart_callback_add(bt, "clicked", _clicked_cb, ly);
   evas_object_show(bt);

   elm_layout_part_cursor_set(ly, "text", ELM_CURSOR_WATCH);

   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