application/main.c

changeset 114
909fe96e5659
parent 113
500c085d2133
child 115
102fc0b8fe3e
equal deleted inserted replaced
113:500c085d2133 114:909fe96e5659
52 52
53 void action_button2(UiEvent *event, void *data) { 53 void action_button2(UiEvent *event, void *data) {
54 ui_setval(radio, 1); 54 ui_setval(radio, 1);
55 } 55 }
56 56
57 UiTextLayout *text;
58
57 void draw(UiEvent *event, UiGraphics *g, void *data) { 59 void draw(UiEvent *event, UiGraphics *g, void *data) {
58 /* 60 ///*
59 int width = g->width; 61 int width = g->width;
60 int height = g->height; 62 int height = g->height;
61 printf("rec[%d,%d]\n", width, height); 63 //printf("rec[%d,%d]\n", width, height);
62 64
63 ui_graphics_color(g, 64, 64, 64); 65 ui_graphics_color(g, 64, 64, 64);
64 ui_draw_rect(g, 0, 0, width, height, TRUE); 66 ui_draw_rect(g, 0, 0, width, height, TRUE);
65 67
66 UiTextLayout *text = ui_text(g); 68 if(!text) {
67 ui_text_setfont(text, "Monospace", 12); 69 text = ui_text(g);
68 ui_text_setstring(text, "Hello World"); 70 ui_text_setfont(text, "Monospace", 12);
71 ui_text_setstring(text, "Hello World");
72 }
69 int w, h; 73 int w, h;
70 ui_text_getsize(text, &w, &h); 74 ui_text_getsize(text, &w, &h);
71 //printf("ext[%d,%d]\n", w, h); 75 //printf("ext[%d,%d]\n", w, h);
72 76
73 ui_graphics_color(g, 255, 255, 255); 77 ui_graphics_color(g, 255, 255, 255);
74 ui_draw_text(g, 50, 50, text); 78 ui_draw_text(g, 50, 50, text);
75 79
76 ui_text_free(text); 80 ui_draw_line(g, 0, 120, width, 120);
77 */ 81 ui_draw_line(g, 200, 0, 200, height);
82
83 //ui_text_free(text);
84 //*/
78 } 85 }
79 86
80 void click(UiEvent *event, void *data) { 87 void click(UiEvent *event, void *data) {
81 UiMouseEvent *me = event->eventdata; 88 UiMouseEvent *me = event->eventdata;
82 printf("click[%d](%d,%d)\n", me->type, me->x, me->y); 89 printf("click[%d](%d,%d)\n", me->type, me->x, me->y);
102 ui_toolitem("button1", "Test", action_button, NULL); 109 ui_toolitem("button1", "Test", action_button, NULL);
103 ui_toolitem("button2", "OK", action_button, NULL); 110 ui_toolitem("button2", "OK", action_button, NULL);
104 ui_toolbar_add_default("button1"); 111 ui_toolbar_add_default("button1");
105 ui_toolbar_add_default("button2"); 112 ui_toolbar_add_default("button2");
106 113
107 UiObject *obj = ui_simplewindow("Test", NULL); 114 UiObject *obj = ui_window("Test", NULL);
108 ui_context_closefunc(obj->ctx, window_close, NULL); 115 ui_context_closefunc(obj->ctx, window_close, NULL);
109 //UIWIDGET w = ui_drawingarea(obj, draw, NULL); 116 UIWIDGET w = ui_drawingarea(obj, draw, NULL);
110 //ui_mouse_handler(obj, w, click, NULL); 117 //ui_mouse_handler(obj, w, click, NULL);
111 118
112 ///* 119 /*
113 ui_vbox_sp(obj, 8, 4); 120 ui_vbox_sp(obj, 8, 4);
114 ui_button(obj, "Button", NULL, NULL); 121 ui_button(obj, "Button", NULL, NULL);
115 ui_button(obj, "Button", NULL, NULL); 122 ui_button(obj, "Button", NULL, NULL);
116 ui_button(obj, "Button", NULL, NULL); 123 ui_button(obj, "Button", NULL, NULL);
117 ui_button(obj, "Button", NULL, NULL); 124 ui_button(obj, "Button", NULL, NULL);

mercurial