ui/winui/list.cpp

branch
newapi
changeset 197
8a82ebe23822
parent 196
320d85f3cd14
child 204
4a258d47f964
equal deleted inserted replaced
196:320d85f3cd14 197:8a82ebe23822
114 current->container->Add(listview, false); 114 current->container->Add(listview, false);
115 115
116 return widget; 116 return widget;
117 } 117 }
118 118
119
120 UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args) {
121 UiObject* current = uic_current_obj(obj);
122
123 // create listview and toolkit wrapper
124 ComboBox combobox = ComboBox();
125
126 UIElement elm = combobox;
127 UiWidget* widget = new UiWidget(elm);
128 widget->data1 = args.model;
129 widget->data2 = args.getvalue;
130 ui_context_add_widget_destructor(current->ctx, widget);
131
132 // bind var
133 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
134 if (var) {
135 UiList* list = (UiList*)var->value;
136 list->update = ui_simple_list_update;
137 list->obj = widget;
138 ui_simple_list_update(list, 0);
139 }
140
141 if (args.onactivate) {
142 ui_callback cb = args.onactivate;
143 void* cbdata = args.onactivatedata;
144 combobox.SelectionChanged([cb, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) {
145 int selectedrow = sender.as<ComboBox>().SelectedIndex();
146 UiListSelection selection;
147 selection.count = 1;
148 selection.rows = &selectedrow;
149
150 UiEvent evt;
151 evt.obj = obj;
152 evt.window = obj->window;
153 evt.document = obj->ctx->document;
154 evt.eventdata = &selection;
155 evt.intval = selectedrow;
156 cb(&evt, cbdata);
157 });
158 }
159
160 // add listview to current container
161 UI_APPLY_LAYOUT1(current, args);
162
163 current->container->Add(combobox, false);
164
165 return widget;
166 }
167
119 static void* getstrvalue(void* elm, int ignore) { 168 static void* getstrvalue(void* elm, int ignore) {
120 return elm; 169 return elm;
121 } 170 }
122 171
123 void ui_simple_list_update(UiList* list, int i) { 172 void ui_simple_list_update(UiList* list, int i) {
124 UiWidget* widget = (UiWidget*)list->obj; 173 UiWidget* widget = (UiWidget*)list->obj;
125 UiModel* model = (UiModel*)widget->data1; 174 UiModel* model = (UiModel*)widget->data1;
126 ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2; 175 ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2;
127 ListView listview = widget->uielement.as<ListView>(); 176 ItemsControl listview = widget->uielement.as<ItemsControl>();
128 auto items = listview.Items(); 177 auto items = listview.Items();
129 178
130 // priority: getvalue, model.getvalue, getstrvalue (fallback) 179 // priority: getvalue, model.getvalue, getstrvalue (fallback)
131 if (getvalue == nullptr) { 180 if (getvalue == nullptr) {
132 if (model && model->getvalue) { 181 if (model && model->getvalue) {

mercurial