31 |
31 |
32 #include <ui/ui.h> |
32 #include <ui/ui.h> |
33 #include <ucx/buffer.h> |
33 #include <ucx/buffer.h> |
34 #include <ucx/utils.h> |
34 #include <ucx/utils.h> |
35 |
35 |
|
36 typedef struct Document { |
|
37 UiText *text; |
|
38 UiString *t1; |
|
39 UiString *t2; |
|
40 UiString *t3; |
|
41 UiInteger *i; |
|
42 } Document; |
|
43 |
|
44 Document *d1; |
|
45 Document *d2; |
|
46 int n = 1; |
|
47 |
|
48 Document* create_doc(); |
|
49 |
|
50 Document* next_doc(void) { |
|
51 Document *doc = d1; |
|
52 if(n == 1) { |
|
53 doc = d2; |
|
54 printf("doc2\n"); |
|
55 } else { |
|
56 printf("doc1\n"); |
|
57 } |
|
58 n++; |
|
59 n = n%2; |
|
60 return doc; |
|
61 } |
|
62 |
36 void action_menu(UiEvent *event, void *data) { |
63 void action_menu(UiEvent *event, void *data) { |
37 printf("action_menu\n"); |
64 printf("action_menu\n"); |
|
65 |
|
66 Document *doc = event->document; |
|
67 char *s = doc->text->get(doc->text); |
|
68 printf("text: {\n%s\n}\n", s); |
|
69 //int i = doc->i->get(doc->i); |
|
70 //printf("i: %d\n", i); |
|
71 |
38 fflush(stdout); |
72 fflush(stdout); |
39 } |
73 } |
40 |
74 |
41 void action_button(UiEvent *event, void *data) { |
75 Document* create_doc() { |
42 printf("action_button\n"); |
76 Document *doc = ui_document_new(sizeof(Document)); |
43 fflush(stdout); |
77 UiContext *ctx = ui_document_context(doc); |
|
78 |
|
79 doc->text = ui_text_new(ctx, "text"); |
|
80 //doc->t1 = ui_string_new(ctx, "t1"); |
|
81 //doc->t2 = ui_string_new(ctx, "t2"); |
|
82 //doc->t3 = ui_string_new(ctx, "t3"); |
|
83 |
|
84 //doc->i = ui_int_new(ctx, "int"); |
|
85 return doc; |
44 } |
86 } |
45 |
87 |
46 void draw(UiEvent *event, UiGraphics *g, void *data) { |
88 void action_newdoc(UiEvent *event, void *data) { |
47 printf("draw: %d, %d\n", g->width, g->height); |
89 printf("new doc\n"); |
48 fflush(stdout); |
|
49 |
90 |
50 ui_graphics_color(g, 200, 240, 240); |
91 Document *newd = next_doc(); |
51 ui_draw_rect(g, 0, 0, 50, g->height, TRUE); |
92 printf("newd: %d\n", (int)(intptr_t)newd); |
52 |
93 ui_set_document(event->obj, newd); |
53 ui_graphics_color(g, 150, 150, 200); |
|
54 ui_draw_rect(g, 50, 0, g->width - 50, g->height, TRUE); |
|
55 |
|
56 ui_graphics_color(g, 0, 0, 0); |
|
57 ui_draw_line(g, 0, 10, 100, 10); |
|
58 ui_draw_line(g, 0, 10, 10, 50); |
|
59 ui_draw_line(g, 10, 50, 50, 50); |
|
60 ui_draw_line(g, 50, 50, 100, 100); |
|
61 |
|
62 ui_draw_rect(g, 15, 15, 80, 80, FALSE); |
|
63 } |
94 } |
64 |
95 |
65 void application_startup(UiEvent *event, void *data) { |
96 void application_startup(UiEvent *event, void *data) { |
|
97 //Document *doc = create_doc(); |
|
98 d1 = create_doc(); |
|
99 d2 = create_doc(); |
|
100 |
66 UiObject *obj = ui_window("Test", NULL); |
101 UiObject *obj = ui_window("Test", NULL); |
|
102 ui_set_document(obj, d1); |
67 |
103 |
68 ui_tabview(obj); |
104 ui_textarea_nv(obj, "text"); |
69 |
105 |
70 ui_tab(obj, "Tab 1"); |
|
71 ui_textarea(obj, NULL); |
|
72 ui_end(obj); |
|
73 |
106 |
74 ui_tab(obj, "Tab 2"); |
|
75 ui_textarea(obj, NULL); |
|
76 ui_end(obj); |
|
77 |
107 |
78 ui_end(obj); |
108 ui_button(obj, "Switch Document", action_newdoc, NULL); |
79 |
109 |
80 ui_show(obj); |
110 ui_show(obj); |
81 } |
111 } |
82 |
112 |
83 int main(int argc, char** argv) { |
113 int main(int argc, char** argv) { |
92 ui_menuitem("item2", action_menu, NULL); |
122 ui_menuitem("item2", action_menu, NULL); |
93 ui_submenu_end(); |
123 ui_submenu_end(); |
94 ui_menuitem("item3", action_menu, NULL); |
124 ui_menuitem("item3", action_menu, NULL); |
95 ui_submenu_end(); |
125 ui_submenu_end(); |
96 ui_menuitem("item4", action_menu, NULL); |
126 ui_menuitem("item4", action_menu, NULL); |
97 |
127 |
98 // toolbar |
|
99 ui_toolitem("button1", "Test1", action_button, NULL); |
|
100 ui_toolitem("button2", "Test2", action_button, NULL); |
|
101 ui_toolitem("button3", "Test3", action_button, NULL); |
|
102 ui_toolitem("button4", "Test4", action_button, NULL); |
|
103 ui_toolitem("button5", "Test5", action_button, NULL); |
|
104 ui_toolitem("button6", "Test6", action_button, NULL); |
|
105 ui_toolitem("button7", "Test7", action_button, NULL); |
|
106 ui_toolbar_add_default("button1"); |
|
107 ui_toolbar_add_default("button2"); |
|
108 ui_toolbar_add_default("button3"); |
|
109 ui_toolbar_add_default("button4"); |
|
110 ui_toolbar_add_default("button5"); |
|
111 ui_toolbar_add_default("button6"); |
|
112 ui_toolbar_add_default("button7"); |
|
113 |
128 |
114 ui_main(); |
129 ui_main(); |
115 |
130 |
116 return (EXIT_SUCCESS); |
131 return (EXIT_SUCCESS); |
117 } |
132 } |