make/vs/testapp/main.c

branch
newapi
changeset 187
24ce2c326d85
parent 186
5db4979bf482
child 188
fbbae6738252
equal deleted inserted replaced
186:5db4979bf482 187:24ce2c326d85
32 #include <stdlib.h> 32 #include <stdlib.h>
33 #include <stdbool.h> 33 #include <stdbool.h>
34 34
35 #include <ui/ui.h> 35 #include <ui/ui.h>
36 36
37 typedef struct WindowData {
38 UiInteger* check;
39 UiInteger* toggle;
40 } WindowData;
37 41
38 void action1(UiEvent* event, void* data) { 42 void action1(UiEvent* event, void* data) {
39 char* action = data; 43 char* action = data;
40 printf("data: %s!\n", data); 44
45 WindowData* wdata = event->window;
46 int64_t is_checked = wdata->check->get(wdata->check);
47
48 printf("data: %s %d\n", data, is_checked);
49 }
50
51 void action_set_checkbox(UiEvent* event, void* data) {
52 char* action = data;
53
54 WindowData* wdata = event->window;
55 wdata->check->set(wdata->check, 1);
41 } 56 }
42 57
43 void application_startup(UiEvent* event, void* data) { 58 void application_startup(UiEvent* event, void* data) {
44 UiObject* obj = ui_window("Test", NULL); 59 UiObject* obj = ui_window("Test", NULL);
60 WindowData* wdata = ui_malloc(obj->ctx, sizeof(WindowData));
61 obj->window = wdata;
62 wdata->check = ui_int_new(obj->ctx, "check");
63 wdata->toggle = ui_int_new(obj->ctx, "toggle");
45 64
46 UI_GRID_SP(obj, 10, 5, 20) { 65 UI_GRID_SP(obj, 10, 5, 20) {
47 ui_button(obj, .label="Button1", .onclick=action1, .onclickdata="action1"); 66 ui_button(obj, .label="Button1", .onclick=action1, .onclickdata="action1");
48 ui_button(obj, .label="Button2", .onclick=action1, .onclickdata="action2"); 67 ui_button(obj, .label="Button2", .onclick=action1, .onclickdata="action2");
49 ui_button(obj, .label="Button3", .onclick=action1, .onclickdata="action3", .hexpand=true); 68 ui_button(obj, .label="Button3", .onclick=action1, .onclickdata="action3", .hexpand=true);
51 70
52 ui_button(obj, .label="Button4", .onclick=action1, .onclickdata="action4"); 71 ui_button(obj, .label="Button4", .onclick=action1, .onclickdata="action4");
53 ui_button(obj, .label="Button5", .onclick=action1, .onclickdata="action5", .colspan=2); 72 ui_button(obj, .label="Button5", .onclick=action1, .onclickdata="action5", .colspan=2);
54 ui_newline(obj); 73 ui_newline(obj);
55 74
56 ui_button(obj, .label="Very Long Button Label Text ____________ Test", .onclick=action1, .onclickdata="test"); 75 ui_button(obj, .label="Very Long Button Label Text ____________ Test", .onclick=action_set_checkbox);
76 ui_newline(obj);
77
78 ui_checkbox(obj, .label = "Option 1", .value = wdata->check);
79 ui_togglebutton(obj, .label = "Option 2", .value = wdata->toggle);
57 } 80 }
58 81
59 ui_show(obj); 82 ui_show(obj);
60 } 83 }
61 84

mercurial