PageRenderTime 826ms CodeModel.GetById 633ms app.highlight 5ms RepoModel.GetById 186ms app.codeStats 0ms

/src/demos/demo_statusbar.c

http://ftk.googlecode.com/
C | 66 lines | 48 code | 17 blank | 1 comment | 0 complexity | a4a48563dbe7293bcc1723ab2f580340 MD5 | raw file
 1#include "ftk.h"
 2#include <time.h>
 3
 4#define IDC_TIME_ITEM 2000
 5
 6static Ret update_time(void* ctx)
 7{
 8	char text[10] = {0};
 9	FtkWidget* item = NULL;
10	FtkWidget* panel = NULL;
11
12	time_t now = time(0);
13	struct tm* t = localtime(&now);
14	panel = ftk_default_status_panel();
15
16	ftk_snprintf(text, sizeof(text)-1, "%2d:%2d", t->tm_hour, t->tm_min);
17
18	item = ftk_widget_lookup(panel, IDC_TIME_ITEM);
19
20	ftk_widget_set_text(item, text);
21
22	ftk_logd("%s: %s\n", __func__, text);
23
24	return RET_OK;
25}
26
27#ifdef FTK_AS_PLUGIN
28#include "ftk_app_demo.h"
29FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
30FtkApp* ftk_app_demo_statusbar_create()
31{
32	return ftk_app_demo_create(_("status_bar"), ftk_main);
33}
34#else
35#define FTK_HIDE extern
36#endif /*FTK_AS_PLUGIN*/
37
38FTK_HIDE int FTK_MAIN(int argc, char* argv[])
39{
40	FtkSource* timer = NULL;
41	FtkWidget* win = NULL;
42	FtkWidget* item = NULL;
43	FtkWidget* panel = NULL;
44	FTK_INIT(argc, argv);
45
46	/*create a time widget in statusbar.*/
47	panel = ftk_default_status_panel();
48	item = ftk_status_item_create(panel, -2, 60);
49	ftk_widget_set_id(item, IDC_TIME_ITEM);
50
51	ftk_widget_show(item, 1);
52
53	win = ftk_app_window_create();
54	ftk_widget_set_text(win, "Hello FTK!");
55
56	ftk_widget_show(win, 1);
57	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
58
59	update_time(NULL);
60	timer = ftk_source_timer_create(60000, update_time, NULL);
61	ftk_main_loop_add_source(ftk_default_main_loop(), timer);
62
63	FTK_RUN();
64
65	return 0;
66}