163 current->container->Add(combobox, false); |
163 current->container->Add(combobox, false); |
164 |
164 |
165 return widget; |
165 return widget; |
166 } |
166 } |
167 |
167 |
|
168 UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) { |
|
169 UiObject* current = uic_current_obj(obj); |
|
170 |
|
171 // create listview and toolkit wrapper |
|
172 BreadcrumbBar bcbar = BreadcrumbBar(); |
|
173 |
|
174 UIElement elm = bcbar; |
|
175 UiWidget* widget = new UiWidget(elm); |
|
176 widget->data1 = args.model; |
|
177 widget->data2 = args.getvalue; |
|
178 ui_context_add_widget_destructor(current->ctx, widget); |
|
179 |
|
180 // bind var |
|
181 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
|
182 if (var) { |
|
183 UiList* list = (UiList*)var->value; |
|
184 list->update = ui_breadcrumbbar_update; |
|
185 list->obj = widget; |
|
186 ui_breadcrumbbar_update(list, 0); |
|
187 } |
|
188 |
|
189 if (args.onactivate) { |
|
190 ui_callback cb = args.onactivate; |
|
191 void* cbdata = args.onactivatedata; |
|
192 bcbar.ItemClicked([cb, cbdata, obj](IInspectable const& sender, BreadcrumbBarItemClickedEventArgs evtargs) { |
|
193 UiEvent evt; |
|
194 evt.obj = obj; |
|
195 evt.window = obj->window; |
|
196 evt.document = obj->ctx->document; |
|
197 evt.eventdata = nullptr; |
|
198 evt.intval = evtargs.Index(); |
|
199 cb(&evt, cbdata); |
|
200 }); |
|
201 } |
|
202 |
|
203 // add listview to current container |
|
204 UI_APPLY_LAYOUT1(current, args); |
|
205 |
|
206 current->container->Add(bcbar, false); |
|
207 |
|
208 return widget; |
|
209 } |
|
210 |
168 static void* getstrvalue(void* elm, int ignore) { |
211 static void* getstrvalue(void* elm, int ignore) { |
169 return elm; |
212 return elm; |
170 } |
213 } |
171 |
214 |
172 void ui_simple_list_update(UiList* list, int i) { |
215 void ui_simple_list_update(UiList* list, int i) { |
194 items.Append(box_value(wstr)); |
237 items.Append(box_value(wstr)); |
195 free(wstr); |
238 free(wstr); |
196 |
239 |
197 elm = list->next(list); |
240 elm = list->next(list); |
198 } |
241 } |
|
242 } |
|
243 |
|
244 extern "C" void ui_breadcrumbbar_update(UiList * list, int i) { |
|
245 UiWidget* widget = (UiWidget*)list->obj; |
|
246 UiModel* model = (UiModel*)widget->data1; |
|
247 ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2; |
|
248 |
|
249 // priority: getvalue, model.getvalue, getstrvalue (fallback) |
|
250 if (getvalue == nullptr) { |
|
251 if (model && model->getvalue) { |
|
252 getvalue = model->getvalue; |
|
253 } |
|
254 else { |
|
255 getvalue = getstrvalue; |
|
256 } |
|
257 } |
|
258 |
|
259 BreadcrumbBar bar = widget->uielement.as<BreadcrumbBar>(); |
|
260 |
|
261 Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> items { winrt::single_threaded_vector<Windows::Foundation::IInspectable>() }; |
|
262 void* elm = list->first(list); |
|
263 while (elm) { |
|
264 char* value = (char*)getvalue(elm, 0); |
|
265 wchar_t* wstr = str2wstr(value, nullptr); |
|
266 items.Append(box_value(wstr)); |
|
267 free(wstr); |
|
268 |
|
269 elm = list->next(list); |
|
270 } |
|
271 |
|
272 bar.ItemsSource(items); |
199 } |
273 } |
200 |
274 |
201 std::vector<int> ui_create_listview_selection(ListView listview) { |
275 std::vector<int> ui_create_listview_selection(ListView listview) { |
202 std::vector<int> selection; |
276 std::vector<int> selection; |
203 int p = 0; |
277 int p = 0; |