29 #include "pch.h" |
29 #include "pch.h" |
30 |
30 |
31 #include "table.h" |
31 #include "table.h" |
32 #include "container.h" |
32 #include "container.h" |
33 #include "util.h" |
33 #include "util.h" |
|
34 #include "icons.h" |
34 |
35 |
35 #include "../common/context.h" |
36 #include "../common/context.h" |
36 #include "../common/object.h" |
37 #include "../common/object.h" |
|
38 #include "../common/types.h" |
37 |
39 |
38 #include <winrt/Microsoft.UI.Xaml.Data.h> |
40 #include <winrt/Microsoft.UI.Xaml.Data.h> |
39 #include <winrt/Microsoft.UI.Xaml.Media.h> |
41 #include <winrt/Microsoft.UI.Xaml.Media.h> |
40 #include <winrt/Microsoft.UI.Xaml.Input.h> |
42 #include <winrt/Microsoft.UI.Xaml.Input.h> |
41 #include <winrt/Windows.UI.Core.h> |
43 #include <winrt/Windows.UI.Core.h> |
195 rowdef.Height(gl); |
217 rowdef.Height(gl); |
196 grid.RowDefinitions().Append(rowdef); |
218 grid.RowDefinitions().Append(rowdef); |
197 maxrows = row; |
219 maxrows = row; |
198 } |
220 } |
199 |
221 |
200 for (int col = 0; col < header.size(); col++) { |
222 Thickness cellpadding = { 10,0,4,0 }; |
|
223 |
|
224 int model_col = 0; |
|
225 for (int col = 0; col < header.size(); col++, model_col++) { |
201 // create ui elements with the correct cell border |
226 // create ui elements with the correct cell border |
202 // dependeing on the column |
227 // dependeing on the column |
203 Border cellBorder = Border(); |
228 Border cellBorder = Border(); |
204 cellBorder.Background(defaultBrush); |
229 cellBorder.Background(defaultBrush); |
205 TextBlock cell = TextBlock(); |
230 |
206 cellBorder.Child(cell); |
231 // set the cell value |
|
232 UiModelType type = model->types[col]; |
|
233 switch (type) { |
|
234 case UI_STRING: { |
|
235 TextBlock cell = TextBlock(); |
|
236 cell.Padding(cellpadding); |
|
237 cell.VerticalAlignment(VerticalAlignment::Stretch); |
|
238 textblock_set_str(cell, (char*)getvalue(elm, model_col)); |
|
239 cellBorder.Child(cell); |
|
240 break; |
|
241 } |
|
242 case UI_INTEGER: { |
|
243 TextBlock cell = TextBlock(); |
|
244 cell.Padding(cellpadding); |
|
245 cell.VerticalAlignment(VerticalAlignment::Stretch); |
|
246 int *value = (int*)getvalue(elm, model_col); |
|
247 if (value) { |
|
248 textblock_set_int(cell, *value); |
|
249 } |
|
250 cellBorder.Child(cell); |
|
251 break; |
|
252 } |
|
253 case UI_ICON: { |
|
254 UiIcon* iconConstr = (UiIcon*)getvalue(elm, model_col); |
|
255 if (iconConstr) { |
|
256 IconElement icon = iconConstr->getIcon(); |
|
257 cellBorder.Child(icon); |
|
258 } |
|
259 break; |
|
260 } |
|
261 case UI_ICON_TEXT: { |
|
262 StackPanel cellPanel = StackPanel(); |
|
263 cellPanel.Spacing(2); |
|
264 cellPanel.Padding(cellpadding); |
|
265 cellPanel.VerticalAlignment(VerticalAlignment::Stretch); |
|
266 |
|
267 cellPanel.Orientation(Orientation::Horizontal); |
|
268 UiIcon* iconConstr = (UiIcon*)getvalue(elm, model_col++); |
|
269 char* str = (char*)getvalue(elm, model_col); |
|
270 if (iconConstr) { |
|
271 IconElement icon = iconConstr->getIcon(); |
|
272 cellPanel.Children().Append(icon); |
|
273 } |
|
274 TextBlock cell = TextBlock(); |
|
275 textblock_set_str(cell, str); |
|
276 cellPanel.Children().Append(cell); |
|
277 cellBorder.Child(cellPanel); |
|
278 break; |
|
279 } |
|
280 } |
|
281 |
207 cellBorder.BorderBrush(defaultBrush); |
282 cellBorder.BorderBrush(defaultBrush); |
208 if (col == 0) { |
283 if (col == 0) { |
209 cellBorder.BorderThickness(b1); |
284 cellBorder.BorderThickness(b1); |
210 } |
285 } |
211 else if (col + 1 == header.size()) { |
286 else if (col + 1 == header.size()) { |
212 cellBorder.BorderThickness(b3); |
287 cellBorder.BorderThickness(b3); |
213 } |
288 } |
214 else { |
289 else { |
215 cellBorder.BorderThickness(b2); |
290 cellBorder.BorderThickness(b2); |
216 } |
|
217 Thickness padding = { 10,0,4,0 }; |
|
218 cell.Padding(padding); |
|
219 cell.VerticalAlignment(VerticalAlignment::Stretch); |
|
220 |
|
221 // set cell value |
|
222 char* value = (char*)getvalue(elm, col); |
|
223 if (value) { |
|
224 wchar_t* wstr = str2wstr(value, nullptr); |
|
225 cell.Text(winrt::hstring(wstr)); |
|
226 free(wstr); |
|
227 } |
291 } |
228 |
292 |
229 // event handler |
293 // event handler |
230 cellBorder.PointerPressed( |
294 cellBorder.PointerPressed( |
231 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
295 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |