| 218 } |
218 } |
| 219 |
219 |
| 220 va_end(ap); |
220 va_end(ap); |
| 221 |
221 |
| 222 size_t len = cxListSize(cols); |
222 size_t len = cxListSize(cols); |
| |
223 info->alloc = len; |
| 223 info->columns = len; |
224 info->columns = len; |
| 224 info->types = ui_calloc(ctx, len, sizeof(UiModelType)); |
225 info->types = ui_calloc(ctx, len, sizeof(UiModelType)); |
| 225 info->titles = ui_calloc(ctx, len, sizeof(char*)); |
226 info->titles = ui_calloc(ctx, len, sizeof(char*)); |
| 226 info->columnsize = ui_calloc(ctx, len, sizeof(int)); |
227 info->columnsize = ui_calloc(ctx, len, sizeof(int)); |
| 227 |
228 |
| 228 int i = 0; |
229 int i = 0; |
| 229 CxIterator iter = cxListIterator(cols); |
230 CxIterator iter = cxListIterator(cols); |
| 230 cx_foreach(UiColumn*, c, iter) { |
231 cx_foreach(UiColumn*, c, iter) { |
| 231 info->types[i] = c->type; |
232 info->types[i] = c->type; |
| 232 info->titles[i] = c->name; |
233 info->titles[i] = ui_strdup(ctx, c->name); |
| 233 i++; |
234 i++; |
| 234 } |
235 } |
| 235 cxListFree(cols); |
236 cxListFree(cols); |
| 236 |
237 |
| 237 return info; |
238 return info; |
| |
239 } |
| |
240 |
| |
241 #define UI_MODEL_DEFAULT_ALLOC_SIZE 16 |
| |
242 |
| |
243 UiModel* ui_model_new(UiContext *ctx) { |
| |
244 UiModel *info = ui_calloc(ctx, 1, sizeof(UiModel)); |
| |
245 info->alloc = UI_MODEL_DEFAULT_ALLOC_SIZE; |
| |
246 info->types = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(UiModelType)); |
| |
247 info->titles = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(char*)); |
| |
248 info->columnsize = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(int)); |
| |
249 return info; |
| |
250 } |
| |
251 |
| |
252 void ui_model_add_column(UiContext *ctx, UiModel *model, UiModelType type, const char *title, int width) { |
| |
253 if(model->columns >= model->alloc) { |
| |
254 model->alloc += UI_MODEL_DEFAULT_ALLOC_SIZE; |
| |
255 model->types = ui_realloc(ctx, model->types, model->alloc * sizeof(UiModelType)); |
| |
256 model->titles = ui_realloc(ctx, model->titles, model->alloc * sizeof(char*)); |
| |
257 model->columnsize = ui_realloc(ctx, model->columnsize, model->alloc * sizeof(int)); |
| |
258 } |
| |
259 model->types[model->columns] = type; |
| |
260 model->titles[model->columns] = ui_strdup(ctx, title); |
| |
261 model->columnsize[model->columns] = width; |
| |
262 model->columns++; |
| 238 } |
263 } |
| 239 |
264 |
| 240 UiModel* ui_model_copy(UiContext *ctx, UiModel* model) { |
265 UiModel* ui_model_copy(UiContext *ctx, UiModel* model) { |
| 241 const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator; |
266 const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator; |
| 242 |
267 |
| 256 return newmodel; |
281 return newmodel; |
| 257 } |
282 } |
| 258 |
283 |
| 259 void ui_model_free(UiContext *ctx, UiModel *mi) { |
284 void ui_model_free(UiContext *ctx, UiModel *mi) { |
| 260 const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator; |
285 const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator; |
| |
286 for(int i=0;i<mi->columns;i++) { |
| |
287 ui_free(ctx, mi->titles[i]); |
| |
288 } |
| 261 cxFree(a, mi->types); |
289 cxFree(a, mi->types); |
| 262 cxFree(a, mi->titles); |
290 cxFree(a, mi->titles); |
| 263 cxFree(a, mi->columnsize); |
291 cxFree(a, mi->columnsize); |
| 264 cxFree(a, mi); |
292 cxFree(a, mi); |
| 265 } |
293 } |
| 417 char* ui_text_get(UiText* s) { |
445 char* ui_text_get(UiText* s) { |
| 418 if (s) { |
446 if (s) { |
| 419 return s->get ? s->get(s) : s->value.ptr; |
447 return s->get ? s->get(s) : s->value.ptr; |
| 420 } |
448 } |
| 421 else { |
449 else { |
| |
450 return NULL; |
| |
451 } |
| |
452 } |
| |
453 |
| |
454 void ui_range_set(UiRange *r, double value) { |
| |
455 if (r) { |
| |
456 if (r->set) { |
| |
457 r->set(r, value); |
| |
458 } else { |
| |
459 r->value = value; |
| |
460 } |
| |
461 } |
| |
462 } |
| |
463 |
| |
464 void ui_range_set_range(UiRange *r, double min, double max) { |
| |
465 if (r) { |
| |
466 if (r->setrange) { |
| |
467 r->setrange(r, min, max); |
| |
468 } else { |
| |
469 r->min = min; |
| |
470 r->max = max; |
| |
471 } |
| |
472 } |
| |
473 } |
| |
474 |
| |
475 void ui_range_set_extent(UiRange *r, double extent) { |
| |
476 if (r) { |
| |
477 if (r->setextent) { |
| |
478 r->setextent(r, extent); |
| |
479 } else { |
| |
480 r->extent = extent; |
| |
481 } |
| |
482 } |
| |
483 } |
| |
484 |
| |
485 double ui_range_get(UiRange *r) { |
| |
486 if (r) { |
| |
487 return r->get ? r->get(r) : r->value; |
| |
488 } else { |
| |
489 return 0; |
| |
490 } |
| |
491 } |
| |
492 |
| |
493 double ui_range_get_min(UiRange *r) { |
| |
494 if (r) { |
| |
495 return r->min; |
| |
496 } else { |
| |
497 return 0; |
| |
498 } |
| |
499 } |
| |
500 |
| |
501 double ui_range_get_max(UiRange *r) { |
| |
502 if (r) { |
| |
503 return r->max; |
| |
504 } else { |
| |
505 return 0; |
| |
506 } |
| |
507 } |
| |
508 |
| |
509 double ui_range_get_extent(UiRange *r) { |
| |
510 if (r) { |
| |
511 return r->extent; |
| |
512 } else { |
| 422 return 0; |
513 return 0; |
| 423 } |
514 } |
| 424 } |
515 } |
| 425 |
516 |
| 426 void ui_generic_set_image(UiGeneric *g, void *img) { |
517 void ui_generic_set_image(UiGeneric *g, void *img) { |
| 597 } |
690 } |
| 598 return (UiListSelection){ 0, NULL }; |
691 return (UiListSelection){ 0, NULL }; |
| 599 } |
692 } |
| 600 |
693 |
| 601 UIEXPORT void ui_list_setselection(UiList *list, int index) { |
694 UIEXPORT void ui_list_setselection(UiList *list, int index) { |
| 602 if (list->setselection && index >= 0) { |
695 if (list->setselection) { |
| 603 UiListSelection sel; |
696 UiListSelection sel = { 0, NULL }; |
| 604 sel.count = 1; |
697 if(index >= 0) { |
| 605 sel.rows = &index; |
698 sel.count = 1; |
| |
699 sel.rows = &index; |
| |
700 } |
| 606 list->setselection(list, sel); |
701 list->setselection(list, sel); |
| 607 } |
702 } |
| 608 } |
703 } |
| 609 |
704 |
| 610 UIEXPORT void ui_listselection_free(UiListSelection selection) { |
705 UIEXPORT void ui_listselection_free(UiListSelection selection) { |