| 693 |
693 |
| 694 void ui_set_destructor(void *mem, ui_destructor_func destr) { |
694 void ui_set_destructor(void *mem, ui_destructor_func destr) { |
| 695 cxMempoolSetDestructor(mem, (cx_destructor_func)destr); |
695 cxMempoolSetDestructor(mem, (cx_destructor_func)destr); |
| 696 } |
696 } |
| 697 |
697 |
| |
698 void ui_var_set_int(UiContext *ctx, const char *name, int64_t value) { |
| |
699 UiInteger *i = ui_get_int_var(ctx, name); |
| |
700 if(i) { |
| |
701 ui_set(i, value); |
| |
702 } |
| |
703 } |
| |
704 |
| |
705 int64_t ui_var_get_int(UiContext *ctx, const char *name) { |
| |
706 UiInteger *i = ui_get_int_var(ctx, name); |
| |
707 if(i) { |
| |
708 return ui_get(i); |
| |
709 } |
| |
710 return 0; |
| |
711 } |
| |
712 |
| |
713 void ui_var_set_double(UiContext *ctx, const char *name, double value) { |
| |
714 UiDouble *d = ui_get_double_var(ctx, name); |
| |
715 if(d) { |
| |
716 ui_set(d, value); |
| |
717 } |
| |
718 } |
| |
719 |
| |
720 double ui_var_get_double(UiContext *ctx, const char *name) { |
| |
721 UiDouble *d = ui_get_double_var(ctx, name); |
| |
722 if(d) { |
| |
723 return ui_get(d); |
| |
724 } |
| |
725 return 0; |
| |
726 } |
| |
727 |
| |
728 void ui_var_set_string(UiContext *ctx, const char *name, char *value) { |
| |
729 UiString *s = ui_get_string_var(ctx, name); |
| |
730 if(s) { |
| |
731 ui_set(s, value); |
| |
732 } |
| |
733 } |
| |
734 |
| |
735 char* ui_var_get_string(UiContext *ctx, const char *name) { |
| |
736 UiString *s = ui_get_string_var(ctx, name); |
| |
737 if(s) { |
| |
738 return ui_get(s); |
| |
739 } |
| |
740 return NULL; |
| |
741 } |
| |
742 |
| |
743 UIEXPORT void ui_var_add_observer(UiContext *ctx, const char *varname, ui_callback f, void *data) { |
| |
744 UiVar *var = uic_get_var(ctx, varname); |
| |
745 if(!var) { |
| |
746 return; |
| |
747 } |
| |
748 |
| |
749 switch(var->type) { |
| |
750 case UI_VAR_INTEGER: { |
| |
751 UiInteger *v = var->value; |
| |
752 v->observers = ui_add_observer(v->observers, f, data); |
| |
753 break; |
| |
754 } |
| |
755 case UI_VAR_DOUBLE: { |
| |
756 UiDouble *v = var->value; |
| |
757 v->observers = ui_add_observer(v->observers, f, data); |
| |
758 break; |
| |
759 } |
| |
760 case UI_VAR_RANGE: { |
| |
761 UiRange *v = var->value; |
| |
762 v->observers = ui_add_observer(v->observers, f, data); |
| |
763 break; |
| |
764 } |
| |
765 case UI_VAR_STRING: { |
| |
766 UiString *v = var->value; |
| |
767 v->observers = ui_add_observer(v->observers, f, data); |
| |
768 break; |
| |
769 } |
| |
770 case UI_VAR_TEXT: { |
| |
771 UiText *v = var->value; |
| |
772 v->observers = ui_add_observer(v->observers, f, data); |
| |
773 break; |
| |
774 } |
| |
775 case UI_VAR_LIST: { |
| |
776 UiList *v = var->value; |
| |
777 v->observers = ui_add_observer(v->observers, f, data); |
| |
778 break; |
| |
779 } |
| |
780 } |
| |
781 } |
| |
782 |
| 698 UiInteger* ui_get_int_var(UiContext *ctx, const char *name) { |
783 UiInteger* ui_get_int_var(UiContext *ctx, const char *name) { |
| 699 UiVar *var = uic_get_var_t(ctx, name, UI_VAR_INTEGER); |
784 UiVar *var = uic_get_var_t(ctx, name, UI_VAR_INTEGER); |
| 700 return var ? var->value : NULL; |
785 return var ? var->value : NULL; |
| 701 } |
786 } |
| 702 |
787 |