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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
#include "test.h"
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#define EFL_PACK_LAYOUT_PROTECTED
#include <Elementary.h>
#include <assert.h>
#define CNT 10
static Evas_Object *objects[CNT] = {};
typedef enum {
NONE,
NONE_BUT_FILL,
EQUAL,
ONE,
TWO
} Weight_Mode;
static Eina_Bool
weights_cb(void *data, const Eo_Event *event)
{
Weight_Mode mode = elm_radio_state_value_get(event->obj);
switch (mode)
{
case NONE:
evas_object_size_hint_align_set(data, 0.5, 0.5);
for (int i = 0; i < CNT; i++)
evas_object_size_hint_weight_set(objects[i], 0, 0);
break;
case NONE_BUT_FILL:
evas_object_size_hint_align_set(data, -1, -1);
for (int i = 0; i < CNT; i++)
evas_object_size_hint_weight_set(objects[i], 0, 0);
break;
case EQUAL:
evas_object_size_hint_align_set(data, 0.5, 0.5);
for (int i = 0; i < CNT; i++)
evas_object_size_hint_weight_set(objects[i], 1, 1);
break;
case ONE:
evas_object_size_hint_align_set(data, 0.5, 0.5);
for (int i = 0; i < 6; i++)
evas_object_size_hint_weight_set(objects[i], 0, 0);
evas_object_size_hint_weight_set(objects[6], 1, 1);
for (int i = 7; i < CNT; i++)
evas_object_size_hint_weight_set(objects[i], 0, 0);
break;
case TWO:
evas_object_size_hint_align_set(data, 0.5, 0.5);
for (int i = 0; i < 5; i++)
evas_object_size_hint_weight_set(objects[i], 0, 0);
evas_object_size_hint_weight_set(objects[5], 1, 1);
evas_object_size_hint_weight_set(objects[6], 1, 1);
for (int i = 7; i < CNT; i++)
evas_object_size_hint_weight_set(objects[i], 0, 0);
break;
}
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
request_slider_cb(void *data EINA_UNUSED, const Eo_Event *event)
{
int val = elm_slider_value_get(event->obj);
evas_object_size_hint_request_set(objects[3], val, val);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
padding_slider_cb(void *data, const Eo_Event *event)
{
int val = elm_slider_value_get(event->obj);
efl_pack_padding_set(data, val, val, EINA_TRUE);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
margin_slider_cb(void *data, const Eo_Event *event)
{
int val = elm_slider_value_get(event->obj);
evas_object_size_hint_padding_set(data, val, val, val, val);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
alignh_slider_cb(void *data, const Eo_Event *event)
{
double av, val;
val = elm_slider_value_get(event->obj);
efl_pack_align_get(data, NULL, &av);
efl_pack_align_set(data, val, av);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
alignv_slider_cb(void *data, const Eo_Event *event)
{
double ah, val;
val = elm_slider_value_get(event->obj);
efl_pack_align_get(data, &ah, NULL);
efl_pack_align_set(data, ah, val);
return EO_CALLBACK_CONTINUE;
}
static Efl_Ui_Box_Flow_Params s_flow_params = { 0, 0 };
static Eina_Bool flow = EINA_FALSE;
static Eina_Bool
flow_check_cb(void *data, const Eo_Event *event)
{
flow = elm_check_selected_get(event->obj);
efl_pack_layout_engine_set(data, flow ? EFL_UI_BOX_FLOW_CLASS : NULL, &s_flow_params);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
horiz_check_cb(void *data, const Eo_Event *event)
{
Eina_Bool chk = elm_check_selected_get(event->obj);
efl_pack_direction_set(data, chk ? EFL_ORIENT_HORIZONTAL : EFL_ORIENT_VERTICAL);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
homo_check_cb(void *data, const Eo_Event *event)
{
Eina_Bool chk = elm_check_selected_get(event->obj);
s_flow_params.homogenous = chk;
efl_pack_layout_engine_set(data, flow ? EFL_UI_BOX_FLOW_CLASS : NULL, &s_flow_params);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
max_size_check_cb(void *data, const Eo_Event *event)
{
Eina_Bool chk = elm_check_selected_get(event->obj);
s_flow_params.max_size = chk;
efl_pack_layout_engine_set(data, flow ? EFL_UI_BOX_FLOW_CLASS : NULL, &s_flow_params);
return EO_CALLBACK_CONTINUE;
}
static Eina_Bool
left_check_cb(void *data, const Eo_Event *event)
{
Eina_Bool chk = elm_check_selected_get(event->obj);
if (chk)
{
efl_pack_align_set(data, 0, 0.5);
}
else
{
efl_pack_align_set(data, 0.5, 0.5);
}
return EO_CALLBACK_CONTINUE;
}
static void
_custom_engine_layout_do(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED,
Efl_Pack *pack, const void *data EINA_UNUSED)
{
Eina_Iterator *it = efl_pack_contents_get(pack);
int count = efl_pack_contents_count(pack), i = 0;
int px, py, pw, ph;
Eo *sobj;
// Note: This is a TERRIBLE layout. Just an example of the API, not showing
// how to write a proper layout function.
evas_object_geometry_get(pack, &px, &py, &pw, &ph);
EINA_ITERATOR_FOREACH(it, sobj)
{
int x, y, h, w, mw, mh;
evas_object_size_hint_min_get(sobj, &mw, &mh);
x = (pw / count) * i;
y = (ph / count) * i;
w = mw;
h = mh;
evas_object_geometry_set(sobj, x + px, y + py, w, h);
i++;
}
eina_iterator_free(it);
}
/* Common Eo Class boilerplate. */
static const Eo_Op_Description custom_engine_op_desc[] = {
EO_OP_CLASS_FUNC_OVERRIDE(efl_pack_layout_do, _custom_engine_layout_do),
};
static const Eo_Class_Description custom_engine_class_desc = {
EO_VERSION, "Custom Layout Engine", EO_CLASS_TYPE_INTERFACE,
EO_CLASS_DESCRIPTION_OPS(custom_engine_op_desc), NULL, 0, NULL, NULL
};
EO_DEFINE_CLASS(_test_ui_box_custom_engine_class_get, &custom_engine_class_desc, EFL_PACK_LAYOUT_INTERFACE, NULL)
static Eina_Bool
custom_check_cb(void *data, const Eo_Event *event)
{
Eina_Bool chk = elm_check_selected_get(event->obj);
efl_pack_layout_engine_set(data, chk ? _test_ui_box_custom_engine_class_get() : NULL, NULL);
return EO_CALLBACK_CONTINUE;
}
void
test_ui_box(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win, *bx, *o, *vbox, *f, *hbox, *chk, *bottombox;
int i = 0;
win = elm_win_util_standard_add("ui-box", "Efl.Ui.Box");
elm_win_autodel_set(win, EINA_TRUE);
efl_gfx_size_set(win, 600, 400);
vbox = eo_add(EFL_UI_BOX_CLASS, win);
efl_pack_padding_set(vbox, 10, 10, EINA_TRUE);
efl_pack_direction_set(vbox, EFL_ORIENT_DOWN);
evas_object_size_hint_weight_set(vbox, 1, 1);
evas_object_size_hint_padding_set(vbox, 5, 5, 5, 5);
elm_win_resize_object_add(win, vbox);
efl_gfx_visible_set(vbox, 1);
// create here to pass in cb
bottombox = eo_add(EFL_UI_BOX_CLASS, win);
/* controls */
f = elm_frame_add(win);
elm_object_text_set(f, "Controls");
evas_object_size_hint_align_set(f, -1, -1);
evas_object_size_hint_weight_set(f, 1, 0);
efl_pack(vbox, f);
efl_gfx_visible_set(f, 1);
hbox = eo_add(EFL_UI_BOX_CLASS, win);
elm_object_content_set(f, hbox);
efl_pack_padding_set(hbox, 10, 0, EINA_TRUE);
efl_gfx_visible_set(hbox, 1);
/* weights radio group */
bx = eo_add(EFL_UI_BOX_CLASS, win,
efl_pack_direction_set(eo_self, EFL_ORIENT_DOWN));
evas_object_size_hint_align_set(bx, 0, -1);
efl_pack(hbox, bx);
efl_gfx_visible_set(bx, 1);
chk = o = elm_radio_add(win);
elm_object_text_set(o, "No weight");
eo_event_callback_add(o, ELM_RADIO_EVENT_CHANGED, weights_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0.5);
elm_radio_state_value_set(o, NONE);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_radio_add(win);
elm_object_text_set(o, "No weight + box fill");
eo_event_callback_add(o, ELM_RADIO_EVENT_CHANGED, weights_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0.5);
elm_radio_state_value_set(o, NONE_BUT_FILL);
elm_radio_group_add(o, chk);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_radio_add(win);
elm_object_text_set(o, "Equal weights");
eo_event_callback_add(o, ELM_RADIO_EVENT_CHANGED, weights_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0.5);
elm_radio_state_value_set(o, EQUAL);
elm_radio_group_add(o, chk);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_radio_add(win);
elm_object_text_set(o, "One weight only");
eo_event_callback_add(o, ELM_RADIO_EVENT_CHANGED, weights_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0.5);
elm_radio_state_value_set(o, ONE);
elm_radio_group_add(o, chk);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_radio_add(win);
elm_object_text_set(o, "Two weights");
eo_event_callback_add(o, ELM_RADIO_EVENT_CHANGED, weights_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0.5);
elm_radio_state_value_set(o, TWO);
elm_radio_group_add(o, chk);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
elm_radio_value_set(chk, NONE);
/* misc */
bx = eo_add(EFL_UI_BOX_CLASS, win,
efl_pack_direction_set(eo_self, EFL_ORIENT_DOWN));
evas_object_size_hint_align_set(bx, 0, -1);
evas_object_size_hint_weight_set(bx, 0, 1);
efl_pack(hbox, bx);
efl_gfx_visible_set(bx, 1);
o = elm_label_add(win);
elm_object_text_set(o, "Misc");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_check_add(win);
elm_check_selected_set(o, 0);
elm_object_text_set(o, "Flow");
eo_event_callback_add(o, ELM_CHECK_EVENT_CHANGED, flow_check_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_check_add(win);
elm_check_selected_set(o, 1);
elm_object_text_set(o, "Horizontal");
eo_event_callback_add(o, ELM_CHECK_EVENT_CHANGED, horiz_check_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_check_add(win);
elm_check_selected_set(o, 0);
elm_object_text_set(o, "Homogenous");
eo_event_callback_add(o, ELM_CHECK_EVENT_CHANGED, homo_check_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_check_add(win);
elm_check_selected_set(o, 0);
elm_object_text_set(o, "Homogenous + Max");
eo_event_callback_add(o, ELM_CHECK_EVENT_CHANGED, max_size_check_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_check_add(win);
elm_check_selected_set(o, 0);
elm_object_text_set(o, "Align left");
eo_event_callback_add(o, ELM_CHECK_EVENT_CHANGED, left_check_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_check_add(win);
elm_check_selected_set(o, 0);
elm_object_text_set(o, "Custom layout");
eo_event_callback_add(o, ELM_CHECK_EVENT_CHANGED, custom_check_cb, bottombox);
evas_object_size_hint_align_set(o, 0, 0);
evas_object_size_hint_weight_set(o, 0, 1);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
/* requested size setter */
bx = eo_add(EFL_UI_BOX_CLASS, win,
efl_pack_direction_set(eo_self, EFL_ORIENT_DOWN));
evas_object_size_hint_align_set(bx, 0, -1);
evas_object_size_hint_weight_set(bx, 0, 1);
efl_pack(hbox, bx);
efl_gfx_visible_set(bx, 1);
o = elm_label_add(win);
elm_object_text_set(o, "Requested size");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_slider_add(win);
elm_slider_indicator_format_set(o, "%.0fpx");
elm_slider_indicator_show_set(o, 1);
elm_slider_horizontal_set(o, 0);
evas_object_size_hint_align_set(o, 0.5, -1);
evas_object_size_hint_weight_set(o, 1, 1);
eo_event_callback_add(o, ELM_SLIDER_EVENT_CHANGED, request_slider_cb, NULL);
elm_slider_min_max_set(o, 0, 250);
elm_slider_inverted_set(o, 1);
elm_slider_value_set(o, 0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
/* inner box padding */
bx = eo_add(EFL_UI_BOX_CLASS, win,
efl_pack_direction_set(eo_self, EFL_ORIENT_DOWN));
evas_object_size_hint_align_set(bx, 0, -1);
evas_object_size_hint_weight_set(bx, 0, 1);
efl_pack(hbox, bx);
efl_gfx_visible_set(bx, 1);
o = elm_label_add(win);
elm_object_text_set(o, "Padding");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_slider_add(win);
elm_slider_indicator_format_set(o, "%.0fpx");
elm_slider_indicator_show_set(o, 1);
elm_slider_horizontal_set(o, 0);
evas_object_size_hint_align_set(o, 0.5, -1);
evas_object_size_hint_weight_set(o, 1, 1);
eo_event_callback_add(o, ELM_SLIDER_EVENT_CHANGED, padding_slider_cb, bottombox);
elm_slider_min_max_set(o, 0, 40);
elm_slider_inverted_set(o, 1);
elm_slider_value_set(o, 10);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
/* outer margin */
bx = eo_add(EFL_UI_BOX_CLASS, win,
efl_pack_direction_set(eo_self, EFL_ORIENT_DOWN));
evas_object_size_hint_align_set(bx, 0, -1);
evas_object_size_hint_weight_set(bx, 0, 1);
efl_pack(hbox, bx);
efl_gfx_visible_set(bx, 1);
o = elm_label_add(win);
elm_object_text_set(o, "Margin");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_slider_add(win);
elm_slider_indicator_format_set(o, "%.0fpx");
elm_slider_indicator_show_set(o, 1);
elm_slider_horizontal_set(o, 0);
evas_object_size_hint_align_set(o, 0.5, -1);
evas_object_size_hint_weight_set(o, 1, 1);
eo_event_callback_add(o, ELM_SLIDER_EVENT_CHANGED, margin_slider_cb, bottombox);
elm_slider_min_max_set(o, 0, 40);
elm_slider_inverted_set(o, 1);
elm_slider_value_set(o, 10);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
/* Box align */
bx = eo_add(EFL_UI_BOX_CLASS, win,
efl_pack_direction_set(eo_self, EFL_ORIENT_DOWN));
evas_object_size_hint_align_set(bx, 0, -1);
evas_object_size_hint_weight_set(bx, 1, 1);
efl_pack(hbox, bx);
efl_gfx_visible_set(bx, 1);
o = elm_label_add(win);
elm_object_text_set(o, "Box align");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_slider_add(win);
elm_slider_indicator_format_set(o, "%.1f");
elm_slider_indicator_show_set(o, 1);
elm_slider_horizontal_set(o, 0);
evas_object_size_hint_align_set(o, 0.5, -1);
evas_object_size_hint_weight_set(o, 1, 1);
eo_event_callback_add(o, ELM_SLIDER_EVENT_CHANGED, alignv_slider_cb, bottombox);
elm_slider_min_max_set(o, -0.1, 1.0);
elm_slider_step_set(o, 0.1);
elm_slider_value_set(o, 0.5);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
o = elm_slider_add(win);
elm_slider_indicator_format_set(o, "%.1f");
elm_slider_indicator_show_set(o, 1);
elm_slider_horizontal_set(o, 1);
evas_object_size_hint_align_set(o, 0.5, -1);
evas_object_size_hint_weight_set(o, 1, 0);
evas_object_size_hint_request_set(o, 100, 0);
eo_event_callback_add(o, ELM_SLIDER_EVENT_CHANGED, alignh_slider_cb, bottombox);
elm_slider_min_max_set(o, -0.1, 1.0);
elm_slider_step_set(o, 0.1);
elm_slider_value_set(o, 0.5);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
/* contents */
f = elm_frame_add(win);
elm_object_text_set(f, "Contents");
evas_object_size_hint_align_set(f, -1, -1);
evas_object_size_hint_weight_set(f, 1, 1);
efl_pack(vbox, f);
efl_gfx_visible_set(f, 1);
bx = bottombox;
efl_pack_padding_set(bx, 10, 10, EINA_TRUE);
evas_object_size_hint_align_set(bx, 0.5, 0.5);
evas_object_size_hint_weight_set(bx, 1, 1);
elm_object_content_set(f, bx);
efl_gfx_visible_set(bx, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "Btn1");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "Button 2");
evas_object_size_hint_align_set(o, -1, -1);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_label_add(win);
elm_label_line_wrap_set(o, ELM_WRAP_WORD);
elm_object_text_set(o, "This label is not marked as fill");
evas_object_size_hint_align_set(o, 0.5, 0.5);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "Requested size example");
evas_object_size_hint_align_set(o, 0.5, 1.0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "Quit!");
evas_object_size_hint_align_set(o, 0.5, 0.0);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_label_add(win);
elm_label_line_wrap_set(o, ELM_WRAP_WORD);
elm_object_text_set(o, "This label on the other hand<br/>is marked as align=fill.");
evas_object_size_hint_align_set(o, -1, -1);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "Button with a quite long text.");
evas_object_size_hint_align_set(o, -1, -1);
evas_object_size_hint_max_set(o, 200, 100);
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "BtnA");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "BtnB");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
objects[i++] = o = elm_button_add(win);
elm_object_text_set(o, "BtnC");
efl_pack(bx, o);
efl_gfx_visible_set(o, 1);
assert(i == CNT);
efl_gfx_visible_set(win, 1);
}
|