application/main.c

changeset 140
c03c338a7dcf
parent 139
dbde25a5bc53
child 142
46448d38885c
--- a/application/main.c	Tue Jan 24 18:46:47 2017 +0100
+++ b/application/main.c	Fri Nov 10 17:17:14 2017 +0100
@@ -33,49 +33,79 @@
 #include <ucx/buffer.h>
 #include <ucx/utils.h>
 
+typedef struct Document {
+    UiText *text;
+    UiString *t1;
+    UiString *t2;
+    UiString *t3;
+    UiInteger *i;
+} Document;
+
+Document *d1;
+Document *d2;
+int n = 1;
+
+Document* create_doc();
+
+Document* next_doc(void) {
+    Document *doc = d1;
+    if(n == 1) {
+        doc = d2;
+        printf("doc2\n");
+    } else {
+        printf("doc1\n");
+    }
+    n++;
+    n = n%2;
+    return doc;
+}
+
 void action_menu(UiEvent *event, void *data) {
     printf("action_menu\n");
-    fflush(stdout);
-}
-
-void action_button(UiEvent *event, void *data) {
-    printf("action_button\n");
+    
+    Document *doc = event->document;
+    char *s = doc->text->get(doc->text);
+    printf("text: {\n%s\n}\n", s);
+    //int i = doc->i->get(doc->i);
+    //printf("i: %d\n", i);
+    
     fflush(stdout);
 }
 
-void draw(UiEvent *event, UiGraphics *g, void *data) {
-    printf("draw: %d, %d\n", g->width, g->height);
-    fflush(stdout);
+Document* create_doc() {
+    Document *doc = ui_document_new(sizeof(Document));
+    UiContext *ctx = ui_document_context(doc);
     
-    ui_graphics_color(g, 200, 240, 240);
-    ui_draw_rect(g, 0, 0, 50, g->height, TRUE);
+    doc->text = ui_text_new(ctx, "text");
+    //doc->t1 = ui_string_new(ctx, "t1");
+    //doc->t2 = ui_string_new(ctx, "t2");
+    //doc->t3 = ui_string_new(ctx, "t3");
     
-    ui_graphics_color(g, 150, 150, 200);
-    ui_draw_rect(g, 50, 0, g->width - 50, g->height, TRUE);
+    //doc->i = ui_int_new(ctx, "int");
+    return doc;
+}
+
+void action_newdoc(UiEvent *event, void *data) {
+    printf("new doc\n");
     
-    ui_graphics_color(g, 0, 0, 0);
-    ui_draw_line(g, 0, 10, 100, 10);
-    ui_draw_line(g, 0, 10, 10, 50);
-    ui_draw_line(g, 10, 50, 50, 50);
-    ui_draw_line(g, 50, 50, 100, 100);
-    
-    ui_draw_rect(g, 15, 15, 80, 80, FALSE);
+    Document *newd = next_doc();
+    printf("newd: %d\n", (int)(intptr_t)newd);
+    ui_set_document(event->obj, newd);
 }
 
 void application_startup(UiEvent *event, void *data) {
-    UiObject *obj = ui_window("Test", NULL);
-    
-    ui_tabview(obj);
+    //Document *doc = create_doc();
+    d1 = create_doc();
+    d2 = create_doc();
     
-    ui_tab(obj, "Tab 1");
-    ui_textarea(obj, NULL);
-    ui_end(obj);
+    UiObject *obj = ui_window("Test", NULL);
+    ui_set_document(obj, d1);
     
-    ui_tab(obj, "Tab 2");
-    ui_textarea(obj, NULL);
-    ui_end(obj);
+    ui_textarea_nv(obj, "text");
+    
     
-    ui_end(obj);
+    
+    ui_button(obj, "Switch Document", action_newdoc, NULL);
     
     ui_show(obj);
 }
@@ -94,22 +124,7 @@
     ui_menuitem("item3", action_menu, NULL);
     ui_submenu_end();
     ui_menuitem("item4", action_menu, NULL);
-    
-    // toolbar
-    ui_toolitem("button1", "Test1", action_button, NULL);
-    ui_toolitem("button2", "Test2", action_button, NULL);
-    ui_toolitem("button3", "Test3", action_button, NULL);
-    ui_toolitem("button4", "Test4", action_button, NULL);
-    ui_toolitem("button5", "Test5", action_button, NULL);
-    ui_toolitem("button6", "Test6", action_button, NULL);
-    ui_toolitem("button7", "Test7", action_button, NULL);
-    ui_toolbar_add_default("button1");
-    ui_toolbar_add_default("button2");
-    ui_toolbar_add_default("button3");
-    ui_toolbar_add_default("button4");
-    ui_toolbar_add_default("button5");
-    ui_toolbar_add_default("button6");
-    ui_toolbar_add_default("button7");
+
     
     ui_main();
     

mercurial