Wed, 10 Dec 2025 22:22:55 +0100
implement all window types in the client + small fixes
| client/uiclient.c | file | annotate | diff | comparison | revisions | |
| client/uiclient.h | file | annotate | diff | comparison | revisions | |
| ui/server/window.c | file | annotate | diff | comparison | revisions |
--- a/client/uiclient.c Wed Dec 10 21:22:57 2025 +0100 +++ b/client/uiclient.c Wed Dec 10 22:22:55 2025 +0100 @@ -46,7 +46,10 @@ io = handler; msg_types = cxHashMapCreateSimple(CX_STORE_POINTERS); - cxMapPut(msg_types, "simple_window", msg_simple_window); + cxMapPut(msg_types, "window", msg_window); + cxMapPut(msg_types, "sidebar_window", msg_window); + cxMapPut(msg_types, "splitview_window", msg_window); + cxMapPut(msg_types, "simple_window", msg_window); cxMapPut(msg_types, "show", msg_show); cxMapPut(msg_types, "vbox", msg_vbox); @@ -68,6 +71,21 @@ } } +static UiBool jsonobj_getbool(const CxJsonValue *obj, const char *name, int *error) { + CxJsonValue *value = cxJsonObjGet(obj, name); + if(value->type == CX_JSON_LITERAL) { + if(*error) { + *error = 0; + } + return value->value.literal == CX_JSON_TRUE ? 1 : 0; + } else { + if(error) { + *error = 1; + } + return FALSE; + } +} + /* * UI thread callback */ @@ -114,7 +132,7 @@ return 1; } - return handler(obj, value); + return handler(obj, value, type->value.string); } int client_handle_children(UiObject *parent, const CxJsonValue *value) { @@ -174,8 +192,8 @@ return client_get_mapped_obj(obj_id->value.string); } -int msg_simple_window(UiObject *parent, const CxJsonValue *value) { - cxmutstr obj_id = jsonobj_getstring(value, "obj_id"); +int msg_window(UiObject *parent, const CxJsonValue *value, cxmutstr type) { + cxmutstr obj_id = jsonobj_getstring(value, "obj"); cxmutstr id = jsonobj_getstring(value, "id"); cxmutstr title = jsonobj_getstring(value, "title"); @@ -186,7 +204,22 @@ return 1; } - UiObject *obj = ui_simple_window(title.ptr, NULL); + UiObject *obj; + if(!cx_strcmp(type, "window")) { + obj = ui_window(title.ptr, NULL); + } else if(!cx_strcmp(type, "sidebar_window")) { + obj = ui_sidebar_window(title.ptr, NULL); + } else if(!cx_strcmp(type, "splitview_window")) { + int err; + bool sidebar = jsonobj_getbool(value, "sidebar", &err); + if(err) { + return 1; + } + obj = ui_splitview_window(title.ptr, sidebar); + } else if(!cx_strcmp(type, "simple_window")) { + obj = ui_simple_window(title.ptr, NULL); + } + client_add_obj_mapping(obj, obj_id); if(obj->widget) { @@ -196,7 +229,7 @@ return client_handle_children(obj, value); } -int msg_show(UiObject *parent, const CxJsonValue *value) { +int msg_show(UiObject *parent, const CxJsonValue *value, cxmutstr type) { UiObject *obj = client_get_mapped_obj(jsonobj_getstring(value, "obj")); if(!obj) { return 1; @@ -226,19 +259,19 @@ return 0; } -int msg_vbox(UiObject *parent, const CxJsonValue *value) { +int msg_vbox(UiObject *parent, const CxJsonValue *value, cxmutstr type) { return msg_container(parent, value, ui_vbox_create); } -int msg_hbox(UiObject *parent, const CxJsonValue *value) { +int msg_hbox(UiObject *parent, const CxJsonValue *value, cxmutstr type) { return msg_container(parent, value, ui_hbox_create); } -int msg_grid(UiObject *parent, const CxJsonValue *value) { +int msg_grid(UiObject *parent, const CxJsonValue *value, cxmutstr type) { return msg_container(parent, value, ui_grid_create); } -int msg_end(UiObject *parent, const CxJsonValue *value) { +int msg_end(UiObject *parent, const CxJsonValue *value, cxmutstr type) { UiObject *obj = get_msg_obj(parent, value); if(!obj) { return 1; @@ -247,7 +280,7 @@ return 0; } -int msg_button(UiObject *parent, const CxJsonValue *value) { +int msg_button(UiObject *parent, const CxJsonValue *value, cxmutstr type) { CxJsonValue *args_value = cxJsonObjGet(value, "args"); cxmutstr id = jsonobj_getstring(value, "id"); if(!id.ptr) { @@ -266,7 +299,7 @@ return 0; } -int msg_togglebutton(UiObject *parent, const CxJsonValue *value) { +int msg_togglebutton(UiObject *parent, const CxJsonValue *value, cxmutstr type) { CxJsonValue *args_value = cxJsonObjGet(value, "args"); cxmutstr id = jsonobj_getstring(value, "id"); if(!id.ptr) {
--- a/client/uiclient.h Wed Dec 10 21:22:57 2025 +0100 +++ b/client/uiclient.h Wed Dec 10 22:22:55 2025 +0100 @@ -44,7 +44,7 @@ CxMap *widgets; } WindowData; -typedef int (*json_msg_handler)(UiObject *parent, const CxJsonValue *value); +typedef int (*json_msg_handler)(UiObject *parent, const CxJsonValue *value, cxmutstr type); void client_init(UiMessageHandler *handler); @@ -60,18 +60,18 @@ UIWIDGET client_get_widget(UiObject *obj, cxmutstr id); -int msg_simple_window(UiObject *parent, const CxJsonValue *value); -int msg_show(UiObject *parent, const CxJsonValue *value); +int msg_window(UiObject *parent, const CxJsonValue *value, cxmutstr type); +int msg_show(UiObject *parent, const CxJsonValue *value, cxmutstr type); -int msg_vbox(UiObject *parent, const CxJsonValue *value); -int msg_hbox(UiObject *parent, const CxJsonValue *value); -int msg_grid(UiObject *parent, const CxJsonValue *value); +int msg_vbox(UiObject *parent, const CxJsonValue *value, cxmutstr type); +int msg_hbox(UiObject *parent, const CxJsonValue *value, cxmutstr type); +int msg_grid(UiObject *parent, const CxJsonValue *value, cxmutstr type); -int msg_end(UiObject *parent, const CxJsonValue *value); +int msg_end(UiObject *parent, const CxJsonValue *value, cxmutstr type); -int msg_button(UiObject *parent, const CxJsonValue *value); +int msg_button(UiObject *parent, const CxJsonValue *value, cxmutstr type); -int msg_togglebutton(UiObject *parent, const CxJsonValue *value); +int msg_togglebutton(UiObject *parent, const CxJsonValue *value, cxmutstr type);
--- a/ui/server/window.c Wed Dec 10 21:22:57 2025 +0100 +++ b/ui/server/window.c Wed Dec 10 22:22:55 2025 +0100 @@ -80,16 +80,16 @@ cxmutstr obj_id = w->widget.obj->id; cxmutstr id = w->widget.id; - cxBufferPutString(&buf, " obj_id=\""); + cxBufferPutString(&buf, ", \"obj\":\""); cxBufferWrite(obj_id.ptr, 1, obj_id.length, &buf); - cxBufferPutString(&buf, "\""); + cxBufferPutString(&buf, "\","); - cxBufferPutString(&buf, " id=\""); + cxBufferPutString(&buf, " \"id\":\""); cxBufferWrite(id.ptr, 1, id.length, &buf); - cxBufferPutString(&buf, "\""); + cxBufferPutString(&buf, "\", "); if(w->title.ptr) { - cxBufferPutString(&buf, " title=\""); + cxBufferPutString(&buf, " \"title\":\""); cxBufferWrite(w->title.ptr, 1, w->title.length, &buf); cxBufferPutString(&buf, "\""); }