1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 
5 #include <Efl_Ui.h>
6 #include <Elementary.h>
7 
8 static void _third_layout_push(void *data, const Efl_Event *ev EINA_UNUSED);
9 
10 static void
_stack_remove(void * data,const Efl_Event * ev EINA_UNUSED)11 _stack_remove(void *data, const Efl_Event *ev EINA_UNUSED)
12 {
13    Eo *stack = data;
14    Eo *top_layout = efl_pack_content_get(stack, 0);
15    efl_del(top_layout);
16 }
17 
18 static void
_stack_pop(void * data,const Efl_Event * ev EINA_UNUSED)19 _stack_pop(void *data, const Efl_Event *ev EINA_UNUSED)
20 {
21    Eo *stack = data;
22    efl_ui_spotlight_pop(stack, EINA_TRUE);
23 }
24 
25 static void
_stack_double_push(void * data,const Efl_Event * ev EINA_UNUSED)26 _stack_double_push(void *data, const Efl_Event *ev EINA_UNUSED)
27 {
28    Eo *stack = data;
29    _third_layout_push(stack, NULL);
30 }
31 
32 static void
_stack_del(void * data,const Efl_Event * ev EINA_UNUSED)33 _stack_del(void *data, const Efl_Event *ev EINA_UNUSED)
34 {
35    Eo *stack = data;
36    Eo *top_layout = efl_pack_content_get(stack, 0);
37    efl_del(top_layout);
38 }
39 
40 static void
_win_del(void * data,const Efl_Event * ev EINA_UNUSED)41 _win_del(void *data, const Efl_Event *ev EINA_UNUSED)
42 {
43    Eo *win = data;
44    efl_del(win);
45 }
46 
47 static Eo *
_navigation_layout_create(Eo * stack,const char * text,Eo * content)48 _navigation_layout_create(Eo *stack, const char *text, Eo *content)
49 {
50    Eo *nl = efl_add(EFL_UI_NAVIGATION_LAYOUT_CLASS, stack);
51 
52    Eo *bn = efl_add(EFL_UI_NAVIGATION_BAR_CLASS, nl);
53    efl_text_set(bn, text);
54    efl_gfx_entity_visible_set(efl_part(bn, "back_button"), EINA_TRUE);
55    efl_ui_navigation_layout_bar_set(nl, bn);
56 
57    efl_content_set(nl, content);
58 
59    printf("Create content(%p).\n\n", nl);
60 
61    return nl;
62 }
63 
64 static void
_bar_left_btn_set(Eo * navigation_layout,Efl_Event_Cb clicked_cb,void * data)65 _bar_left_btn_set(Eo *navigation_layout, Efl_Event_Cb clicked_cb, void *data)
66 {
67    Eo *bn = efl_ui_navigation_layout_bar_get(navigation_layout);
68 
69    Eo *left_btn = efl_add(EFL_UI_BUTTON_CLASS, bn);
70    efl_text_set(left_btn, "Prev");
71    efl_content_set(efl_part(bn, "left_content"), left_btn);
72 
73    efl_event_callback_add(left_btn, EFL_INPUT_EVENT_CLICKED, clicked_cb, data);
74 
75    //Positions of "left_content" and "back_button" are the same.
76    efl_gfx_entity_visible_set(efl_part(bn, "back_button"), EINA_FALSE);
77 }
78 
79 static void
_bar_right_btn_set(Eo * navigation_layout,Efl_Event_Cb clicked_cb,void * data)80 _bar_right_btn_set(Eo *navigation_layout, Efl_Event_Cb clicked_cb, void *data)
81 {
82    Eo *bn = efl_ui_navigation_layout_bar_get(navigation_layout);
83 
84    Eo *right_btn = efl_add(EFL_UI_BUTTON_CLASS, bn);
85    efl_text_set(right_btn, "Next");
86    efl_content_set(efl_part(bn, "right_content"), right_btn);
87 
88    efl_event_callback_add(right_btn, EFL_INPUT_EVENT_CLICKED, clicked_cb, data);
89 }
90 
91 static void
_fifth_layout_insert(void * data,const Efl_Event * ev EINA_UNUSED)92 _fifth_layout_insert(void *data, const Efl_Event *ev EINA_UNUSED)
93 {
94    Eo *stack = data;
95 
96    Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
97    efl_text_set(btn, "Press to remove top layout");
98    efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _stack_remove, stack);
99 
100    Eo *nl = _navigation_layout_create(stack, "5th layout", btn);
101 
102    efl_ui_spotlight_push(stack, nl);
103 }
104 
105 static void
_third_layout_push(void * data,const Efl_Event * ev EINA_UNUSED)106 _third_layout_push(void *data, const Efl_Event *ev EINA_UNUSED)
107 {
108    Eo *stack = data;
109 
110    Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
111    efl_text_set(btn, "Press to pop");
112    efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _stack_pop, stack);
113 
114    Eo *nl = _navigation_layout_create(stack, "3rd layout", btn);
115 
116    _bar_right_btn_set(nl, _fifth_layout_insert, stack);
117 
118    efl_ui_spotlight_push(stack, nl);
119 }
120 
121 static void
_second_layout_push(void * data,const Efl_Event * ev EINA_UNUSED)122 _second_layout_push(void *data, const Efl_Event *ev EINA_UNUSED)
123 {
124    Eo *stack = data;
125 
126    Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
127    efl_text_set(btn, "Press to double push");
128    efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _stack_double_push, stack);
129 
130    Eo *nl = _navigation_layout_create(stack, "2nd layout", btn);
131 
132    _bar_right_btn_set(nl, _third_layout_push, stack);
133 
134    efl_ui_spotlight_push(stack, nl);
135 }
136 
137 static void
_first_layout_push(Eo * win,Eo * stack)138 _first_layout_push(Eo *win, Eo *stack)
139 {
140    Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, stack);
141    efl_text_set(btn, "Press to delete stack");
142    efl_event_callback_add(btn, EFL_INPUT_EVENT_CLICKED, _stack_del, stack);
143 
144    Eo *nl = _navigation_layout_create(stack, "1st layout", btn);
145 
146    _bar_left_btn_set(nl, _win_del, win);
147    _bar_right_btn_set(nl, _second_layout_push, stack);
148 
149    efl_ui_spotlight_push(stack, nl);
150 }
151 
152 void
test_ui_stack(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)153 test_ui_stack(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
154 {
155    Eo *win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
156                      efl_text_set(efl_added, "Efl.Ui.Stack"),
157                      efl_ui_win_autodel_set(efl_added, EINA_TRUE));
158 
159    efl_gfx_entity_size_set(win, EINA_SIZE2D(500, 500));
160 
161    Eo *stack = efl_ui_spotlight_util_stack_gen(win);
162 
163    efl_content_set(win, stack);
164 
165    _first_layout_push(win, stack);
166 }
167