ref: 6ff9ef0c4bef23bfd91f33f0c2f5cab0b88c0307
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_box.h" #include "../n_label.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(); } 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"); 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()) ->MakeRoot() ->Slot( New_Box() ->SizeToContent(1) ->Border(1, red) ->Slot( New_HBox() ->SizeToContent(1) ->Slot( NAssign(NBox, &box1, New_Box()) ->Border(1, green) ->SizeToContent(1) ->OnClick(callclick, nil) ->Slot( New_Label() ->LabelFunc(getlabel) ) ) ->Slot( NAssign(NBox, &box2, New_Box()) ->Border(1, blue) ->SizeToContent(1) ->OnClick(callclick, nil) ->Slot( New_Label() ->Label("DEF") ) ) ) ); eresized(0); for (;;) { e = event(&ev); switch (e) { case Emouse: if (ev.mouse.buttons & 4) exits(nil); if (ev.mouse.buttons & 1) natemouseevent(ev.mouse); break; default: break; } } }