aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/elementary/src/bin/test_factory.c
blob: 63a43427004ec266600e9845b6ef72c88601813b (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
#ifndef ELM_LIB_QUICKLAUNCH

// 16 ^ 4 = 65k
#define BLOK 16
// homogenous layout
//#define HOMOG 1
// aligned to top of box
#define ZEROALIGN 1
#define DEFSZ 64

static void
fac_unrealize(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
{
   // setting factory content to null deletes it
   printf("--------DELETE for factory %p [f: %p]\n", elm_object_content_get(obj), obj);
   elm_object_content_set(obj, NULL);
}

static void
fac_realize_end(void *data, Evas_Object *obj, void *event_info __UNUSED__)
{
   Evas_Object *win = data;
   Evas_Object *bx, *bt;
   int i;

   bx = elm_box_add(win);
   printf("   ADD lv 3 = %p [%i]\n", bx, (BLOK * (int)(long)evas_object_data_get(obj, "num")));
#ifdef HOMOG
   elm_box_homogeneous_set(bx, EINA_TRUE);
#endif
#ifdef ZEROALIGN
   elm_box_align_set(bx, 0.0, 0.0);
#endif

   for (i = 0; i < BLOK; i++)
     {
        char buf[32];

        snprintf(buf, sizeof(buf), "%i",
                 (i + (BLOK * (int)(long)evas_object_data_get(obj, "num"))));

        bt = elm_button_add(win);
        evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
        elm_object_text_set(bt, buf);
        elm_box_pack_end(bx, bt);
        evas_object_show(bt);
     }

   elm_object_content_set(obj, bx);
   evas_object_show(bx);
}

static void
fac_realize2(void *data, Evas_Object *obj, void *event_info __UNUSED__)
{
   Evas_Object *win = data;
   Evas_Object *bx, *fc;
   int i;

   bx = elm_box_add(win);
   printf("  ADD lv 2 = %p [%i]\n", bx, (BLOK * (int)(long)evas_object_data_get(obj, "num")));
#ifdef HOMOG
   elm_box_homogeneous_set(bx, EINA_TRUE);
#endif
#ifdef ZEROALIGN
   elm_box_align_set(bx, 0.0, 0.0);
#endif

   for (i = 0; i < BLOK; i++)
     {
        fc = elm_factory_add(win);
        elm_factory_maxmin_mode_set(fc, EINA_TRUE);
        // initial height per factory of DEFSZ
        // scrollbar will be wrong until enough
        // children have been realized and the
        // real size is known
        evas_object_data_set(fc, "num", (void *)(long)(i + (BLOK * (int)(long)evas_object_data_get(obj, "num"))));
        evas_object_size_hint_min_set(fc, 0, DEFSZ);
        evas_object_size_hint_weight_set(fc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(fc, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_smart_callback_add(fc, "realize", fac_realize_end, win);
        evas_object_smart_callback_add(fc, "unrealize", fac_unrealize, win);
        elm_box_pack_end(bx, fc);
        evas_object_show(fc);
     }

   elm_object_content_set(obj, bx);
   evas_object_show(bx);
}

static void
fac_realize1(void *data, Evas_Object *obj, void *event_info __UNUSED__)
{
   Evas_Object *win = data;
   Evas_Object *bx, *fc;
   int i;

   bx = elm_box_add(win);
   printf(" ADD lv 1 = %p [%i]\n", bx, (BLOK * (int)(long)evas_object_data_get(obj, "num")));
#ifdef HOMOG
   elm_box_homogeneous_set(bx, EINA_TRUE);
#endif
#ifdef ZEROALIGN
   elm_box_align_set(bx, 0.0, 0.0);
#endif

   for (i = 0; i < BLOK; i++)
     {
        fc = elm_factory_add(win);
        elm_factory_maxmin_mode_set(fc, EINA_TRUE);
        // initial height per factory of DEFSZ
        // scrollbar will be wrong until enough
        // children have been realized and the
        // real size is known
        evas_object_data_set(fc, "num", (void *)(long)(i + (BLOK * (int)(long)evas_object_data_get(obj, "num"))));
        evas_object_size_hint_min_set(fc, 0, DEFSZ);
        evas_object_size_hint_weight_set(fc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(fc, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_smart_callback_add(fc, "realize", fac_realize2, win);
//        evas_object_smart_callback_add(fc, "unrealize", fac_unrealize, win);
        elm_box_pack_end(bx, fc);
        evas_object_show(fc);
     }

   elm_object_content_set(obj, bx);
   evas_object_show(bx);
}

void
test_factory(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
{
   Evas_Object *win, *bg, *bx, *sc, *fc;
   int i;

   win = elm_win_add(NULL, "factory", ELM_WIN_BASIC);
   elm_win_title_set(win, "Factory");
   elm_win_autodel_set(win, EINA_TRUE);

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

   bx = elm_box_add(win);
#ifdef HOMOG
   elm_box_homogeneous_set(bx, EINA_TRUE);
#endif
#ifdef ZEROALIGN
   elm_box_align_set(bx, 0.0, 0.0);
#endif
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, 0.0);

   for (i = 0; i < BLOK; i++)
     {
        fc = elm_factory_add(win);
        elm_factory_maxmin_mode_set(fc, EINA_TRUE);
        // initial height per factory of DEFSZ
        // scrollbar will be wrong until enough
        // children have been realized and the
        // real size is known
        evas_object_data_set(fc, "num", (void *)(long)i);
        evas_object_size_hint_min_set(fc, 0, DEFSZ);
        evas_object_size_hint_weight_set(fc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(fc, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_smart_callback_add(fc, "realize", fac_realize1, win);
//        evas_object_smart_callback_add(fc, "unrealize", fac_unrealize, win);
        elm_box_pack_end(bx, fc);
        evas_object_show(fc);
     }

   sc = elm_scroller_add(win);
   elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE);
   evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, sc);

   elm_object_content_set(sc, bx);
   evas_object_show(bx);

   evas_object_show(sc);

   evas_object_resize(win, 320, 480);
   evas_object_show(win);
}
#endif