summaryrefslogtreecommitdiff
path: root/src/bin/elementary/test_ui_relative_container.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/elementary/test_ui_relative_container.c')
-rw-r--r--src/bin/elementary/test_ui_relative_container.c331
1 files changed, 331 insertions, 0 deletions
diff --git a/src/bin/elementary/test_ui_relative_container.c b/src/bin/elementary/test_ui_relative_container.c
new file mode 100644
index 0000000..4b5ca73
--- /dev/null
+++ b/src/bin/elementary/test_ui_relative_container.c
@@ -0,0 +1,331 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Efl_Ui.h>
6#include <Elementary.h>
7#include "elm_priv.h" //FIXME remove this once efl.ui.text doesn't need elm_general.h
8#include "test.h"
9static Eo *layout, *btn1, *btn2, *btn3;
10
11typedef enum {
12 LEFT,
13 RIGHT,
14 TOP,
15 BOTTOM
16} Options;
17
18static void
19_btn_color_clicked_cb(void *data, const Efl_Event *event EINA_UNUSED)
20{
21 Eo *l = data;
22
23 static Eina_Bool changed = EINA_TRUE;
24
25 if (changed)
26 efl_gfx_color_set(l, 0, 88, 204, 255);
27 else
28 efl_gfx_color_set(l, 255, 255, 255, 255);
29
30 changed = !changed;
31}
32
33static void
34_btn_clicked_to_cb(void *data, const Efl_Event *event)
35{
36 Eo *to, *btn, *obj = event->object;
37 Options opt = (Options)data;
38 double relative;
39
40 btn = efl_key_wref_get(obj, "btn");
41 to = efl_key_wref_get(obj, "to");
42
43 do
44 {
45 if (to == layout)
46 to = btn1;
47 else if (to == btn1)
48 to = btn2;
49 else if (to == btn2)
50 to = btn3;
51 else if (to == btn3)
52 to = layout;
53 }
54 while (btn == to);
55 efl_key_wref_set(obj, "to", to);
56
57 switch (opt)
58 {
59 case LEFT:
60 efl_ui_relative_container_relation_left_get(layout, btn, NULL, &relative);
61 efl_ui_relative_container_relation_left_set(layout, btn, to, relative);
62 break;
63 case RIGHT:
64 efl_ui_relative_container_relation_right_get(layout, btn, NULL, &relative);
65 efl_ui_relative_container_relation_right_set(layout, btn, to, relative);
66 break;
67 case TOP:
68 efl_ui_relative_container_relation_top_get(layout, btn, NULL, &relative);
69 efl_ui_relative_container_relation_top_set(layout, btn, to, relative);
70 break;
71 case BOTTOM:
72 efl_ui_relative_container_relation_bottom_get(layout, btn, NULL, &relative);
73 efl_ui_relative_container_relation_bottom_set(layout, btn, to, relative);
74 break;
75 }
76 efl_text_set(obj, ((to == layout) ? "parent" : (char *)efl_text_get(to)));
77}
78
79static void
80_slider_changed_relative_cb(void *data, const Efl_Event *event)
81{
82 Options opt = (Options)data;
83 Eo *btn, *slider = event->object;
84 double val;
85
86 btn = efl_key_wref_get(slider, "btn");
87 val = efl_ui_range_value_get(slider);
88
89 switch (opt)
90 {
91 case LEFT:
92 efl_ui_relative_container_relation_left_set(layout, btn, NULL, val);
93 break;
94 case RIGHT:
95 efl_ui_relative_container_relation_right_set(layout, btn, NULL, val);
96 break;
97 case TOP:
98 efl_ui_relative_container_relation_top_set(layout, btn, NULL, val);
99 break;
100 case BOTTOM:
101 efl_ui_relative_container_relation_bottom_set(layout, btn, NULL, val);
102 break;
103 }
104}
105
106static void
107_slider_changed_align_cb(void *data, const Efl_Event *event)
108{
109 char opt = (char)(uintptr_t)data;
110 Eo *btn, *slider = event->object;
111 double val, x, y;
112
113 btn = efl_key_wref_get(slider, "btn");
114 val = efl_ui_range_value_get(slider);
115
116 efl_gfx_hint_align_get(btn, &x, &y);
117 if (opt == 'x')
118 efl_gfx_hint_align_set(btn, val, y);
119 else if (opt == 'y')
120 efl_gfx_hint_align_set(btn, x, val);
121}
122
123static void
124_setter_add(Eo *vbox, Eo *btn, Options option)
125{
126 Eo *to, *hbox;
127 char *text = NULL, *btn_text;
128 double relative;
129
130 switch (option)
131 {
132 case LEFT:
133 text = "left";
134 efl_ui_relative_container_relation_left_get(layout, btn, &to, &relative);
135 break;
136 case RIGHT:
137 text = "right";
138 efl_ui_relative_container_relation_right_get(layout, btn, &to, &relative);
139 break;
140 case TOP:
141 text = "top";
142 efl_ui_relative_container_relation_top_get(layout, btn, &to, &relative);
143 break;
144 case BOTTOM:
145 text = "bottom";
146 efl_ui_relative_container_relation_bottom_get(layout, btn, &to, &relative);
147 break;
148 }
149 btn_text = ((to == layout) ? "parent" : (char *)efl_text_get(to));
150
151 hbox = efl_add(EFL_UI_BOX_CLASS, vbox,
152 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
153 efl_gfx_arrangement_content_padding_set(efl_added, 2, 2),
154 efl_pack(vbox, efl_added));
155
156 efl_add(EFL_UI_TEXT_CLASS, hbox,
157 efl_text_set(efl_added, text),
158 efl_text_interactive_editable_set(efl_added, EINA_FALSE),
159 efl_text_vertical_align_set(efl_added, 0.5),
160 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(40, 0)),
161 efl_gfx_hint_weight_set(efl_added, 0, EFL_GFX_HINT_EXPAND),
162 efl_pack(hbox, efl_added));
163
164 efl_add(EFL_UI_BUTTON_CLASS, hbox,
165 efl_text_set(efl_added, btn_text),
166 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(60, 0)),
167 efl_key_wref_set(efl_added, "to", to),
168 efl_key_wref_set(efl_added, "btn", btn),
169 efl_gfx_hint_weight_set(efl_added, 0, EFL_GFX_HINT_EXPAND),
170 efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, _btn_clicked_to_cb, (void *)option),
171 efl_pack(hbox, efl_added));
172
173 efl_add(EFL_UI_SLIDER_CLASS, hbox,
174 efl_ui_range_limits_set(efl_added, 0.0, 1.0),
175 efl_ui_range_step_set(efl_added, 0.1),
176 efl_ui_range_value_set(efl_added, relative),
177 efl_key_wref_set(efl_added, "btn", btn),
178 efl_event_callback_add(efl_added, EFL_UI_RANGE_EVENT_CHANGED, _slider_changed_relative_cb, (void *)option),
179 efl_pack(hbox, efl_added));
180}
181
182static void
183_button_frame_add(Eo *box, Eo *btn)
184{
185 Eo *f, *vbox, *hbox;
186 double align_x, align_y;
187
188 f = efl_add(EFL_UI_FRAME_CLASS, box,
189 efl_text_set(efl_added, efl_text_get(btn)),
190 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
191 efl_pack(box, efl_added));
192
193 vbox = efl_add(EFL_UI_BOX_CLASS, f,
194 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL),
195 efl_gfx_arrangement_content_padding_set(efl_added, 2, 2),
196 efl_gfx_hint_margin_set(efl_added, 2, 2, 2, 2),
197 efl_content_set(f, efl_added));
198
199 hbox = efl_add(EFL_UI_BOX_CLASS, vbox,
200 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
201 efl_gfx_arrangement_content_padding_set(efl_added, 2, 2),
202 efl_pack(vbox, efl_added));
203
204 efl_add(EFL_CANVAS_RECTANGLE_CLASS, hbox,
205 efl_gfx_color_set(efl_added, 0, 0, 0, 0),
206 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(40, 0)),
207 efl_gfx_hint_weight_set(efl_added, 0, EFL_GFX_HINT_EXPAND),
208 efl_pack(hbox, efl_added));
209
210 efl_add(EFL_UI_TEXT_CLASS, hbox,
211 efl_text_set(efl_added, "to"),
212 efl_text_interactive_editable_set(efl_added, EINA_FALSE),
213 efl_text_horizontal_align_set(efl_added, 0.5),
214 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(60, 0)),
215 efl_gfx_hint_weight_set(efl_added, 0, EFL_GFX_HINT_EXPAND),
216 efl_pack(hbox, efl_added));
217
218 efl_add(EFL_UI_TEXT_CLASS, hbox,
219 efl_text_set(efl_added, "relative"),
220 efl_text_horizontal_align_set(efl_added, 0.5),
221 efl_text_interactive_editable_set(efl_added, EINA_FALSE),
222 efl_pack(hbox, efl_added));
223
224 _setter_add(vbox, btn, LEFT);
225 _setter_add(vbox, btn, RIGHT);
226 _setter_add(vbox, btn, TOP);
227 _setter_add(vbox, btn, BOTTOM);
228
229 /* align setter */
230 efl_gfx_hint_align_get(btn, &align_x, &align_y);
231
232 hbox = efl_add(EFL_UI_BOX_CLASS, vbox,
233 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
234 efl_gfx_arrangement_content_padding_set(efl_added, 2, 2),
235 efl_pack(vbox, efl_added));
236
237 efl_add(EFL_UI_TEXT_CLASS, hbox,
238 efl_text_set(efl_added, "align_x"),
239 efl_text_interactive_editable_set(efl_added, EINA_FALSE),
240 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(40, 0)),
241 efl_gfx_hint_weight_set(efl_added, 0, EFL_GFX_HINT_EXPAND),
242 efl_pack(hbox, efl_added));
243
244 efl_add(EFL_UI_SLIDER_CLASS, hbox,
245 efl_ui_range_limits_set(efl_added, 0.0, 1.0),
246 efl_ui_range_step_set(efl_added, 0.1),
247 efl_ui_range_value_set(efl_added, align_x),
248 efl_key_wref_set(efl_added, "btn", btn),
249 efl_event_callback_add(efl_added, EFL_UI_RANGE_EVENT_CHANGED, _slider_changed_align_cb, (void *)'x'),
250 efl_pack(hbox, efl_added));
251
252 hbox = efl_add(EFL_UI_BOX_CLASS, vbox,
253 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
254 efl_gfx_arrangement_content_padding_set(efl_added, 2, 2),
255 efl_pack(vbox, efl_added));
256
257 efl_add(EFL_UI_TEXT_CLASS, hbox,
258 efl_text_set(efl_added, "align_y"),
259 efl_text_interactive_editable_set(efl_added, EINA_FALSE),
260 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(40, 0)),
261 efl_gfx_hint_weight_set(efl_added, 0, EFL_GFX_HINT_EXPAND),
262 efl_pack(hbox, efl_added));
263
264 efl_add(EFL_UI_SLIDER_CLASS, hbox,
265 efl_ui_range_limits_set(efl_added, 0.0, 1.0),
266 efl_ui_range_step_set(efl_added, 0.1),
267 efl_ui_range_value_set(efl_added, align_y),
268 efl_key_wref_set(efl_added, "btn", btn),
269 efl_event_callback_add(efl_added, EFL_UI_RANGE_EVENT_CHANGED, _slider_changed_align_cb, (void *)'y'),
270 efl_pack(hbox, efl_added));
271}
272
273void
274test_ui_relative_container(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
275{
276 Eo *win, *vbox, *f, *hbox;
277
278 win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
279 efl_text_set(efl_added, "Efl.Ui.Relative_Container"),
280 efl_ui_win_autodel_set(efl_added, EINA_TRUE));
281
282 vbox = efl_add(EFL_UI_BOX_CLASS, win,
283 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL),
284 efl_gfx_arrangement_content_padding_set(efl_added, 10, 10),
285 efl_gfx_hint_margin_set(efl_added, 5, 5, 5, 5),
286 efl_content_set(win, efl_added));
287
288 /* controls */
289 f = efl_add(EFL_UI_FRAME_CLASS, vbox,
290 efl_text_set(efl_added, "Controls"),
291 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
292 efl_pack(vbox, efl_added));
293
294 hbox = efl_add(EFL_UI_BOX_CLASS, f,
295 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
296 efl_gfx_arrangement_content_padding_set(efl_added, 10, 0),
297 efl_content_set(f, efl_added));
298
299 /* contents */
300 f = efl_add(EFL_UI_FRAME_CLASS, vbox,
301 efl_text_set(efl_added, "Contents"),
302 efl_pack(vbox, efl_added));
303
304 layout = efl_add(EFL_UI_RELATIVE_CONTAINER_CLASS, f,
305 efl_content_set(f, efl_added));
306
307 btn1 = efl_add(EFL_UI_BUTTON_CLASS, layout,
308 efl_text_set(efl_added, "button1"),
309 efl_gfx_hint_align_set(efl_added, 0.0, 0.0),
310 efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, _btn_color_clicked_cb, layout),
311 efl_ui_relative_container_relation_right_set(layout, efl_added, layout, 0.0),
312 efl_ui_relative_container_relation_bottom_set(layout, efl_added, layout, 0.0));
313
314 btn2 = efl_add(EFL_UI_BUTTON_CLASS, layout,
315 efl_text_set(efl_added, "button2"),
316 efl_gfx_hint_align_set(efl_added, 0.5, 0.0),
317 efl_ui_relative_container_relation_left_set(layout, efl_added, btn1, 1.0),
318 efl_ui_relative_container_relation_bottom_set(layout, efl_added, layout, 0.0));
319
320 btn3 = efl_add(EFL_UI_BUTTON_CLASS, layout,
321 efl_text_set(efl_added, "button3"),
322 efl_ui_relative_container_relation_left_set(layout, efl_added, btn2, 0.0),
323 efl_ui_relative_container_relation_top_set(layout, efl_added, btn2, 1.0));
324
325 _button_frame_add(hbox, btn1);
326 _button_frame_add(hbox, btn2);
327 _button_frame_add(hbox, btn3);
328
329 efl_gfx_entity_size_set(win, EINA_SIZE2D(600, 400));
330 efl_gfx_entity_visible_set(win, EINA_TRUE);
331}