1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #ifdef _WIN32
6 # include <evil_private.h> /* strcasestr */
7 #endif
8
9 #include <Elementary.h>
10
11 enum _slide_style
12 {
13 SLIDE_SHORT,
14 SLIDE_LONG,
15 SLIDE_BOUNCE,
16 SLIDE_STYLE_LAST
17 };
18
19 /*** Label *******************************************************************/
20 void
test_label(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)21 test_label(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
22 {
23 Evas_Object *win, *bx, *lb;
24
25 win = elm_win_util_standard_add("label", "Label");
26 elm_win_autodel_set(win, EINA_TRUE);
27
28 bx = elm_box_add(win);
29 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
30
31 lb = elm_label_add(win);
32 elm_object_text_set(lb,
33 "<b>This is a small label</b>"
34 );
35 evas_object_size_hint_weight_set(lb, 0.0, 0.0);
36 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
37 elm_box_pack_end(bx, lb);
38 evas_object_show(lb);
39
40 lb = elm_label_add(win);
41 elm_object_text_set(lb,
42 "This is a larger label with newlines<br/>"
43 "to make it bigger, bit it won't expand or wrap<br/>"
44 "just be a block of text that can't change its<br/>"
45 "formatting as it's fixed based on text<br/>"
46 );
47 evas_object_size_hint_weight_set(lb, 0.0, 0.0);
48 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
49 elm_box_pack_end(bx, lb);
50 evas_object_show(lb);
51
52 lb = elm_label_add(win);
53 elm_label_line_wrap_set(lb, ELM_WRAP_CHAR);
54 elm_object_text_set(lb,
55 "<b>"
56 "This is more text designed to line-wrap here as "
57 "This object is resized horizontally. As it is "
58 "resized vertically though, nothing should change. "
59 "The amount of space allocated vertically should "
60 "change as horizontal size changes."
61 "</b>"
62 );
63 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
64 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
65 elm_box_pack_end(bx, lb);
66 evas_object_show(lb);
67
68 lb = elm_label_add(win);
69 elm_object_text_set(lb,
70 "This small label set to wrap"
71 );
72 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
73 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
74 elm_box_pack_end(bx, lb);
75 evas_object_show(lb);
76
77 lb = elm_label_add(win);
78 elm_object_text_set(lb,
79 "You can also use all the default entry style tags, like "
80 "<hilight>hilight</hilight>, <success>success</success>, "
81 "<bigger>bigger</bigger>, <smaller>smaller</smaller>, etc..."
82 );
83 elm_label_line_wrap_set(lb, ELM_WRAP_WORD);
84 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
85 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
86 elm_box_pack_end(bx, lb);
87 evas_object_show(lb);
88
89 evas_object_resize(win, 320, 300);
90
91 evas_object_show(bx);
92 evas_object_show(win);
93 elm_win_resize_object_add(win, bx);
94 }
95
96 /*** Label Slide *************************************************************/
97 static void
_cb_size_radio_changed(void * data,Evas_Object * obj,void * event EINA_UNUSED)98 _cb_size_radio_changed(void *data, Evas_Object *obj, void *event EINA_UNUSED)
99 {
100 Evas_Object *lb = data;
101 int style = elm_radio_value_get((Evas_Object *)obj);
102 switch (style)
103 {
104 case SLIDE_SHORT:
105 elm_object_style_set(lb, "slide_short");
106 break;
107
108 case SLIDE_LONG:
109 elm_object_style_set(lb, "slide_long");
110 break;
111
112 case SLIDE_BOUNCE:
113 elm_object_style_set(lb, "slide_bounce");
114 break;
115
116 default:
117 return;
118 }
119 }
120
121 static void
_duration_change_cb(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)122 _duration_change_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
123 {
124 Evas_Object *lb = data;
125 double val = elm_slider_value_get(obj);
126
127 elm_label_slide_duration_set(lb, val);
128 elm_label_slide_go(lb);
129
130 Evas_Object *sl = evas_object_data_get(lb, "speed_slider");
131 elm_slider_value_set(sl, elm_label_slide_speed_get(lb));
132 }
133
134 static void
_speed_change_cb(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)135 _speed_change_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
136 {
137 Evas_Object *lb = data;
138 double val = elm_slider_value_get(obj);
139
140 elm_label_slide_speed_set(lb, val);
141 elm_label_slide_go(lb);
142
143 Evas_Object *sl = evas_object_data_get(lb, "duration_slider");
144 elm_slider_value_set(sl, elm_label_slide_duration_get(lb));
145 }
146
147 static void
_label_resize_cb(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)148 _label_resize_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
149 void *event_info EINA_UNUSED)
150 {
151 Evas_Object *speed_slider = evas_object_data_get(obj, "speed_slider");
152 Evas_Object *duration_slider = evas_object_data_get(obj, "duration_slider");
153
154 elm_slider_value_set(duration_slider, elm_label_slide_duration_get(obj));
155 elm_slider_value_set(speed_slider, elm_label_slide_speed_get(obj));
156 }
157
158 static void
_label_slide_stop_cb(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)159 _label_slide_stop_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
160 {
161 Eina_List *lbs = data, *itr;
162 Evas_Object *lb;
163 EINA_LIST_FOREACH(lbs, itr, lb)
164 {
165 elm_label_slide_speed_set(lb, 0.01);
166 elm_label_slide_go(lb);
167 }
168 }
169
170 void
test_label_slide(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)171 test_label_slide(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
172 {
173 Evas_Object *win, *gd, *rect, *lb, *lb1, *lb2, *rd, *rdg, *sl, *bt;
174 Eina_List *lbs = NULL;
175
176 win = elm_win_util_standard_add("label-slide", "Label Slide");
177 elm_win_autodel_set(win, EINA_TRUE);
178
179 gd = elm_grid_add(win);
180 elm_grid_size_set(gd, 100, 100);
181 evas_object_size_hint_weight_set(gd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
182 elm_win_resize_object_add(win, gd);
183 evas_object_show(gd);
184
185 /* Test Label Slide */
186 lb = elm_label_add(win);
187 elm_object_text_set(lb, "<b>Test Label Slide:</b>");
188 elm_grid_pack(gd, lb, 5, 0, 90, 10);
189 evas_object_show(lb);
190
191 rect = evas_object_rectangle_add(evas_object_evas_get(win));
192 elm_grid_pack(gd, rect, 5, 10, 90, 10);
193 evas_object_color_set(rect, 55, 125, 250, 255);
194 evas_object_show(rect);
195
196 lb = elm_label_add(win);
197 elm_object_style_set(lb, "slide_short");
198 elm_object_text_set(lb,
199 "This is a label set to slide. "
200 "If set slide to true the text of the label "
201 "will slide/scroll through the length of label."
202 "This only works with the themes \"slide_short\", "
203 "\"slide_long\" and \"slide_bounce\"."
204 );
205 elm_label_slide_mode_set(lb, ELM_LABEL_SLIDE_MODE_AUTO);
206 elm_label_slide_speed_set(lb, 40.0);
207 elm_label_slide_go(lb);
208 elm_grid_pack(gd, lb, 5, 10, 90, 10);
209 evas_object_show(lb);
210 lbs = eina_list_append(lbs, lb);
211
212 /* The speed or the duration of the slide animation will change when the
213 * label change size, so we need to update the sliders on resize. */
214 evas_object_event_callback_add(lb, EVAS_CALLBACK_RESIZE, _label_resize_cb, NULL);
215
216 rd = elm_radio_add(win);
217 elm_radio_state_value_set(rd, SLIDE_SHORT);
218 elm_object_text_set(rd, "slide_short");
219 evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
220 evas_object_smart_callback_add(rd, "changed", _cb_size_radio_changed, lb);
221 elm_grid_pack(gd, rd, 5, 20, 30, 10);
222 evas_object_show(rd);
223 rdg = rd;
224
225 rd = elm_radio_add(win);
226 elm_radio_state_value_set(rd, SLIDE_LONG);
227 elm_radio_group_add(rd, rdg);
228 elm_object_text_set(rd, "slide_long");
229 evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
230 evas_object_smart_callback_add(rd, "changed", _cb_size_radio_changed, lb);
231 elm_grid_pack(gd, rd, 35, 20, 30, 10);
232 evas_object_show(rd);
233
234 rd = elm_radio_add(win);
235 elm_radio_state_value_set(rd, SLIDE_BOUNCE);
236 elm_radio_group_add(rd, rdg);
237 elm_object_text_set(rd, "slide_bounce");
238 evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
239 evas_object_smart_callback_add(rd, "changed", _cb_size_radio_changed, lb);
240 elm_grid_pack(gd, rd, 65, 20, 30, 10);
241 evas_object_show(rd);
242
243 sl = elm_slider_add(win);
244 elm_object_text_set(sl, "Slide Duration");
245 elm_slider_unit_format_set(sl, "%1.1f sec");
246 elm_slider_min_max_set(sl, 3, 40);
247 elm_slider_value_set(sl, elm_label_slide_duration_get(lb));
248 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
249 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
250 evas_object_smart_callback_add(sl, "changed", _duration_change_cb, lb);
251 evas_object_data_set(lb, "duration_slider", sl);
252 elm_grid_pack(gd, sl, 5, 30, 90, 10);
253 evas_object_show(sl);
254
255 sl = elm_slider_add(win);
256 elm_object_text_set(sl, "Slide Speed");
257 elm_slider_unit_format_set(sl, "%1.1f px/sec");
258 elm_slider_min_max_set(sl, 40, 300);
259 elm_slider_value_set(sl, elm_label_slide_speed_get(lb));
260 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
261 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
262 evas_object_smart_callback_add(sl, "changed", _speed_change_cb, lb);
263 evas_object_data_set(lb, "speed_slider", sl);
264 elm_grid_pack(gd, sl, 5, 40, 90, 10);
265 evas_object_show(sl);
266
267 bt = elm_button_add(win);
268 elm_object_text_set(bt, "Stop sliding");
269 elm_grid_pack(gd, bt, 40, 50, 20, 10);
270 evas_object_show(bt);
271
272 /* Test 2 label at the same speed */
273 lb = elm_label_add(win);
274 elm_object_text_set(lb, "<b>Test 2 label with the same speed:</b>");
275 elm_grid_pack(gd, lb, 5, 60, 90, 10);
276 evas_object_show(lb);
277
278 rect = evas_object_rectangle_add(evas_object_evas_get(win));
279 elm_grid_pack(gd, rect, 5, 70, 90, 20);
280 evas_object_color_set(rect, 55, 125, 250, 255);
281 evas_object_show(rect);
282
283 lb1 = elm_label_add(win);
284 elm_object_style_set(lb1, "slide_short");
285 elm_object_text_set(lb1, "This is a label set to slide with a fixed speed,"
286 " should match the speed with the below label."
287 " This label has few extra char for testing.");
288 elm_label_slide_mode_set(lb1, ELM_LABEL_SLIDE_MODE_ALWAYS);
289 elm_label_slide_speed_set(lb1, 40.0);
290 elm_label_slide_go(lb1);
291 elm_grid_pack(gd, lb1, 5, 70, 90, 10);
292 evas_object_show(lb1);
293 lbs = eina_list_append(lbs, lb1);
294
295 lb2 = elm_label_add(win);
296 elm_object_style_set(lb2, "slide_long");
297 elm_object_text_set(lb2, "This is a label set to slide and will"
298 " match the speed of the upper label.");
299 elm_label_slide_mode_set(lb2, ELM_LABEL_SLIDE_MODE_ALWAYS);
300 elm_label_slide_speed_set(lb2, 40.0);
301 elm_label_slide_go(lb2);
302 elm_grid_pack(gd, lb2, 5, 80, 90, 10);
303 evas_object_show(lb2);
304 lbs = eina_list_append(lbs, lb2);
305
306 evas_object_smart_callback_add(bt, "clicked", _label_slide_stop_cb, lbs);
307
308 evas_object_resize(win, 320, 320);
309 evas_object_show(win);
310 }
311
312
313
314 /*** FIT TEXT **************************************************************/
315 enum BUTTON{
316 BUTTON_MODE = 0,
317 BUTTON_MAX = 1,
318 BUTTON_MIN = 2,
319 BUTTON_STEP = 3,
320 BUTTON_ARRAY = 4,
321 BUTTON_CONTENT = 5,
322 BUTTON_STYLE = 6,
323 BUTTON_ALL = BUTTON_STYLE+1,
324 };
325
326 char* BUTTON_STR[BUTTON_ALL] ={
327 "MODE",
328 "MAX",
329 "MIN",
330 "STEP",
331 "ARRAY",
332 "CONTENT",
333 "STYLE",
334 };
335
336 char *contents[] = {
337 "Hello World",
338 "This is Line<br>THis is other Line",
339 "This text contains <font_size=20 color=#F00>SPECIFIC SIZE</font_size>that does not effected by fit mode"
340 };
341
342 char *styles[] = {
343 "DEFAULT='font=sans font_size=30 color=#000 wrap=mixed ellipsis=1.0'",
344 "DEFAULT='font=sans font_size=30 color=#000 wrap=mixed'",
345 "DEFAULT='font=sans font_size=30 color=#000 ellipsis=1.0'",
346 "DEFAULT='font=sans font_size=30 color=#000'",
347 };
348
349 char *styles_names[] = {
350 "wrap=<color=#F00>mixed</color> ellipsis=<color=#F00>1.0</color>",
351 "wrap=<color=#F00>mixed</color> ellipsis=<color=#F00>NONE</color>",
352 "wrap=<color=#F00>NONE</color> ellipsis=<color=#F00>1.0</color>",
353 "wrap=<color=#F00>NONE</color> ellipsis=<color=#F00>NONE</color>",
354 };
355
356 typedef struct _APP
357 {
358 Evas_Object *win, *box, *txtblock,*bg, *boxHor, *boxHor2;
359 Eo *btn[BUTTON_ALL];
360 Eo *lbl_status;
361 char * str;
362 unsigned int i_contnet, i_style;
363 } APP;
364 APP *app;
365
366 char * get_fit_status(Eo * textblock);
367
_btn_clicked(void * data EINA_UNUSED,Eo * obj,void * eventInfo EINA_UNUSED)368 static void _btn_clicked(void *data EINA_UNUSED, Eo *obj, void *eventInfo EINA_UNUSED){
369 if (obj == app->btn[BUTTON_MODE])
370 {
371 unsigned int options;
372 evas_textblock_fit_options_get(app->txtblock, &options);
373 if (options == TEXTBLOCK_FIT_MODE_NONE)
374 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_HEIGHT);
375 else if (options == TEXTBLOCK_FIT_MODE_HEIGHT)
376 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_WIDTH);
377 else if (options == TEXTBLOCK_FIT_MODE_WIDTH)
378 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_ALL);
379 else if (options == TEXTBLOCK_FIT_MODE_ALL)
380 evas_textblock_fit_options_set(app->txtblock, TEXTBLOCK_FIT_MODE_NONE);
381 }
382 else if (obj == app->btn[BUTTON_MAX])
383 {
384 unsigned int min, max;
385 evas_textblock_fit_size_range_get(app->txtblock, &min, &max);
386 max -= 5;
387 evas_textblock_fit_size_range_set(app->txtblock, min, max);
388 }
389 else if (obj == app->btn[BUTTON_MIN])
390 {
391 unsigned int min, max;
392 evas_textblock_fit_size_range_get(app->txtblock, &min, &max);
393 min += 5;
394 evas_textblock_fit_size_range_set(app->txtblock, min, max);
395 }
396 else if (obj == app->btn[BUTTON_STEP])
397 {
398 unsigned int step;
399 evas_textblock_fit_step_size_get(app->txtblock, &step);
400 step++;
401 evas_textblock_fit_step_size_set(app->txtblock, step);
402 }
403 else if (obj == app->btn[BUTTON_ARRAY])
404 {
405 unsigned int font_size[] = {10, 50, 100 ,150};
406 evas_textblock_fit_size_array_set(app->txtblock,font_size,4);
407 }
408 else if (obj == app->btn[BUTTON_CONTENT])
409 {
410 app->i_contnet++;
411 if(app->i_contnet>=sizeof(contents)/sizeof(char*))
412 app->i_contnet=0;
413 evas_object_textblock_text_markup_set(app->txtblock,contents[app->i_contnet]);
414 }
415 else if (obj == app->btn[BUTTON_STYLE])
416 {
417 app->i_style++;
418 if(app->i_style>=sizeof(styles)/sizeof(char*))
419 app->i_style=0;
420
421 Evas_Textblock_Style *style = evas_object_textblock_style_get(app->txtblock);
422 evas_textblock_style_set(style,styles[app->i_style]);
423 }
424
425 elm_object_text_set(app->lbl_status, get_fit_status(app->txtblock));
426 }
427
get_fit_status(Eo * textblock)428 char * get_fit_status(Eo * textblock)
429 {
430 static char status[0xFFF];
431 unsigned int options,min,max,step,size_array[256];
432 size_t size_array_len;
433 evas_textblock_fit_options_get(textblock,&options);
434 evas_textblock_fit_size_range_get(textblock,&min,&max);
435 evas_textblock_fit_step_size_get(textblock,&step);
436 evas_textblock_fit_size_array_get(textblock,NULL,&size_array_len,0);
437 if (size_array_len>255)
438 size_array_len = 255;
439 evas_textblock_fit_size_array_get(textblock,size_array,NULL,size_array_len);
440
441 strcpy(status,"Mode : ");
442 if (options == TEXTBLOCK_FIT_MODE_NONE)
443 strcat(status,"MODE_NONE");
444 else if (options == TEXTBLOCK_FIT_MODE_HEIGHT)
445 strcat(status,"MODE_HEIGHT");
446 else if (options == TEXTBLOCK_FIT_MODE_WIDTH)
447 strcat(status,"MODE_WIDTH");
448 else if (options == TEXTBLOCK_FIT_MODE_ALL)
449 strcat(status,"MODE_ALL");
450
451 strcat(status,"<br>");
452 sprintf(status + strlen(status),"Max : %d<br>",max);
453 sprintf(status + strlen(status),"Min : %d<br>",min);
454 sprintf(status + strlen(status),"Step : %d<br>",step);
455 sprintf(status + strlen(status),"Array : [ ");
456 for (size_t i = 0 ; i < 10 ; i++)
457 {
458 if(i<size_array_len)
459 sprintf(status + strlen(status)," %d,",size_array[i]);
460 }
461
462 if(10<size_array_len)
463 sprintf(status + strlen(status)," ... ");
464 sprintf(status + strlen(status)," ]");
465
466 sprintf(status + strlen(status),"<br>");
467 sprintf(status + strlen(status),"%s",styles_names[app->i_style]);
468
469
470
471 return status;
472 }
473
474 void
test_textblock_fit(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)475 test_textblock_fit(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
476 {
477 app = calloc(sizeof(APP), 1);
478
479 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
480
481 app->win = elm_win_util_standard_add("Main", "App");
482 elm_win_autodel_set(app->win, EINA_TRUE);
483
484 app->box = elm_box_add(app->win);
485 app->boxHor = elm_box_add(app->box);
486 app->boxHor2 = elm_box_add(app->box);
487 app->txtblock = evas_object_textblock_add(app->box);
488 app->bg = elm_bg_add(app->box);
489 elm_bg_color_set(app->bg,255,255,255);
490
491 Evas_Textblock_Style *style = evas_textblock_style_new();
492 evas_textblock_style_set(style,styles[0]);
493 evas_object_textblock_style_set(app->txtblock,style);
494 evas_object_textblock_text_markup_set(app->txtblock,contents[0]);
495 evas_textblock_style_free(style);
496 style = NULL;
497
498 elm_box_horizontal_set(app->boxHor, EINA_TRUE);
499 elm_box_horizontal_set(app->boxHor2, EINA_TRUE);
500
501 evas_object_size_hint_weight_set(app->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
502 evas_object_size_hint_align_set(app->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
503
504
505 evas_object_size_hint_weight_set(app->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
506 evas_object_size_hint_align_set(app->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
507
508 evas_object_show(app->txtblock);
509 evas_object_show(app->bg);
510 evas_object_show(app->box);
511 evas_object_show(app->boxHor);
512 evas_object_show(app->boxHor2);
513
514 elm_box_pack_end(app->box, app->bg);
515 elm_box_pack_end(app->box, app->boxHor);
516 elm_box_pack_end(app->box, app->boxHor2);
517
518 elm_object_content_set(app->bg,app->txtblock);
519
520 elm_win_resize_object_add(app->win, app->box);
521 evas_object_resize(app->win, 320, 480);
522
523 for(int i = 0 ; i < BUTTON_ALL ; i++)
524 {
525 app->btn[i] = elm_button_add(app->boxHor);
526 evas_object_smart_callback_add(app->btn[i], "clicked", _btn_clicked, NULL);
527 elm_object_text_set(app->btn[i], BUTTON_STR[i]);
528 elm_box_pack_end(app->boxHor, app->btn[i]);
529 evas_object_show(app->btn[i]);
530 }
531
532 app->lbl_status = elm_label_add(app->boxHor2);
533 elm_object_text_set(app->lbl_status, get_fit_status(app->txtblock));
534 elm_box_pack_end(app->boxHor2, app->lbl_status);
535 evas_object_show(app->lbl_status);
536
537 evas_object_size_hint_weight_set(app->txtblock, EVAS_HINT_EXPAND,EVAS_HINT_EXPAND);
538 evas_object_size_hint_align_set(app->txtblock, EVAS_HINT_FILL, EVAS_HINT_FILL);
539
540 evas_object_size_hint_weight_set(app->bg, EVAS_HINT_EXPAND,EVAS_HINT_EXPAND);
541 evas_object_size_hint_align_set(app->bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
542
543 evas_object_show(app->win);
544 }
545
546 /*** Text Memory Configuration **************************************************************/
547 enum BUTTON_MEM{
548 BUTTON_MEM_SET_TEXT = 0,
549 BUTTON_MEM_APPLY_MEM = 1,
550 BUTTON_MEM_APPLY_FONT_SIZE = 2,
551 BUTTON_MEM_ALL = BUTTON_MEM_APPLY_FONT_SIZE+1,
552 };
553
554 char* BUTTON_MEM_STR[BUTTON_MEM_ALL] ={
555 "Load Emojis Text",
556 "Memory Limit(MB)",
557 "Font Size"
558 };
559
560 char *content = "<align=center>☺☹☻☠⚕️⚕️⚖⚖✈️✈️♂️♀️️♂️️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️☝️✌✋✊✍❤❣⛑⚘☘☕✨⚽️⚾️⛳️♂️️♀️⛸⛷♂️♀️♂️♀️⛹️♂️⛹️♀️️♂️️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♂️♀️♠️♥️♦️♣️⛰⛪⛩⛲⛺⛼♨️⛟⛽⚓⛵♂️♀️⛴✈⌛⏳⌚⏰⏱⏲☀️⭐☁️⛅⛈☂️☔⛱⚡❄☃️⛄☄☎️⌨✉✏✒✂️⛏⚒⚔⚙⚗⚖⛓⚰⚱♿⚠️⛔☢☣⬆️↗️➡️↘️⬇️↙️⬅️↖️↕️↔️↩↪⤴️⤵️⚛✡☸☯️☦☮♈♉♊♋♌♍♎♏♐♑♒♓⛎▶️⏩⏭⏯◀️⏪⏮⏫⏬⏸⏹⏺⏏♻️⚜⭕✅☑✔✖❌❎➕♀️♂️⚕➖➗➰➿〽✳✴❇⁉️❓❔❕❗〰️️️️️️ℹ️Ⓜ️️️️️️️️️㊗㊙▫️◻◼◽◾⬛⬜️️️️️⚪⚫️⚀⚁⚂⚃⚄⚅⛾♾</align>";
561
562 typedef struct _APP_MEM
563 {
564 Evas_Object *win, *box, *main_entry;
565 Eo *btn[BUTTON_MEM_ALL];
566 Eo *entry[BUTTON_MEM_ALL];
567 } APP_MEM;
568 APP_MEM *app_mem;
569
_btn_clicked_mem(void * data EINA_UNUSED,Eo * obj,void * eventInfo EINA_UNUSED)570 static void _btn_clicked_mem(void *data EINA_UNUSED, Eo *obj, void *eventInfo EINA_UNUSED){
571 if (obj == app_mem->btn[BUTTON_MEM_SET_TEXT])
572 {
573 elm_object_text_set(app_mem->main_entry, content);
574 }
575 else if (obj == app_mem->btn[BUTTON_MEM_APPLY_MEM])
576 {
577 int size = atoi(elm_object_text_get(app_mem->entry[BUTTON_MEM_APPLY_MEM]));
578 if (size > 0 && size < 4000)
579 {
580 evas_font_data_cache_set(EVAS_FONT_DATA_CACHE_TEXTURE, size * 1024 * 1024);
581 }
582 else
583 {
584 elm_object_text_set(app_mem->entry[BUTTON_MEM_APPLY_MEM], "NAN");
585 }
586 }
587 else if (obj == app_mem->btn[BUTTON_MEM_APPLY_FONT_SIZE])
588 {
589 int font_size = atoi(elm_object_text_get(app_mem->entry[BUTTON_MEM_APPLY_FONT_SIZE]));
590 if (font_size > 0 && font_size < 1000)
591 {
592 char sfont_size[256] = {0};
593 sprintf(sfont_size,"DEFAULT='font_size=%i'", font_size);
594 elm_entry_text_style_user_push(app_mem->main_entry, sfont_size);
595 }
596 else
597 {
598 elm_object_text_set(app_mem->entry[BUTTON_MEM_APPLY_FONT_SIZE], "NAN");
599 }
600 }
601 }
602
603 void
test_text_memory(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)604 test_text_memory(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
605 {
606 app_mem = calloc(sizeof(APP_MEM), 1);
607
608 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
609
610 app_mem->win = elm_win_util_standard_add("Main", "App");
611 elm_win_autodel_set(app_mem->win, EINA_TRUE);
612
613 app_mem->box = elm_box_add(app_mem->win);
614 app_mem->main_entry = elm_entry_add(app_mem->box);
615
616 evas_object_size_hint_weight_set(app_mem->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
617 evas_object_size_hint_align_set(app_mem->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
618
619 app_mem->btn[BUTTON_MEM_SET_TEXT] = elm_button_add(app_mem->box);
620 evas_object_smart_callback_add(app_mem->btn[BUTTON_MEM_SET_TEXT], "clicked", _btn_clicked_mem, NULL);
621 elm_object_text_set(app_mem->btn[BUTTON_MEM_SET_TEXT], BUTTON_MEM_STR[BUTTON_MEM_SET_TEXT]);
622 evas_object_size_hint_align_set(app_mem->btn[BUTTON_MEM_SET_TEXT], EVAS_HINT_FILL, EVAS_HINT_FILL);
623 elm_box_pack_end(app_mem->box, app_mem->btn[BUTTON_MEM_SET_TEXT]);
624 evas_object_show(app_mem->btn[BUTTON_MEM_SET_TEXT]);
625
626 elm_entry_scrollable_set(app_mem->main_entry, EINA_TRUE);
627 evas_object_show(app_mem->main_entry);
628 evas_object_show(app_mem->box);
629
630 elm_box_pack_end(app_mem->box, app_mem->main_entry);
631 evas_object_smart_callback_add(app_mem->btn[BUTTON_MEM_SET_TEXT], "clicked", _btn_clicked_mem, NULL);
632 evas_object_show(app_mem->btn[BUTTON_MEM_SET_TEXT]);
633
634 elm_win_resize_object_add(app_mem->win, app_mem->box);
635 evas_object_resize(app_mem->win, 320, 320);
636
637 elm_entry_text_style_user_push(app_mem->main_entry, "DEFAULT='font_size=20'");
638
639 for(int i = BUTTON_MEM_APPLY_MEM ; i < BUTTON_MEM_ALL ; i++)
640 {
641 app_mem->btn[i] = elm_button_add(app_mem->box);
642 app_mem->entry[i] = elm_entry_add(app_mem->box);
643 evas_object_smart_callback_add(app_mem->btn[i], "clicked", _btn_clicked_mem, NULL);
644 elm_object_text_set(app_mem->btn[i], BUTTON_MEM_STR[i]);
645 elm_box_pack_end(app_mem->box, app_mem->btn[i]);
646 elm_box_pack_end(app_mem->box, app_mem->entry[i]);
647
648 evas_object_size_hint_align_set(app_mem->btn[i], EVAS_HINT_FILL, EVAS_HINT_FILL);
649 evas_object_size_hint_align_set(app_mem->entry[i], EVAS_HINT_FILL, EVAS_HINT_FILL);
650
651 evas_object_show(app_mem->btn[i]);
652 evas_object_show(app_mem->entry[i]);
653 }
654
655 elm_object_text_set(app_mem->entry[BUTTON_MEM_APPLY_MEM],"Texture limit in MB");
656 elm_object_text_set(app_mem->entry[BUTTON_MEM_APPLY_FONT_SIZE],"20");
657
658 evas_object_size_hint_weight_set(app_mem->main_entry, EVAS_HINT_EXPAND,EVAS_HINT_EXPAND);
659 evas_object_size_hint_align_set(app_mem->main_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
660
661 evas_object_show(app_mem->win);
662 }
663
664 /*** Label Wrap **************************************************************/
665 void
test_label_wrap(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)666 test_label_wrap(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
667 {
668 Evas_Object *win, *lb;
669
670 win = elm_win_util_standard_add("label-wrap", "Label Wrap");
671 elm_win_autodel_set(win, EINA_TRUE);
672
673 lb = elm_label_add(win);
674 elm_object_text_set(lb,
675 "This is text for our label, that is long but "
676 "not too long. The label is designed to have line-wrap."
677 );
678 elm_label_line_wrap_set(lb, ELM_WRAP_CHAR);
679 elm_label_wrap_width_set(lb, ELM_SCALE_SIZE(200));
680 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
681 elm_win_resize_object_add(win, lb);
682 evas_object_show(lb);
683
684 evas_object_show(win);
685 }
686
687
688 /*** Label Ellipsis **********************************************************/
689 void
test_label_ellipsis(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)690 test_label_ellipsis(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
691 {
692 Evas_Object *win, *bx, *lb;
693
694 win = elm_win_util_standard_add("label-ellipsis", "Label Ellipsis");
695 elm_win_autodel_set(win, EINA_TRUE);
696
697 bx = elm_box_add(win);
698 elm_box_padding_set(bx, 0, ELM_SCALE_SIZE(10));
699 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
700 elm_win_resize_object_add(win, bx);
701 evas_object_show(bx);
702
703 lb = elm_label_add(win);
704 elm_object_text_set(lb,
705 "This is a label set to ellipsis. "
706 "If set ellipsis to true and the text doesn't fit "
707 "in the label an ellipsis(\"...\") will be shown "
708 "at the end of the widget."
709 );
710 elm_label_ellipsis_set(lb, EINA_TRUE);
711 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
712 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, 0.0);
713 elm_box_pack_end(bx, lb);
714 evas_object_show(lb);
715
716 lb = elm_label_add(win);
717 elm_object_text_set(lb,
718 "<big>"
719 "This label also have <b>markups</b>, "
720 "<hilight>hilight</hilight>, "
721 "<success>success</success>, "
722 "<failure>failure</failure>."
723 "</big>"
724 );
725 elm_label_ellipsis_set(lb, EINA_TRUE);
726 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
727 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, 0.0);
728 elm_box_pack_end(bx, lb);
729 evas_object_show(lb);
730
731 evas_object_resize(win, 300, 100);
732 evas_object_show(win);
733 }
734
735 /*** Label colors **************************************************************/
736 void
test_label_colors(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)737 test_label_colors(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
738 {
739 Evas_Object *win, *lb;
740
741 win = elm_win_util_standard_add("label-colors", "Label colors");
742 elm_win_autodel_set(win, EINA_TRUE);
743
744 lb = elm_label_add(win);
745 elm_object_text_set(lb,
746 "<color=red>this is red color line(color = red)<color><br>"
747 "<color=#0000FF>this is blue color line (color = #0000FF)<color><br>"
748 "<color=rgb(0,255,0)>this is green color line (color = rgb(0,255,0))<color><br>"
749 "<color=rgba(0,255,0,255)>this is blue color line (color = rgba(0,255,0,255))<color><br>"
750 );
751 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
752 elm_win_resize_object_add(win, lb);
753 evas_object_show(lb);
754
755 evas_object_show(win);
756 }
757
758 /*** Label variation sequence **************************************************************/
759 void
test_label_variation_sequence(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)760 test_label_variation_sequence(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
761 {
762 Evas_Object *win, *lb;
763
764 win = elm_win_util_standard_add("label-variation sequence", "Label variation sequnece");
765 elm_win_autodel_set(win, EINA_TRUE);
766
767 lb = elm_label_add(win);
768 elm_object_text_set(lb,
769 "You need to have at least on font contains variation sequence<br>"
770 "Three different 8 glyphs : <br>"
771 "8<tab>8️<tab>8️⃣<br>"
772 "line with 3 variation glyphs : <br>"
773 "8️⃣☪️AAA☪︎1234567️⃣"
774 );
775 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
776 elm_win_resize_object_add(win, lb);
777 evas_object_show(lb);
778
779 evas_object_show(win);
780 }
781
782 /*** Label Emoji *************************************************************/
783 static char *
_fontlist_text_get(void * data,Evas_Object * obj EINA_UNUSED,const char * part EINA_UNUSED)784 _fontlist_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
785 {
786 return strdup(data);
787 }
788
789 static void
_font_set(Evas_Object * label,const char * font)790 _font_set(Evas_Object *label, const char *font)
791 {
792 // Note: u1F420 doesn't work but U0001F420 does.
793 const char *emojis = u8""
794 "<font='%s',Sans font_size=16 align=left>"
795 "Grinning Face: \U0001f600<br/>"
796 "Face with Tears of Joy: \xf0\x9f\x98\x82<br/>"
797 "Panda Face: \xf0\x9f\x90\xbc<br/>"
798 "Ghost: \xf0\x9f\x91\xbb<br/>"
799 "Tropical Fish: \U0001F420<br/>"
800 "Mosque: \U0001f54c<br/>"
801 "Pencil: \u270f<br/>"
802 "Person With Ball: \u26f9<br/>"
803 "Birthday Cake: \U0001F382<br/>"
804 "Dog Face: \U0001F436<br/>"
805 "Music: \U0001F3B5 \U0001F3B6 \U0001F3BC<br/>"
806 "Person Shrugging: \U0001F937<br/>"
807 "</>";
808
809 elm_object_text_set(label, eina_slstr_printf(emojis, font));
810 }
811
812 static void
_font_item_sel_cb(void * data,Evas_Object * obj,void * event_info)813 _font_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
814 {
815 Elm_Object_Item *item = event_info;
816 Evas_Object *lb = data;
817 const char *font;
818
819 font = elm_object_item_text_get(item);
820 elm_object_text_set(obj, font);
821 elm_combobox_hover_end(obj);
822 _font_set(lb, font);
823 }
824
825 static void
_font_item_del_cb(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)826 _font_item_del_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
827 {
828 free(data);
829 }
830
831 void
test_label_emoji(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)832 test_label_emoji(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
833 {
834 Evas_Object *win, *bx, *txt, *cmb;
835 Elm_Genlist_Item_Class *itc;
836 Eina_List *list, *l;
837 const char *font;
838 Evas *evas;
839
840 const char *font_patterns[] = { "emoji", "symbola" };
841
842 win = elm_win_util_standard_add("label-emoji", "Label Emoji");
843 elm_win_autodel_set(win, EINA_TRUE);
844
845 bx = elm_box_add(win);
846 elm_box_padding_set(bx, 0, ELM_SCALE_SIZE(10));
847 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
848 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
849 elm_win_resize_object_add(win, bx);
850 evas_object_show(bx);
851
852 txt = elm_entry_add(win);
853 elm_entry_editable_set(txt, EINA_TRUE);
854 elm_entry_scrollable_set(txt, EINA_TRUE);
855 evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
856 evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
857 elm_box_pack_end(bx, txt);
858 evas_object_show(txt);
859
860 cmb = elm_combobox_add(win);
861 elm_entry_editable_set(cmb, EINA_FALSE);
862 evas_object_size_hint_weight_set(cmb, EVAS_HINT_EXPAND, 0.0);
863 evas_object_size_hint_align_set(cmb, EVAS_HINT_FILL, EVAS_HINT_FILL);
864 elm_box_pack_end(bx, cmb);
865
866 itc = elm_genlist_item_class_new();
867 itc->item_style = "default";
868 itc->func.text_get = _fontlist_text_get;
869
870 evas = evas_object_evas_get(win);
871 list = evas_font_available_list(evas);
872 EINA_LIST_FOREACH(list, l, font)
873 {
874 size_t k;
875
876 if (!font) continue;
877 for (k = 0; k < EINA_C_ARRAY_LENGTH(font_patterns); k++)
878 {
879 if (strcasestr(font, font_patterns[k]))
880 {
881 Elm_Object_Item *it;
882
883 it = elm_genlist_item_append(cmb, itc, strdup(font), NULL,
884 ELM_GENLIST_ITEM_NONE,
885 NULL, NULL);
886 elm_object_item_del_cb_set(it, _font_item_del_cb);
887 }
888 }
889 }
890 evas_font_available_list_free(evas, list);
891
892 evas_object_smart_callback_add(cmb, "item,pressed", _font_item_sel_cb, txt);
893
894 elm_genlist_item_class_free(itc);
895
896 elm_object_text_set(cmb, "Sans");
897 _font_set(txt, "Sans");
898 evas_object_show(cmb);
899
900 evas_object_resize(win, 300, 400);
901 evas_object_show(win);
902 }
903