PageRenderTime 369ms CodeModel.GetById 181ms app.highlight 72ms RepoModel.GetById 110ms app.codeStats 0ms

/src/demos/demo_button.c

http://ftk.googlecode.com/
C | 91 lines | 70 code | 21 blank | 0 comment | 0 complexity | fe2d2ea20f5465c08b0d1d0a56dde917 MD5 | raw file
 1#include "ftk.h"
 2
 3#define IDC_TEST_BUTTON 1000
 4static Ret button_quit_clicked(void* ctx, void* obj)
 5{
 6	ftk_widget_unref(ctx);
 7
 8	return RET_OK;
 9}
10
11static Ret button_hide_clicked(void* ctx, void* obj)
12{
13	ftk_widget_show(ftk_widget_lookup(ctx, IDC_TEST_BUTTON), 0);
14
15	return RET_OK;
16}
17
18static Ret button_show_clicked(void* ctx, void* obj)
19{
20	ftk_widget_show(ftk_widget_lookup(ctx, IDC_TEST_BUTTON), 1);
21
22	return RET_OK;
23}
24
25static Ret button_default_clicked(void* ctx, void* obj)
26{
27	printf("%s: button %s is clicked.\n", __func__, ftk_widget_get_text(obj));
28
29	return RET_OK;
30}
31
32#ifdef FTK_AS_PLUGIN
33#include "ftk_app_demo.h"
34FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
35FtkApp* ftk_app_demo_button_create()
36{
37	return ftk_app_demo_create(_("button"), ftk_main);
38}
39#else
40#define FTK_HIDE extern
41#endif /*FTK_AS_PLUGIN*/
42
43FTK_HIDE int FTK_MAIN(int argc, char* argv[])
44{
45	int width = 0;
46	int height = 0;
47	FtkWidget* win = NULL;
48	FtkWidget* button = NULL;
49
50	FTK_INIT(argc, argv);
51	
52	win = ftk_app_window_create();
53	ftk_window_set_animation_hint(win, "app_main_window");
54	width = ftk_widget_width(win);
55	height = ftk_widget_height(win);
56	
57	width = width/3 - 10;
58	button = ftk_button_create(win, 0, 30, width, 50);
59	ftk_widget_set_text(button, "show");
60	ftk_button_set_clicked_listener(button, button_show_clicked, win);
61
62	button = ftk_button_create(win, width + 10, 30, width, 50);
63	ftk_widget_set_text(button, "hide");
64	ftk_button_set_clicked_listener(button, button_hide_clicked, win);
65	
66	button = ftk_button_create(win, 2*(width + 10), 30, width, 50);
67	ftk_widget_set_text(button, "????(BUTTON)");
68	ftk_widget_set_id(button, IDC_TEST_BUTTON);
69	ftk_button_set_clicked_listener(button, button_default_clicked, win);
70	
71	button = ftk_button_create(win, 0, 130, width, 40);
72	ftk_widget_set_text(button, "yes");
73	ftk_button_set_clicked_listener(button, button_default_clicked, win);
74	
75	button = ftk_button_create(win, 2*(width + 10), 130, width, 40);
76	ftk_widget_set_text(button, "no");
77	ftk_button_set_clicked_listener(button, button_default_clicked, win);
78	
79	button = ftk_button_create(win, width + 10, height/2, width, 60);
80	ftk_widget_set_text(button, "quit");
81	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
82	ftk_window_set_focus(win, button);
83
84	ftk_widget_set_text(win, "button demo");
85	ftk_widget_show_all(win, 1);
86	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
87	FTK_RUN();
88
89	return 0;
90}
91