application/main.c

changeset 146
dd0ae1c62a72
parent 145
853685152c1d
child 147
2e384acc89a6
equal deleted inserted replaced
145:853685152c1d 146:dd0ae1c62a72
39 UiString *t2; 39 UiString *t2;
40 UiString *t3; 40 UiString *t3;
41 UiInteger *i; 41 UiInteger *i;
42 UiDouble *d; 42 UiDouble *d;
43 UiRange *r; 43 UiRange *r;
44 UiList *list;
44 } Document; 45 } Document;
46
47 typedef struct Entry {
48 char *name;
49 char *desc;
50 } Entry;
45 51
46 Document *d1; 52 Document *d1;
47 Document *d2; 53 Document *d2;
48 int n = 1; 54 int n = 1;
49 55
50 Document* create_doc(); 56 UiImage *img;
57
58 Document* create_doc(char *str);
51 59
52 Document* next_doc(void) { 60 Document* next_doc(void) {
53 Document *doc = d1; 61 Document *doc = d1;
54 if(n == 1) { 62 if(n == 1) {
55 doc = d2; 63 doc = d2;
72 //printf("i: %d\n", i); 80 //printf("i: %d\n", i);
73 81
74 fflush(stdout); 82 fflush(stdout);
75 } 83 }
76 84
77 Document* create_doc() { 85 Document* create_doc(char *str) {
78 Document *doc = ui_document_new(sizeof(Document)); 86 Document *doc = ui_document_new(sizeof(Document));
79 UiContext *ctx = ui_document_context(doc); 87 UiContext *ctx = ui_document_context(doc);
80 88
81 doc->text = ui_text_new(ctx, "text"); 89 doc->text = ui_text_new(ctx, "text");
82 doc->t1 = ui_string_new(ctx, "t1"); 90 doc->t1 = ui_string_new(ctx, "t1");
84 doc->t3 = ui_string_new(ctx, "t3"); 92 doc->t3 = ui_string_new(ctx, "t3");
85 93
86 doc->i = ui_int_new(ctx, "int"); 94 doc->i = ui_int_new(ctx, "int");
87 doc->d = ui_double_new(ctx, "d"); 95 doc->d = ui_double_new(ctx, "d");
88 doc->r = ui_range_new(ctx, "r"); 96 doc->r = ui_range_new(ctx, "r");
97
98 doc->list = ui_list_new(ctx, "list");
99 printf("doc list: %d\n", doc->list);
100 Entry *e1 = malloc(sizeof(Entry));
101 e1->name = "test";
102 e1->desc = "test file";
103 Entry *e2 = malloc(sizeof(Entry));
104 e2->name = str;
105 e2->desc = "important document";
106 ui_list_append(doc->list, e1);
107 ui_list_append(doc->list, e2);
108
89 return doc; 109 return doc;
110 }
111
112 void* model_get(Entry *e, int col) {
113 if(col == 0) {
114 return img;
115 } else if(col == 1) {
116 return e->name;
117 } else if(col == 2) {
118 return e->desc;
119 }
120 return NULL;
90 } 121 }
91 122
92 void action_newdoc(UiEvent *event, void *data) { 123 void action_newdoc(UiEvent *event, void *data) {
93 printf("new doc\n"); 124 printf("new doc\n");
94 125
105 UiDouble *d = event->eventdata; 136 UiDouble *d = event->eventdata;
106 printf("d: %f\n", (float)d->get(d)); 137 printf("d: %f\n", (float)d->get(d));
107 } 138 }
108 139
109 void application_startup(UiEvent *event, void *data) { 140 void application_startup(UiEvent *event, void *data) {
141 UiIcon *icon = ui_icon("folder", 16);
142 img = ui_icon_image(icon);
143 if(!img) {
144 fprintf(stderr, "Cannot load folder icon\n");
145 }
146
110 //Document *doc = create_doc(); 147 //Document *doc = create_doc();
111 d1 = create_doc(); 148 d1 = create_doc("doc1");
112 d2 = create_doc(); 149 d2 = create_doc("doc2");
113 150
114 UiObject *obj = ui_window("Test", NULL); 151 UiObject *obj = ui_window("Test", NULL);
115 ui_set_document(obj, d1); 152 ui_set_document(obj, d1);
116 153
117 //ui_textarea_nv(obj, "text"); 154 //ui_textarea_nv(obj, "text");
118 ui_radiobutton_nv(obj, "1", "int"); 155 ui_radiobutton_nv(obj, "1", "int");
119 ui_radiobutton_nv(obj, "2", "int"); 156 ui_radiobutton_nv(obj, "2", "int");
120 ui_radiobutton_nv(obj, "3", "int"); 157 ui_radiobutton_nv(obj, "3", "int");
121 158
122 ui_textfield_nv(obj, "t1"); 159 ui_textfield_nv(obj, "t1");
123 ui_textarea_nv(obj, "text"); 160 //ui_textarea_nv(obj, "text");
124 d1->t1->observers = ui_add_observer(d1->t1->observers, observ, "t1"); 161 d1->t1->observers = ui_add_observer(d1->t1->observers, observ, "t1");
125 d1->text->observers = ui_add_observer(d1->text->observers, observ, "text"); 162 //d1->text->observers = ui_add_observer(d1->text->observers, observ, "text");
163
164 UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "name", UI_STRING, "desc", -1);
165 model->getvalue = (ui_getvaluefunc)model_get;
166 UiListCallbacks cb = {NULL, NULL, NULL};
167 ui_table_nv(obj, "list", model, cb);
126 168
127 //ui_spinner_setrange(ui_spinnerf_nv(obj, 1, 0, "d"), 0, 1000); 169 //ui_spinner_setrange(ui_spinnerf_nv(obj, 1, 0, "d"), 0, 1000);
128 ui_spinnerr_nv(obj, "r"); 170 ui_spinnerr_nv(obj, "r");
129 d1->r->setrange(d1->r, 0, 10); 171 d1->r->setrange(d1->r, 0, 10);
130 d1->r->setextent(d1->r, 1); 172 d1->r->setextent(d1->r, 1);

mercurial