--- a/application/main.c Sun Feb 11 15:44:33 2024 +0100 +++ b/application/main.c Sun Feb 11 22:06:23 2024 +0100 @@ -34,7 +34,8 @@ #include <cx/utils.h> typedef struct { - UiText *text; + UiString *str1; + UiString *str2; } MyDocument; MyDocument *doc1; @@ -42,48 +43,31 @@ void action_menu(UiEvent *event, void *userdata) { - printf("action_menu: %s\n", (char*)userdata); + } void action_button(UiEvent *event, void *userdata) { - printf("button test\n"); - MyDocument *doc = event->document; - if(!doc) { - printf("no document\n"); - return; - } - char *text = doc->text->get(doc->text); - printf("text: {\n%s\n}\n", text); } void action_switch(UiEvent *event, void *userdata) { - if(event->document == doc1) { - ui_set_document(event->obj, doc2); - } else { - ui_set_document(event->obj, doc1); - } + } MyDocument* create_doc(void) { MyDocument *doc = ui_document_new(sizeof(MyDocument)); UiContext *docctx = ui_document_context(doc); - doc->text = ui_text_new(docctx, "text"); + doc->str1 = ui_string_new(docctx, "str1"); + doc->str1 = ui_string_new(docctx, "str2"); return doc; } void application_startup(UiEvent *event, void *data) { UiObject *obj = ui_window("Test", NULL); - ui_textarea_nv(obj, "text"); - ui_button(obj, "Test", action_button, NULL); - ui_button(obj, "Switch Document", action_switch, NULL); - doc1 = create_doc(); - doc2 = create_doc(); - ui_attach_document(obj->ctx, doc1); ui_show(obj); } @@ -93,15 +77,7 @@ ui_onstartup(application_startup, NULL); // menu - ui_menu("_File"); - ui_menuitem("_Hello", action_menu, NULL); - ui_submenu("Submenu1"); - ui_submenu("Submenu2"); - ui_menuitem("item2", action_menu, NULL); - ui_submenu_end(); - ui_menuitem("item3", action_menu, NULL); - ui_submenu_end(); - ui_menuitem("item4", action_menu, NULL); + ui_main();