summaryrefslogtreecommitdiff
path: root/src/bin/elementary/test_grid_static.c
blob: 0cb89360c761c0fc582d9bbf19c2617efcf42153 (plain)
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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Elementary.h>

struct _Api_Data
{
   Eo *grid;
   Eo *child;
};
typedef struct _Api_Data Api_Data;

struct _api_data
{
   unsigned int state;  /* What state we are testing       */
   Api_Data data;
};
typedef struct _api_data api_data;

enum _api_state
{
   GRID_PACK_SET,
   GRID_UNPACK,
   GRID_SIZE,
   GRID_CLEAR,
   API_STATE_LAST
};
typedef enum _api_state api_state;

static void
set_api_state(api_data *api)
{
   Api_Data *dt = &api->data;
   int w, h;

   switch(api->state)
     { /* Put all api-changes under switch */
      case GRID_PACK_SET: /* 0 */
         efl_pack_grid(dt->grid, dt->child, 5, 15, 60, 40);
         break;

      case GRID_UNPACK: /* 1 */
         efl_pack_unpack(dt->grid, dt->child);
         eo_del(dt->child);
         break;

      case GRID_SIZE: /* 2 */
         efl_pack_grid_size_get(dt->grid, &w, &h);
         printf("size w=<%d> h=<%d>\n", w, h);
         w = h = 100; /* grid size returns wrong values */
         w += 30;
         h += 10;

         efl_pack_grid_size_set(dt->grid, w, h);
         break;

      case GRID_CLEAR: /* 3 */
         efl_pack_clear(dt->grid);
         break;

      default:
         return;
     }
}

static Eina_Bool
_api_bt_clicked(void *data, const Eo_Event *ev)
{  /* Will add here a SWITCH command containing code to modify test-object */
   /* in accordance a->state value. */
   api_data *a = data;
   char str[128];

   printf("clicked event on API Button: api_state=<%d>\n", a->state);
   set_api_state(a);
   a->state++;
   sprintf(str, "Next API function (%u)", a->state);
   elm_object_text_set(ev->object, str);
   elm_object_disabled_set(ev->object, a->state == API_STATE_LAST);
   return 1;
}

static Eina_Bool
_ch_grid(void *data, const Eo_Event *ev)
{
   Eo *gd = data;
   int x, y, w, h;

   // FIXME: old elm_grid API doesn't need grid object
   //elm_grid_pack_get(obj, &x, &y, &w, &h);
   //elm_grid_pack_set(obj, x - 1, y - 1, w + 2, h + 2);
   efl_pack_grid_position_get(gd, ev->object, &x, &y, &w, &h);
   efl_pack_grid(gd, ev->object, x - 1, y - 1, w + 2, h + 2);
   return 1;
}

static Eina_Bool
_win_del(void *data, const Eo_Event *ev EINA_UNUSED)
{
   free(data);
   return 1;
}

void
test_grid_static(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eo *win, *gd, *bt, *rc, *en;
   api_data *api = calloc(1, sizeof(*api));

   win = eo_add(EFL_UI_WIN_STANDARD_CLASS, NULL,
                efl_ui_win_name_set(eo_self, "grid"),
                efl_text_set(eo_self, "Grid"),
                efl_ui_win_autodel_set(eo_self, EINA_TRUE),
                eo_event_callback_add(eo_self, EO_EVENT_DEL, _win_del, api));

   static int run_count = 0;
   if (((run_count++) % 2) == 0)
     {
        gd = eo_add(EFL_UI_GRID_STATIC_CLASS, win,
                    efl_gfx_size_hint_weight_set(eo_self, 1, 1));
     }
   else
     {
        gd = eo_add(EFL_UI_GRID_CLASS, win,
                    efl_gfx_size_hint_weight_set(eo_self, 1, 1),
                    efl_pack_layout_engine_set(eo_self, EFL_UI_GRID_STATIC_CLASS, NULL));
     }
   efl_pack(win, gd);
   api->data.grid = gd;
   efl_gfx_visible_set(gd, 1);

   /* FIXME: EO-ify entry & button & test_set! */

   en = elm_entry_add(win);
   elm_entry_scrollable_set(en, EINA_TRUE);
   elm_object_text_set(en, "Entry text");
   elm_entry_single_line_set(en, EINA_TRUE);
   efl_pack_grid(gd, en, 50, 10, 40, 10);
   efl_gfx_visible_set(en, 1);

   en = elm_entry_add(win);
   elm_entry_scrollable_set(en, EINA_TRUE);
   elm_object_text_set(en, "Entry text 2");
   elm_entry_single_line_set(en, EINA_TRUE);
   efl_pack_grid(gd, en, 60, 20, 30, 10);
   efl_gfx_visible_set(en, 1);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Next API function");
   eo_event_callback_add(bt, EFL_UI_EVENT_CLICKED, _api_bt_clicked, api);
   efl_pack_grid(gd, bt, 30, 0, 40, 10);
   elm_object_disabled_set(bt, api->state == API_STATE_LAST);
   efl_gfx_visible_set(bt, 1);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Button");
   efl_pack_grid(gd, bt,  0,  0, 20, 20);
   efl_gfx_visible_set(bt, 1);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Button");
   efl_pack_grid(gd, bt, 10, 10, 40, 20);
   api->data.child = bt;
   efl_gfx_visible_set(bt, 1);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Button");
   efl_pack_grid(gd, bt, 10, 30, 20, 50);
   efl_gfx_visible_set(bt, 1);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Button");
   efl_pack_grid(gd, bt, 80, 80, 20, 20);
   efl_gfx_visible_set(bt, 1);

   bt = elm_button_add(win);
   elm_object_text_set(bt, "Change");
   efl_pack_grid(gd, bt, 40, 40, 20, 20);
   eo_event_callback_add(bt, EFL_UI_EVENT_CLICKED, _ch_grid, gd);
   efl_gfx_visible_set(bt, 1);

   rc = eo_add(EFL_CANVAS_RECTANGLE_CLASS, win);
   efl_gfx_color_set(rc, 128, 0, 0, 128);
   efl_pack_grid(gd, rc, 40, 70, 20, 10);
   efl_gfx_visible_set(rc, 1);

   rc = eo_add(EFL_CANVAS_RECTANGLE_CLASS, win);
   efl_gfx_color_set(rc, 0, 128, 0, 128);
   efl_pack_grid(gd, rc, 60, 70, 10, 10);
   efl_gfx_visible_set(rc, 1);

   rc = eo_add(EFL_CANVAS_RECTANGLE_CLASS, win);
   efl_gfx_color_set(rc, 0, 0, 128, 128);
   efl_pack_grid(gd, rc, 40, 80, 10, 10);
   efl_gfx_visible_set(rc, 1);

   rc = eo_add(EFL_CANVAS_RECTANGLE_CLASS, win);
   efl_gfx_color_set(rc, 128, 0, 128, 128);
   efl_pack_grid(gd, rc, 50, 80, 10, 10);
   efl_gfx_visible_set(rc, 1);

   rc = eo_add(EFL_CANVAS_RECTANGLE_CLASS, win);
   efl_gfx_color_set(rc, 128, 64, 0, 128);
   efl_pack_grid(gd, rc, 60, 80, 10, 10);
   efl_gfx_visible_set(rc, 1);

   efl_gfx_size_set(win, 480, 480);
   efl_gfx_visible_set(win, 1);
}