35 #include <cx/utils.h> |
35 #include <cx/utils.h> |
36 |
36 |
37 #include "cx/string.h" |
37 #include "cx/string.h" |
38 #include "cx/list.h" |
38 #include "cx/list.h" |
39 |
39 |
40 #if !defined(UI_COCOA) && !defined(UI_MOTIF) && !defined(UI_WIN32) && !defined(UI_QT) |
40 #define UI_TEST |
|
41 |
|
42 #ifdef UI_TEST |
|
43 |
|
44 #define STATE_DOC 10 |
|
45 #define STATE_SUB 100 |
|
46 |
|
47 typedef struct ToplevelDoc { |
|
48 UiContext *ctx; |
|
49 |
|
50 UiList *doclist; |
|
51 |
|
52 void *current; |
|
53 } ToplevelDoc; |
|
54 |
|
55 typedef struct Document { |
|
56 UiContext *ctx; |
|
57 |
|
58 UiString *name; |
|
59 char *name_str; |
|
60 |
|
61 UiInteger *i; |
|
62 UiString *s; |
|
63 UiText *t; |
|
64 UiList *ls1; |
|
65 UiList *ls2; |
|
66 } Document; |
|
67 |
|
68 |
|
69 |
|
70 Document* create_doc(int i) { |
|
71 Document *doc = ui_document_new(sizeof(Document)); |
|
72 doc->ctx = ui_document_context(doc); |
|
73 doc->name = ui_string_new(doc->ctx, "name"); |
|
74 doc->i = ui_int_new(doc->ctx, "int"); |
|
75 doc->s = ui_string_new(doc->ctx, "string"); |
|
76 doc->t = ui_text_new(doc->ctx, "text"); |
|
77 doc->ls1 = ui_list_new(doc->ctx, "list1"); |
|
78 doc->ls2 = ui_list_new(doc->ctx, "list2"); |
|
79 |
|
80 ui_list_append(doc->ls1, "Hello"); |
|
81 ui_list_append(doc->ls1, "World"); |
|
82 ui_list_append(doc->ls1, "Test"); |
|
83 |
|
84 for(int x=0;x<(i+1)*2;x++) { |
|
85 char buf[32]; |
|
86 snprintf(buf, 32, "%d", x); |
|
87 ui_list_append(doc->ls2, strdup(buf)); |
|
88 } |
|
89 |
|
90 return doc; |
|
91 } |
|
92 |
|
93 ToplevelDoc* create_toplevel() { |
|
94 ToplevelDoc *doc = ui_document_new(sizeof(ToplevelDoc)); |
|
95 doc->ctx = ui_document_context(doc); |
|
96 doc->doclist = ui_list_new(doc->ctx, "doclist"); |
|
97 |
|
98 for(int i=0;i<3;i++) { |
|
99 Document *sub = create_doc(i); |
|
100 char buf[32]; |
|
101 snprintf(buf, 32, "%d", i); |
|
102 ui_set(sub->name, buf); |
|
103 sub->name_str = strdup(buf); |
|
104 ui_list_append(doc->doclist, sub); |
|
105 } |
|
106 |
|
107 return doc; |
|
108 } |
|
109 |
|
110 static void* doclist_getvalue(void *elm, int col) { |
|
111 Document *doc = elm; |
|
112 return doc->name_str; |
|
113 } |
|
114 |
|
115 static void action_document_selected(UiEvent *event, void *userdata) { |
|
116 Document *sub = event->eventdata; |
|
117 ToplevelDoc *doc = event->document; |
|
118 if(doc->current) { |
|
119 ui_detach_document2(doc->ctx, doc->current); |
|
120 } |
|
121 ui_attach_document(doc->ctx, sub); |
|
122 doc->current = sub; |
|
123 } |
|
124 |
|
125 void application_startup(UiEvent *event, void *data) { |
|
126 UiObject *obj = ui_window("Test", NULL); |
|
127 |
|
128 ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10) { |
|
129 ui_hbox(obj, .colspan = 2, .spacing = 10) { |
|
130 ui_combobox(obj, .varname = "doclist", .getvalue = doclist_getvalue, .onactivate = action_document_selected); |
|
131 ui_textfield(obj, .varname = "name"); |
|
132 ui_button(obj, .colspan = 4, .label = "Test Groups", .groups = UI_GROUPS(STATE_DOC, STATE_SUB)); |
|
133 } |
|
134 ui_newline(obj); |
|
135 |
|
136 ui_rlabel(obj, .label = "Integer", .vfill = TRUE); |
|
137 ui_togglebutton(obj, .label = "Test", .varname = "int", .hfill = TRUE); |
|
138 ui_newline(obj); |
|
139 |
|
140 |
|
141 ui_rlabel(obj, .label = "String", .vfill = TRUE); |
|
142 ui_textfield(obj, .varname = "string", .hfill = TRUE); |
|
143 ui_newline(obj); |
|
144 |
|
145 ui_rlabel(obj, .label = "Text"); |
|
146 UIWIDGET textarea = ui_textarea(obj, .varname = "text", .hfill =TRUE); |
|
147 ui_widget_set_size(textarea, 300, 300); |
|
148 ui_newline(obj); |
|
149 |
|
150 ui_rlabel(obj, .label = "List 1", .vfill = TRUE); |
|
151 ui_combobox(obj, .varname = "list1"); |
|
152 } |
|
153 |
|
154 ToplevelDoc *doc = create_toplevel(); |
|
155 ui_attach_document(obj->ctx, doc); |
|
156 |
|
157 ui_show(obj); |
|
158 } |
|
159 |
|
160 int main(int argc, char** argv) { |
|
161 ui_init("app1", argc, argv); |
|
162 ui_onstartup(application_startup, NULL); |
|
163 |
|
164 ui_set_property("ui.gtk.window.showtitle", "main"); |
|
165 |
|
166 // menu |
|
167 ui_menu("File") { |
|
168 ui_menuitem(.label = "Static Item"); |
|
169 ui_menuseparator(); |
|
170 ui_menu_itemlist(.varname = "list2"); |
|
171 } |
|
172 |
|
173 ui_main(); |
|
174 |
|
175 return (EXIT_SUCCESS); |
|
176 } |
|
177 |
|
178 |
|
179 #endif |
|
180 |
|
181 |
|
182 #if !defined(UI_COCOA) && !defined(UI_MOTIF) && !defined(UI_WIN32) && !defined(UI_QT) && !defined(UI_TEST) |
41 |
183 |
42 typedef struct { |
184 typedef struct { |
43 UiString *str1; |
185 UiString *str1; |
44 UiString *str2; |
186 UiString *str2; |
45 UiString *path; |
187 UiString *path; |