65 } |
69 } |
66 |
70 |
67 void action_switch(UiEvent* event, void* data) { |
71 void action_switch(UiEvent* event, void* data) { |
68 printf("onchange: %d\n", event->intval); |
72 printf("onchange: %d\n", event->intval); |
69 } |
73 } |
|
74 |
|
75 |
70 |
76 |
71 void action_listselection_changed(UiEvent* event, void* data) { |
77 void action_listselection_changed(UiEvent* event, void* data) { |
72 printf("selection changed\n"); |
78 printf("selection changed\n"); |
73 UiListSelection* sel = event->eventdata; |
79 UiListSelection* sel = event->eventdata; |
74 for (int i = 0; i < sel->count; i++) { |
80 for (int i = 0; i < sel->count; i++) { |
82 UiListSelection* sel = event->eventdata; |
88 UiListSelection* sel = event->eventdata; |
83 for (int i = 0; i < sel->count; i++) { |
89 for (int i = 0; i < sel->count; i++) { |
84 int row = sel->rows[i]; |
90 int row = sel->rows[i]; |
85 printf("row: %d\n", row); |
91 printf("row: %d\n", row); |
86 } |
92 } |
|
93 } |
|
94 |
|
95 typedef struct TableData { |
|
96 char* col1; |
|
97 char* col2; |
|
98 char* col3; |
|
99 } TableData; |
|
100 |
|
101 void* table_getvalue(void* data, int i) { |
|
102 TableData* t = data; |
|
103 switch (i) { |
|
104 case 0: return t->col1; |
|
105 case 1: return t->col2; |
|
106 case 2: return t->col3; |
|
107 } |
|
108 return NULL; |
|
109 } |
|
110 |
|
111 void action_add(UiEvent* event, void* data) { |
|
112 WindowData* wdata = event->window; |
|
113 char* t1 = wdata->t1->get(wdata->t1); |
|
114 char* t2 = wdata->t2->get(wdata->t2); |
|
115 char* t3 = wdata->t3->get(wdata->t3); |
|
116 |
|
117 TableData* tdat = malloc(sizeof(TableData)); |
|
118 tdat->col1 = _strdup(t1); |
|
119 tdat->col2 = _strdup(t2); |
|
120 tdat->col3 = _strdup(t3); |
|
121 ui_list_append(wdata->list2, tdat); |
|
122 wdata->list2->update(wdata->list2, 0); |
|
123 |
87 } |
124 } |
88 |
125 |
89 void application_startup(UiEvent* event, void* data) { |
126 void application_startup(UiEvent* event, void* data) { |
90 UiObject* obj = ui_window("Test", NULL); |
127 UiObject* obj = ui_window("Test", NULL); |
91 WindowData* wdata = ui_malloc(obj->ctx, sizeof(WindowData)); |
128 WindowData* wdata = ui_malloc(obj->ctx, sizeof(WindowData)); |
94 wdata->toggle = ui_int_new(obj->ctx, "toggle"); |
131 wdata->toggle = ui_int_new(obj->ctx, "toggle"); |
95 wdata->radio = ui_int_new(obj->ctx, "radio"); |
132 wdata->radio = ui_int_new(obj->ctx, "radio"); |
96 wdata->text = ui_string_new(obj->ctx, "text"); |
133 wdata->text = ui_string_new(obj->ctx, "text"); |
97 wdata->password = ui_string_new(obj->ctx, "password"); |
134 wdata->password = ui_string_new(obj->ctx, "password"); |
98 wdata->list = ui_list_new(obj->ctx, "list"); |
135 wdata->list = ui_list_new(obj->ctx, "list"); |
|
136 wdata->list2 = ui_list_new(obj->ctx, "list2"); |
|
137 wdata->t1 = ui_string_new(obj->ctx, "t1"); |
|
138 wdata->t2 = ui_string_new(obj->ctx, "t2"); |
|
139 wdata->t3 = ui_string_new(obj->ctx, "t3"); |
99 |
140 |
100 ui_list_append(wdata->list, "Hello"); |
141 ui_list_append(wdata->list, "Hello"); |
101 ui_list_append(wdata->list, "World"); |
142 ui_list_append(wdata->list, "World"); |
102 ui_list_append(wdata->list, "Item3"); |
143 ui_list_append(wdata->list, "Item3"); |
103 ui_list_append(wdata->list, "Item4"); |
144 ui_list_append(wdata->list, "Item4"); |
104 ui_list_append(wdata->list, "Item5"); |
145 ui_list_append(wdata->list, "Item5"); |
105 ui_list_append(wdata->list, "Item6"); |
146 ui_list_append(wdata->list, "Item6"); |
|
147 |
|
148 TableData* td1 = malloc(sizeof(TableData)); |
|
149 TableData* td2 = malloc(sizeof(TableData)); |
|
150 TableData* td3 = malloc(sizeof(TableData)); |
|
151 td1->col1 = "a1"; |
|
152 td1->col2 = "b1"; |
|
153 td1->col3 = "c1"; |
|
154 td2->col1 = "a2"; |
|
155 td2->col2 = "b2"; |
|
156 td2->col3 = "b3"; |
|
157 td3->col1 = "a3"; |
|
158 td3->col2 = "b3"; |
|
159 td3->col3 = "c3"; |
|
160 |
|
161 ui_list_append(wdata->list2, td1); |
|
162 ui_list_append(wdata->list2, td2); |
|
163 ui_list_append(wdata->list2, td3); |
106 |
164 |
107 ui_scrolledwindow0(obj) { |
165 ui_scrolledwindow0(obj) { |
108 ui_grid(obj, .margin = 10, .columnspacing = 5, .rowspacing = 20) { |
166 ui_grid(obj, .margin = 10, .columnspacing = 5, .rowspacing = 20) { |
109 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); |
167 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); |
110 ui_button(obj, .label = "Button2", .onclick = action1, .onclickdata = "action2"); |
168 ui_button(obj, .label = "Button2", .onclick = action1, .onclickdata = "action2"); |
157 } |
215 } |
158 ui_tab(obj, "Tab 2") { |
216 ui_tab(obj, "Tab 2") { |
159 ui_button(obj, .label = "Tab 2 Button"); |
217 ui_button(obj, .label = "Tab 2 Button"); |
160 } |
218 } |
161 } |
219 } |
|
220 |
|
221 ui_newline(obj); |
|
222 ui_textfield(obj, .value = wdata->t1); |
|
223 ui_textfield(obj, .value = wdata->t2); |
|
224 ui_textfield(obj, .value = wdata->t3); |
|
225 ui_newline(obj); |
|
226 ui_button(obj, .label = "Add", .onclick = action_add); |
|
227 ui_newline(obj); |
|
228 |
|
229 |
|
230 ui_newline(obj); |
|
231 |
|
232 UiModel* model = ui_model(obj->ctx, UI_STRING, "Col 1", UI_STRING, "Col 2", UI_STRING, "Col 3", -1); |
|
233 model->getvalue = table_getvalue; |
|
234 ui_table(obj, .colspan = 3, .model = model, .list = wdata->list2); |
|
235 ui_model_free(obj->ctx, model); |
162 } |
236 } |
163 } |
237 } |
164 |
238 |
165 ui_show(obj); |
239 ui_show(obj); |
166 } |
240 } |