ui/common/types.c

changeset 1104
2cbfa74acda7
parent 1100
7773850dc77f
child 1105
8e8c7670547f
equal deleted inserted replaced
1103:4ba6f75d8966 1104:2cbfa74acda7
98 } 98 }
99 99
100 /* --------------------------- UiList --------------------------- */ 100 /* --------------------------- UiList --------------------------- */
101 101
102 void uic_ucx_list_init(UiContext *ctx, UiList *list, void *unused) { 102 void uic_ucx_list_init(UiContext *ctx, UiList *list, void *unused) {
103 const CxAllocator *a = ctx ? ctx->allocator : cxDefaultAllocator;
103 list->destroy = uic_ucx_list_destroy; 104 list->destroy = uic_ucx_list_destroy;
104 list->data = cxArrayListCreate(ctx->mp->allocator, CX_STORE_POINTERS, 32); 105 list->data = cxArrayListCreate(a, CX_STORE_POINTERS, 32);
105 list->first = ui_list_first; 106 list->first = ui_list_first;
106 list->next = ui_list_next; 107 list->next = ui_list_next;
107 list->get = ui_list_get; 108 list->get = ui_list_get;
108 list->count = ui_list_count; 109 list->count = ui_list_count;
109 } 110 }
392 393
393 // public functions 394 // public functions
394 UiInteger* ui_int_new(UiContext *ctx, const char *name) { 395 UiInteger* ui_int_new(UiContext *ctx, const char *name) {
395 UiInteger *i = ui_malloc(ctx, sizeof(UiInteger)); 396 UiInteger *i = ui_malloc(ctx, sizeof(UiInteger));
396 memset(i, 0, sizeof(UiInteger)); 397 memset(i, 0, sizeof(UiInteger));
397 if(name) { 398 if(name && ctx) {
398 uic_reg_var(ctx, name, UI_VAR_INTEGER, i); 399 uic_reg_var(ctx, name, UI_VAR_INTEGER, i);
399 } 400 }
400 return i; 401 return i;
401 } 402 }
402 403
403 UiDouble* ui_double_new(UiContext *ctx, const char *name) { 404 UiDouble* ui_double_new(UiContext *ctx, const char *name) {
404 UiDouble *d = ui_malloc(ctx, sizeof(UiDouble)); 405 UiDouble *d = ui_malloc(ctx, sizeof(UiDouble));
405 memset(d, 0, sizeof(UiDouble)); 406 memset(d, 0, sizeof(UiDouble));
406 if(name) { 407 if(name && ctx) {
407 uic_reg_var(ctx, name, UI_VAR_DOUBLE, d); 408 uic_reg_var(ctx, name, UI_VAR_DOUBLE, d);
408 } 409 }
409 return d; 410 return d;
410 } 411 }
411 412
417 418
418 UiString* ui_string_new(UiContext *ctx, const char *name) { 419 UiString* ui_string_new(UiContext *ctx, const char *name) {
419 UiString *s = ui_malloc(ctx, sizeof(UiString)); 420 UiString *s = ui_malloc(ctx, sizeof(UiString));
420 memset(s, 0, sizeof(UiString)); 421 memset(s, 0, sizeof(UiString));
421 ui_set_destructor(s, (ui_destructor_func)string_destroy); 422 ui_set_destructor(s, (ui_destructor_func)string_destroy);
422 if(name) { 423 if(name && ctx) {
423 uic_reg_var(ctx, name, UI_VAR_STRING, s); 424 uic_reg_var(ctx, name, UI_VAR_STRING, s);
424 } 425 }
425 return s; 426 return s;
426 } 427 }
427 428
433 434
434 UiText* ui_text_new(UiContext *ctx, const char *name) { 435 UiText* ui_text_new(UiContext *ctx, const char *name) {
435 UiText *t = ui_malloc(ctx, sizeof(UiText)); 436 UiText *t = ui_malloc(ctx, sizeof(UiText));
436 memset(t, 0, sizeof(UiText)); 437 memset(t, 0, sizeof(UiText));
437 ui_set_destructor(t, (ui_destructor_func)text_destroy); 438 ui_set_destructor(t, (ui_destructor_func)text_destroy);
438 if(name) { 439 if(name && ctx) {
439 uic_reg_var(ctx, name, UI_VAR_TEXT, t); 440 uic_reg_var(ctx, name, UI_VAR_TEXT, t);
440 } 441 }
441 return t; 442 return t;
442 } 443 }
443 444
444 UiRange* ui_range_new(UiContext *ctx, const char *name) { 445 UiRange* ui_range_new(UiContext *ctx, const char *name) {
445 UiRange *r = ui_malloc(ctx, sizeof(UiRange)); 446 UiRange *r = ui_malloc(ctx, sizeof(UiRange));
446 memset(r, 0, sizeof(UiRange)); 447 memset(r, 0, sizeof(UiRange));
447 if(name) { 448 if(name && ctx) {
448 uic_reg_var(ctx, name, UI_VAR_RANGE, r); 449 uic_reg_var(ctx, name, UI_VAR_RANGE, r);
449 } 450 }
450 return r; 451 return r;
451 } 452 }
452 453
457 } 458 }
458 459
459 UiGeneric* ui_generic_new(UiContext *ctx, const char *name) { 460 UiGeneric* ui_generic_new(UiContext *ctx, const char *name) {
460 UiGeneric *g = ui_malloc(ctx, sizeof(UiGeneric)); 461 UiGeneric *g = ui_malloc(ctx, sizeof(UiGeneric));
461 memset(g, 0, sizeof(UiGeneric)); 462 memset(g, 0, sizeof(UiGeneric));
462 ui_set_destructor(g, (ui_destructor_func)generic_destroy); 463 if(ctx) {
463 if(name) { 464 ui_set_destructor(g, (ui_destructor_func)generic_destroy);
465 }
466 if(name && ctx) {
464 uic_reg_var(ctx, name, UI_VAR_GENERIC, g); 467 uic_reg_var(ctx, name, UI_VAR_GENERIC, g);
465 } 468 }
466 return g; 469 return g;
467 } 470 }
468 471

mercurial