PageRenderTime 445ms CodeModel.GetById 241ms app.highlight 8ms RepoModel.GetById 193ms app.codeStats 0ms

/src/demos/demo_label.c

http://ftk.googlecode.com/
C | 102 lines | 84 code | 18 blank | 0 comment | 2 complexity | ad1b58696daab104720391c71302c245 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		ftk_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
 31#ifdef FTK_AS_PLUGIN
 32#include "ftk_app_demo.h"
 33FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
 34FtkApp* ftk_app_demo_label_create()
 35{
 36	return ftk_app_demo_create(_("label"), ftk_main);
 37}
 38#else
 39#define FTK_HIDE extern
 40#endif /*FTK_AS_PLUGIN*/
 41
 42FTK_HIDE int FTK_MAIN(int argc, char* argv[])
 43{
 44	int width = 0;
 45	int height = 0;
 46	FtkGc gc = {0};
 47	TimerInfo* info = NULL;
 48	FtkSource* timer = NULL;
 49	FtkWidget* win = NULL;
 50	FtkWidget* label = NULL;
 51
 52	gc.mask = FTK_GC_BG;
 53
 54	FTK_INIT(argc, argv);
 55	info = (TimerInfo*)FTK_ZALLOC(sizeof(TimerInfo));
 56	info->times = 5;
 57		
 58	timer = ftk_source_timer_create(1000, timeout, info);
 59	win = ftk_app_window_create();
 60	ftk_window_set_animation_hint(win, "app_main_window");
 61
 62	width = ftk_widget_width(win);
 63	height = ftk_widget_height(win);
 64
 65	label = ftk_label_create(win, 10, 10, width - 20, 22);
 66	ftk_widget_set_text(label, "Left Text");
 67	
 68	label = ftk_label_create(win, 10, 40, width - 20, 22);
 69	ftk_widget_set_text(label, "English Text(center)");
 70	ftk_label_set_alignment(label, FTK_ALIGN_CENTER);
 71	assert(strcmp(ftk_widget_get_text(label), "English Text(center)") == 0);
 72	
 73	label = ftk_label_create(win, 10, 70, width - 20, 22);
 74	ftk_widget_set_text(label, "English Text(right)");
 75	ftk_label_set_alignment(label, FTK_ALIGN_RIGHT);
 76
 77	gc.bg.a = 0xff;
 78	gc.bg.r = 0xF0;
 79	gc.bg.g = 0xF0;
 80	gc.bg.b = 0x80;
 81	label = ftk_label_create(win, 10, height/2, width - 20, 120);
 82	ftk_widget_set_gc(label, FTK_WIDGET_INSENSITIVE, &gc);
 83	ftk_widget_unset_attr(label, FTK_ATTR_TRANSPARENT);
 84#ifdef WIN32	
 85	ftk_widget_set_text(label, "The linux mobile development(with background color)");
 86#else
 87	ftk_widget_set_text(label, "???????????:the linux mobile development.???????");
 88#endif
 89	label = ftk_label_create(win, 50, height/2-30, width, 22);
 90	info->label = label;
 91	
 92	ftk_widget_set_text(win, "label demo");
 93	ftk_widget_show_all(win, 1);
 94
 95	ftk_widget_set_attr(win, FTK_ATTR_IGNORE_CLOSE);
 96	ftk_main_loop_add_source(ftk_default_main_loop(), timer);
 97
 98	FTK_RUN();
 99
100	return 0;
101}
102