| 30 #include <cx/buffer.h> |
30 #include <cx/buffer.h> |
| 31 #include <cx/printf.h> |
31 #include <cx/printf.h> |
| 32 |
32 |
| 33 #include "args.h" |
33 #include "args.h" |
| 34 #include "container.h" |
34 #include "container.h" |
| |
35 #include "widget.h" |
| 35 |
36 |
| 36 cxmutstr ui_button_args_to_string(UiContext *ctx, UiButtonArgs *args) { |
37 cxmutstr ui_button_args_to_string(UiContext *ctx, UiButtonArgs *args) { |
| 37 CxBuffer buf; |
38 CxBuffer buf; |
| 38 cxBufferInit(&buf, NULL, 256, ctx->allocator, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS); |
39 cxBufferInit(&buf, NULL, 256, ctx->allocator, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS); |
| 39 |
40 |
| 56 |
57 |
| 57 |
58 |
| 58 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) { |
59 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) { |
| 59 UiCallbackWidget *widget = cxZalloc(obj->ctx->allocator, sizeof(UiCallbackWidget)); |
60 UiCallbackWidget *widget = cxZalloc(obj->ctx->allocator, sizeof(UiCallbackWidget)); |
| 60 widget->widget.obj = obj->widget->obj; |
61 widget->widget.obj = obj->widget->obj; |
| |
62 widget->widget.type = CX_STR("button"); |
| 61 widget->widget.args = ui_button_args_to_string(obj->ctx, args); |
63 widget->widget.args = ui_button_args_to_string(obj->ctx, args); |
| 62 widget->widget.serialize = (ui_serialize_func)ui_button_serialize; |
64 widget->widget.serialize = (ui_serialize_func)ui_button_serialize; |
| 63 widget->callback = args->onclick; |
65 widget->callback = args->onclick; |
| 64 widget->userdata = args->onclickdata; |
66 widget->userdata = args->onclickdata; |
| 65 ui_reg_widget((UiWidget*)widget); |
67 ui_reg_widget((UiWidget*)widget); |
| 72 |
74 |
| 73 cxmutstr ui_button_serialize(UiCallbackWidget *w) { |
75 cxmutstr ui_button_serialize(UiCallbackWidget *w) { |
| 74 CxBuffer buf; |
76 CxBuffer buf; |
| 75 cxBufferInit(&buf, NULL, 1024, NULL, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS); |
77 cxBufferInit(&buf, NULL, 1024, NULL, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_FREE_CONTENTS); |
| 76 |
78 |
| 77 cxBufferPutString(&buf, "{\"type\":\"button\", \"obj\":\""); |
79 cxBufferPutString(&buf, "{"); |
| 78 cxBufferPutString(&buf, w->widget.obj->id.ptr); |
80 ui_serialize_type_obj_id(&w->widget, &buf); |
| 79 cxBufferPutString(&buf, "\", \"id\":\""); |
81 cxBufferPutString(&buf, ",\"args\":"); |
| 80 cxBufferPutString(&buf, w->widget.id.ptr); |
|
| 81 cxBufferPutString(&buf, "\", \"args\":"); |
|
| 82 cxBufferPutString(&buf, w->widget.args.ptr); |
82 cxBufferPutString(&buf, w->widget.args.ptr); |
| 83 cxBufferPutString(&buf, "}\n"); |
83 cxBufferPutString(&buf, "}\n"); |
| 84 |
84 |
| 85 return cx_mutstrn(buf.space, buf.size); |
85 return cx_mutstrn(buf.space, buf.size); |
| 86 } |
86 } |