68 // bind var |
68 // bind var |
69 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
69 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
70 if (var) { |
70 if (var) { |
71 UiList* list = (UiList*)var->value; |
71 UiList* list = (UiList*)var->value; |
72 list->update = ui_simple_list_update; |
72 list->update = ui_simple_list_update; |
|
73 list->getselection = ui_listview_getselection; |
|
74 list->setselection = ui_listview_setselection; |
73 list->obj = widget; |
75 list->obj = widget; |
|
76 |
74 ui_simple_list_update(list, 0); |
77 ui_simple_list_update(list, 0); |
75 } |
78 } |
76 |
79 |
77 if (args.onselection) { |
80 if (args.onselection) { |
78 ui_callback onselection = args.onselection; |
81 ui_callback onselection = args.onselection; |
136 // bind var |
139 // bind var |
137 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
140 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
138 if (var) { |
141 if (var) { |
139 UiList* list = (UiList*)var->value; |
142 UiList* list = (UiList*)var->value; |
140 list->update = ui_simple_list_update; |
143 list->update = ui_simple_list_update; |
|
144 list->getselection = ui_dropdown_getselection; |
|
145 list->setselection = ui_dropdown_setselection; |
141 list->obj = widget; |
146 list->obj = widget; |
142 ui_simple_list_update(list, 0); |
147 ui_simple_list_update(list, 0); |
143 } |
148 } |
144 |
149 |
145 if (args.onactivate) { |
150 if (args.onactivate) { |
165 UI_APPLY_LAYOUT1(current, args); |
170 UI_APPLY_LAYOUT1(current, args); |
166 |
171 |
167 current->container->Add(combobox, false); |
172 current->container->Add(combobox, false); |
168 |
173 |
169 return widget; |
174 return widget; |
|
175 } |
|
176 |
|
177 UiListSelection ui_listview_getselection(UiList *list) { |
|
178 UiWidget *widget = (UiWidget*)list->obj; |
|
179 ListView listview = widget->uielement.as<ListView>(); |
|
180 std::vector<int> selectedRows = ui_create_listview_selection(listview); |
|
181 |
|
182 UiListSelection selection = { NULL, 0 }; |
|
183 if (selectedRows.size() > 0) { |
|
184 selection.count = selectedRows.size(); |
|
185 int *data = selectedRows.data(); |
|
186 selection.rows = (int*)calloc(selection.count, sizeof(int)); |
|
187 memcpy(selection.rows, data, selection.count); |
|
188 } |
|
189 |
|
190 return selection; |
|
191 } |
|
192 |
|
193 void ui_listview_setselection(UiList *list, UiListSelection selection) { |
|
194 UiWidget* widget = (UiWidget*)list->obj; |
|
195 if (selection.count > 0) { |
|
196 ListView listview = widget->uielement.as<ListView>(); |
|
197 listview.SelectedIndex(selection.rows[0]); |
|
198 } |
|
199 } |
|
200 |
|
201 UiListSelection ui_dropdown_getselection(UiList *list) { |
|
202 UiWidget* widget = (UiWidget*)list->obj; |
|
203 ComboBox cb = widget->uielement.as<ComboBox>(); |
|
204 int index = cb.SelectedIndex(); |
|
205 UiListSelection selection = { NULL, 0 }; |
|
206 if (index >= 0) { |
|
207 selection.rows = (int*)calloc(1, sizeof(int)); |
|
208 selection.count = 1; |
|
209 selection.rows[0] = index; |
|
210 } |
|
211 return selection; |
|
212 } |
|
213 |
|
214 void ui_dropdown_setselection(UiList *list, UiListSelection selection) { |
|
215 UiWidget* widget = (UiWidget*)list->obj; |
|
216 if (selection.count > 0) { |
|
217 ComboBox cb = widget->uielement.as<ComboBox>(); |
|
218 cb.SelectedIndex(selection.rows[0]); |
|
219 } |
170 } |
220 } |
171 |
221 |
172 UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) { |
222 UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) { |
173 UiObject* current = uic_current_obj(obj); |
223 UiObject* current = uic_current_obj(obj); |
174 |
224 |