PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/src/demos/demo_bidi.c

http://ftk.googlecode.com/
C | 78 lines | 62 code | 16 blank | 0 comment | 2 complexity | 23ec5045c3207b518002ad1b9d75a5af MD5 | raw file
 1#include "ftk.h"
 2
 3typedef struct _TimerInfo
 4{
 5	int times;
 6	FtkWidget* label;
 7}TimerInfo;
 8
 9static Ret timeout(void* ctx)
10{
11	TimerInfo* info = ctx;
12	char buffer[32] = {0};
13	if(info->times > 0)
14	{
15		snprintf(buffer, sizeof(buffer), "Quit after %d seconds", info->times);
16		ftk_widget_set_text(info->label, buffer);
17		info->times--;
18
19		return RET_OK;
20	}
21	else
22	{
23		ftk_widget_unref(ftk_widget_toplevel(info->label));
24		ftk_logd("%s: timeout and quit.\n", __func__);
25		FTK_FREE(info);
26		FTK_QUIT();
27		return RET_REMOVE;
28	}
29}
30
31FTK_HIDE int FTK_MAIN(int argc, char* argv[])
32{
33	int width = 0;
34	int height = 0;
35	FtkGc gc = {.mask = FTK_GC_BG};
36	TimerInfo* info = NULL;
37
38	FTK_INIT(argc, argv);
39	info = (TimerInfo*)FTK_ZALLOC(sizeof(TimerInfo));
40	info->times = 100;
41		
42	FtkSource* timer = ftk_source_timer_create(1000, timeout, info);
43	FtkWidget* win = ftk_app_window_create();
44	ftk_window_set_animation_hint(win, "app_main_window");
45
46	width = ftk_widget_width(win);
47	height = ftk_widget_height(win);
48
49	FtkWidget* label = ftk_label_create(win, 10, 10, width - 20, 20);
50	ftk_widget_set_text(label, "arabic bidi demo");
51	
52	label = ftk_label_create(win, 10, 40, width - 20, 20);
53	ftk_widget_set_text(label, "English Text");
54	assert(strcmp(ftk_widget_get_text(label), "English Text") == 0);
55	
56	gc.bg.a = 0xff;
57	gc.bg.r = 0xF0;
58	gc.bg.g = 0xF0;
59	gc.bg.b = 0x80;
60	label = ftk_label_create(win, 10, height/2, width - 20, 120);
61	ftk_widget_set_gc(label, FTK_WIDGET_INSENSITIVE, &gc);
62	ftk_widget_unset_attr(label, FTK_ATTR_TRANSPARENT);
63	ftk_widget_set_text(label, "?? ??? ????? ?????? ??? ???? ????? ????? ?????? ??? ?? ???? ??????");
64	
65	label = ftk_label_create(win, 50, height/2-30, width, 20);
66	info->label = label;
67	
68	ftk_widget_set_text(win, "label demo");
69	ftk_widget_show_all(win, 1);
70
71	ftk_widget_set_attr(win, FTK_ATTR_IGNORE_CLOSE);
72	ftk_main_loop_add_source(ftk_default_main_loop(), timer);
73
74	FTK_RUN();
75
76	return 0;
77}
78