Sun, 13 Oct 2024 19:37:00 +0200
add UiGeneric var type
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/common/context.h | file | annotate | diff | comparison | revisions | |
ui/common/types.c | file | annotate | diff | comparison | revisions | |
ui/common/types.h | file | annotate | diff | comparison | revisions | |
ui/ui/icons.h | file | annotate | diff | comparison | revisions | |
ui/ui/image.h | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/ui/common/context.c Sun Oct 13 16:05:06 2024 +0200 +++ b/ui/common/context.c Sun Oct 13 19:37:00 2024 +0200 @@ -243,6 +243,9 @@ val = ui_range_new(ctx, NULL); break; } + case UI_VAR_GENERIC: { + val = ui_generic_new(ctx, NULL); + } } return val; } @@ -343,6 +346,14 @@ t->set(t, t->value); break; } + case UI_VAR_GENERIC: { + UiGeneric *f = fromvalue; + UiGeneric *t = to->value; + if(!f->obj) break; + uic_generic_copy(f, t); + t->set(t, t->value, t->type); + break; + } } } @@ -355,6 +366,7 @@ case UI_VAR_TEXT: uic_text_save(var->value); break; case UI_VAR_LIST: break; case UI_VAR_RANGE: uic_range_save(var->value); break; + case UI_VAR_GENERIC: uic_generic_save(var->value); break; } } @@ -367,6 +379,7 @@ case UI_VAR_TEXT: uic_text_unbind(var->value); break; case UI_VAR_LIST: uic_list_unbind(var->value); break; case UI_VAR_RANGE: uic_range_unbind(var->value); break; + case UI_VAR_GENERIC: uic_generic_unbind(var->value); break; } }
--- a/ui/common/context.h Sun Oct 13 16:05:06 2024 +0200 +++ b/ui/common/context.h Sun Oct 13 19:37:00 2024 +0200 @@ -54,7 +54,8 @@ UI_VAR_STRING, UI_VAR_TEXT, UI_VAR_LIST, - UI_VAR_RANGE + UI_VAR_RANGE, + UI_VAR_GENERIC }; struct UiContext {
--- a/ui/common/types.c Sun Oct 13 16:05:06 2024 +0200 +++ b/ui/common/types.c Sun Oct 13 19:37:00 2024 +0200 @@ -281,6 +281,15 @@ return r; } +UIEXPORT UiGeneric* ui_generic_new(UiContext *ctx, char *name) { + UiGeneric *g = ui_malloc(ctx, sizeof(UiGeneric)); + memset(g, 0, sizeof(UiGeneric)); + if(name) { + uic_reg_var(ctx, name, UI_VAR_GENERIC, g); + } + return g; +} + void ui_int_set(UiInteger* i, int64_t value) { if (i && i->set) { @@ -389,6 +398,12 @@ to->obj = from->obj; } +void uic_generic_copy(UiGeneric *from, UiGeneric *to) { + to->get = from->get; + to->get_type = from->get_type; + to->set = from->set; + to->obj = from->obj; +} void uic_int_save(UiInteger *i) { if(!i->obj) return; @@ -416,6 +431,11 @@ r->get(r); } +void uic_generic_save(UiGeneric *g) { + if(!g->obj) return; + g->get(g); +} + void uic_int_unbind(UiInteger *i) { i->get = NULL; @@ -462,6 +482,13 @@ l->obj = NULL; } +void uic_generic_unbind(UiGeneric *g) { + g->get = NULL; + g->get_type = NULL; + g->set = NULL; + g->obj = NULL; +} + UIEXPORT UiListSelection ui_list_getselection(UiList *list) { if (list->getselection) {
--- a/ui/common/types.h Sun Oct 13 16:05:06 2024 +0200 +++ b/ui/common/types.h Sun Oct 13 19:37:00 2024 +0200 @@ -42,12 +42,14 @@ void uic_text_copy(UiText *from, UiText *to); void uic_range_copy(UiRange *from, UiRange *to); void uic_list_copy(UiList *from, UiList *to); +void uic_generic_copy(UiGeneric *from, UiGeneric *to); void uic_int_save(UiInteger *i); void uic_double_save(UiDouble *d); void uic_string_save(UiString *s); void uic_text_save(UiText *t); void uic_range_save(UiRange *r); +void uic_generic_save(UiGeneric *g); void uic_int_unbind(UiInteger *i); void uic_double_unbind(UiDouble *d); @@ -55,6 +57,7 @@ void uic_text_unbind(UiText *t); void uic_range_unbind(UiRange *r); void uic_list_unbind(UiList *l); +void uic_generic_unbind(UiGeneric *g); #ifdef __cplusplus }
--- a/ui/ui/icons.h Sun Oct 13 16:05:06 2024 +0200 +++ b/ui/ui/icons.h Sun Oct 13 19:37:00 2024 +0200 @@ -70,6 +70,15 @@ #define UI_ICON_GO_FORWARD "Forward" #endif /* UI_WINUI */ + + +UIEXPORT UiIcon* ui_icon(const char* name, size_t size); +UIEXPORT UiIcon* ui_icon_unscaled(const char *name, int size); +UIEXPORT UiIcon* ui_imageicon(const char* file); +UIEXPORT void ui_icon_free(UiIcon* icon); + +UIEXPORT UiIcon* ui_foldericon(size_t size); +UIEXPORT UiIcon* ui_fileicon(size_t size); #ifdef __cplusplus
--- a/ui/ui/image.h Sun Oct 13 16:05:06 2024 +0200 +++ b/ui/ui/image.h Sun Oct 13 19:37:00 2024 +0200 @@ -35,24 +35,22 @@ extern "C" { #endif - /* -UIEXPORT UiIcon* ui_icon(const char* name, size_t size); -UIEXPORT UiIcon* ui_imageicon(const char* file); -UIEXPORT void ui_icon_free(UiIcon* icon); -*/ +typedef struct UiImageViewerArgs { + UiTri fill; + UiBool hexpand; + UiBool vexpand; + int colspan; + int rowspan; + const char *name; + const char *style_class; -/* -UiIcon* ui_icon(const char *name, int size); -UiIcon* ui_icon_unscaled(const char *name, int size); -void ui_free_icon(UiIcon *icon); - -UiImage* ui_icon_image(UiIcon *icon); -UiImage* ui_image(const char *filename); -UiImage* ui_named_image(const char *filename, const char *name); -UiImage* ui_load_image_from_path(const char *path, const char *name); -void ui_free_image(UiImage *img); -*/ - + UiBool scrollarea; + +} UiImageViewerArgs; + +#define ui_imageviewer(obj, ...) ui_imageviewer_create(obj, (UiImageViewerArgs){ __VA_ARGS__ } ) + +UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args); #ifdef __cplusplus }
--- a/ui/ui/toolkit.h Sun Oct 13 16:05:06 2024 +0200 +++ b/ui/ui/toolkit.h Sun Oct 13 19:37:00 2024 +0200 @@ -163,6 +163,7 @@ typedef struct UiText UiText; typedef struct UiList UiList; typedef struct UiRange UiRange; +typedef struct UiGeneric UiGeneric; typedef struct UiStr UiStr; @@ -324,6 +325,17 @@ // TODO: replacefunc, ... UiObserver *observers; }; + +struct UiGeneric { + void* (*get)(UiGeneric*); + const char* (*get_type)(UiGeneric*); + void (*set)(UiGeneric*, void *, const char *type); + void *obj; + + void *value; + const char *type; + UiObserver *observers; +}; /* * abstract list @@ -447,6 +459,7 @@ UIEXPORT UiString* ui_string_new(UiContext *ctx, char *name); UIEXPORT UiText* ui_text_new(UiContext *ctx, char *name); UIEXPORT UiRange* ui_range_new(UiContext *ctx, char *name); +UIEXPORT UiGeneric* ui_generic_new(UiContext *ctx, char *name); #define ui_get(v) _Generic(v, \ UiInteger*: ui_int_get, \ @@ -509,14 +522,6 @@ UIEXPORT void ui_listselection_free(UiListSelection selection); -UIEXPORT UiIcon* ui_icon(const char* name, size_t size); -UIEXPORT UiIcon* ui_icon_unscaled(const char *name, int size); -UIEXPORT UiIcon* ui_imageicon(const char* file); -UIEXPORT void ui_icon_free(UiIcon* icon); - -UIEXPORT UiIcon* ui_foldericon(size_t size); -UIEXPORT UiIcon* ui_fileicon(size_t size); - UIEXPORT UiStr ui_str(char *cstr); UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v));