Mon, 09 Jun 2025 08:41:16 +0200
add ui_image_set/ui_image_get for setting UiGeneric image values
| ui/common/types.c | file | annotate | diff | comparison | revisions | |
| ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/ui/common/types.c Sun Jun 08 23:47:00 2025 +0200 +++ b/ui/common/types.c Mon Jun 09 08:41:16 2025 +0200 @@ -36,6 +36,7 @@ #include "../ui/tree.h" #include "types.h" #include "context.h" +#include "../ui/image.h" @@ -395,6 +396,28 @@ } } +void ui_image_set(UiGeneric *g, void *img) { + // TODO: ref? + if(g->set) { + g->set(g, img, UI_IMAGE_OBJECT_TYPE); + } else { + g->value = img; + g->type = UI_IMAGE_OBJECT_TYPE; + } +} + +void* ui_image_get(UiGeneric *g) { + if(g->type) { + if(!strcmp(g->type, UI_IMAGE_OBJECT_TYPE)) { + return g->value; + } else { + return NULL; + } + } + return g->value; +} + + char* ui_text_get(UiText* s) { if (s) { return s->get ? s->get(s) : s->value.ptr;
--- a/ui/ui/toolkit.h Sun Jun 08 23:47:00 2025 +0200 +++ b/ui/ui/toolkit.h Mon Jun 09 08:41:16 2025 +0200 @@ -558,6 +558,8 @@ UIEXPORT char* ui_string_get(UiString *s); UIEXPORT void ui_text_set(UiText *s, const char* value); UIEXPORT char* ui_text_get(UiText *s); +UIEXPORT void ui_image_set(UiGeneric *g, void *img); +UIEXPORT void* ui_image_get(UiGeneric *g); UIEXPORT void ui_var_set_int(UiContext *ctx, const char *name, int64_t value); UIEXPORT int64_t ui_var_get_int(UiContext *ctx, const char *name);