ref: 69e287559e1faed50092d64659c5bc02f9bf395c
dir: /test/ntest.c/
#include <u.h> #include <libc.h> #include <draw.h> #include <event.h> #include "../nate.h" #include "../n_window.h" #include "../n_hbox.h" #include "../n_vbox.h" #include "../n_box.h" #include "../n_label.h" #include "../n_image.h" char* getlabel(void) { return "ABC"; } NBox *box1; NBox *box2; int callclick(Mouse, Nelem* el, void*) { int id = 0; if (el == box1) id = 1; if (el == box2) id = 2; fprint(2, "click: %s (%d)\n", el->type, id); return 1; } void eresized(int new) { if (new && getwindow(display, Refnone) < 0) sysfatal("getwindow: %r"); nateredraw(1); } void main(int argc, char **argv) { USED(argc, argv); Nelem* mainwindow; Event ev; int e; if (initdraw(nil, nil, "nate test") < 0) sysfatal("initdraw: %r"); /* send 2 output to /srv/ntest */ if (1) { int p[2]; pipe(p); dup(p[0], 2); int fd = create("/srv/ntest", OWRITE|ORCLOSE, 0666); if (fd < 0) sysfatal("create: %r"); fprint(fd, "%d\n", p[1]); close(p[1]); } /* debug nate */ nateborders = 1; //natetracehit = 1; natetracedraw = 1; natedebugfd = 2; einit(Emouse); nateinit(); Image* red = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DRed); Image* green = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DGreen); Image* blue = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DBlue); NAssign(NWindow, &mainwindow, New_Window("window")) ->MakeRoot() ->Slot(NSlot(), New_VBox("outer_vbox") ->Slot(NSlot(), New_HBox("first_hbox") ->Slot(NSlot(), NAssign(NBox, &box1, New_Box("first_box")) ->Border(1, green) ->AutoSize(1) ->Padding(NMargin2(5, 3)) ->OnClick(callclick, nil) ->Slot(NSlot(), New_Label("first_label") ->LabelFunc(getlabel) ->Margin(NMargin2(5, 5)) ) ) ->Slot(NSlot(), NAssign(NBox, &box2, New_Box("second_box")) ->Border(1, blue) ->OnClick(callclick, nil) ->Slot(NSlot(), New_Label("second_label") ->Label("DEF") ->Align(BOTRIGHT) ->Margin(NMargin2(5, 5)) ) ) ->Slot(NSlot(), New_Box("image_box") ->Size(Pt(50, 50)) ->Slot(NSlot(), New_Image("image") ->Image(display->black) ) ) ) ->Slot(NSlot(), New_HBox("second_hbox") ->Slot(NSlot(), New_Label("third_label") ->Label("abc") ) ) ); eresized(0); for (;;) { e = event(&ev); switch (e) { case Emouse: natemouseevent(ev.mouse); break; default: break; } } }