#include <stdio.h>
#include <stdlib.h>
#include <ui/ui.h>
#include <ucx/buffer.h>
#include <ucx/utils.h>
typedef struct {
UiText *text;
} MyDocument;
MyDocument *doc1;
MyDocument *doc2;
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");
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);
}
int main(int argc, char** argv) {
ui_init("app1", argc, argv);
ui_onstartup(application_startup, NULL);
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();
return (EXIT_SUCCESS);
}