aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/elementary/test_ui_stack.c
blob: 1cb3041ce92a6216e104d86efb11e78e5e3bfffd (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Elementary.h>

static void _third_layout_push(void *data, const Efl_Event *ev EINA_UNUSED);
static void _fourth_layout_push(void *data, const Efl_Event *ev EINA_UNUSED);

static void
_stack_remove(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;
   Eo *top_layout = efl_ui_stack_top(stack);
   efl_ui_stack_remove(stack, top_layout);
}

static void
_stack_double_pop(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;
   efl_ui_stack_pop(stack);
   efl_ui_stack_pop(stack);
}

static void
_stack_pop(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;
   efl_ui_stack_pop(stack);
}

static void
_stack_double_push(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;
   _third_layout_push(stack, NULL);
   _fourth_layout_push(stack, NULL);
}

static void
_stack_del(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;
   Eo *top_layout = efl_ui_stack_top(stack);
   efl_del(top_layout);
}

static void
_win_del(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *win = data;
   efl_del(win);
}

static Eo *
_navigation_layout_create(Eo *stack, const char *text, Eo *content)
{
   Eo *nl = efl_add(EFL_UI_NAVIGATION_LAYOUT_CLASS, stack);

   Eo *bn = efl_add(EFL_UI_NAVIGATION_BAR_CLASS, nl);
   efl_text_set(bn, text);
   efl_gfx_entity_visible_set(efl_part(bn, "back_button"), EINA_TRUE);
   efl_ui_navigation_layout_bar_set(nl, bn);

   efl_content_set(nl, content);

   printf("Create content(%p).\n\n", nl);

   return nl;
}

static void
_bar_left_btn_set(Eo *navigation_layout, Efl_Event_Cb clicked_cb, void *data)
{
   Eo *bn = efl_ui_navigation_layout_bar_get(navigation_layout);

   Eo *left_btn = efl_add(EFL_UI_BUTTON_CLASS, bn);
   efl_text_set(left_btn, "Prev");
   efl_content_set(efl_part(bn, "left_content"), left_btn);

   efl_event_callback_add(left_btn, EFL_UI_EVENT_CLICKED, clicked_cb, data);

   //Positions of "left_content" and "back_button" are the same.
   efl_gfx_entity_visible_set(efl_part(bn, "back_button"), EINA_FALSE);
}

static void
_bar_right_btn_set(Eo *navigation_layout, Efl_Event_Cb clicked_cb, void *data)
{
   Eo *bn = efl_ui_navigation_layout_bar_get(navigation_layout);

   Eo *right_btn = efl_add(EFL_UI_BUTTON_CLASS, bn);
   efl_text_set(right_btn, "Next");
   efl_content_set(efl_part(bn, "right_content"), right_btn);

   efl_event_callback_add(right_btn, EFL_UI_EVENT_CLICKED, clicked_cb, data);
}

static void
_fifth_layout_insert(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;

   Eo *top_layout = efl_ui_stack_top(stack);

   Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
   efl_text_set(btn, "Press to remove top layout");
   efl_event_callback_add(btn, EFL_UI_EVENT_CLICKED, _stack_remove, stack);

   Eo *nl = _navigation_layout_create(stack, "5th layout", btn);

   efl_ui_stack_insert_after(stack, top_layout, nl);
}

static void
_fourth_layout_push(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;

   Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
   efl_text_set(btn, "Press to double pop");
   efl_event_callback_add(btn, EFL_UI_EVENT_CLICKED, _stack_double_pop, stack);

   Eo *nl = _navigation_layout_create(stack, "4th layout", btn);

   _bar_right_btn_set(nl, _fifth_layout_insert, stack);

   efl_ui_stack_push(stack, nl);
}

static void
_third_layout_push(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;

   Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
   efl_text_set(btn, "Press to pop");
   efl_event_callback_add(btn, EFL_UI_EVENT_CLICKED, _stack_pop, stack);

   Eo *nl = _navigation_layout_create(stack, "3rd layout", btn);

   _bar_right_btn_set(nl, _fourth_layout_push, stack);

   efl_ui_stack_push(stack, nl);
}

static void
_second_layout_push(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *stack = data;

   Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
   efl_text_set(btn, "Press to double push");
   efl_event_callback_add(btn, EFL_UI_EVENT_CLICKED, _stack_double_push, stack);

   Eo *nl = _navigation_layout_create(stack, "2nd layout", btn);

   _bar_right_btn_set(nl, _third_layout_push, stack);

   efl_ui_stack_push(stack, nl);
}

static void
_first_layout_push(Eo *win, Eo *stack)
{
   Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
   efl_text_set(btn, "Press to delete stack");
   efl_event_callback_add(btn, EFL_UI_EVENT_CLICKED, _stack_del, stack);

   Eo *nl = _navigation_layout_create(stack, "1st layout", btn);

   _bar_left_btn_set(nl, _win_del, win);
   _bar_right_btn_set(nl, _second_layout_push, stack);

   efl_ui_stack_push(stack, nl);
}

static void
_stack_loaded_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
   Efl_Ui_Stack_Event_Loaded *loaded_info = event->info;
   printf("Content(%p) is loaded to the stack.\n\n", loaded_info->content);
}

static void
_stack_unloaded_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
   Efl_Ui_Stack_Event_Unloaded *unloaded_info = event->info;
   printf("Content(%p) is unloaded from the stack.\n\n", unloaded_info->content);
}

static void
_stack_activated_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
   Efl_Ui_Stack_Event_Activated *activated_info = event->info;
   printf("Content(%p) is activated in the stack.\n\n", activated_info->content);
}

static void
_stack_deactivated_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
   Efl_Ui_Stack_Event_Deactivated *deactivated_info = event->info;
   printf("Content(%p) is deactivated in the stack.\n\n", deactivated_info->content);
}

void
test_ui_stack(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eo *win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                     efl_text_set(efl_added, "Efl.Ui.Stack"),
                     efl_ui_win_autodel_set(efl_added, EINA_TRUE));

   efl_gfx_entity_size_set(win, EINA_SIZE2D(500, 500));

   Eo *stack = efl_add(EFL_UI_STACK_CLASS, win);
   efl_event_callback_add(stack, EFL_UI_STACK_EVENT_LOADED,
                          _stack_loaded_cb, NULL);
   efl_event_callback_add(stack, EFL_UI_STACK_EVENT_UNLOADED,
                          _stack_unloaded_cb, NULL);
   efl_event_callback_add(stack, EFL_UI_STACK_EVENT_ACTIVATED,
                          _stack_activated_cb, NULL);
   efl_event_callback_add(stack, EFL_UI_STACK_EVENT_DEACTIVATED,
                          _stack_deactivated_cb, NULL);
   efl_content_set(win, stack);

   _first_layout_push(win, stack);
}