ref: a578dcbab74f736509dbe3e8fc1cefaa9919132c
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"
//#define T_VBOX
//#define T_HBOX
#define T_BOX
//#define T_GRID
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);
#ifdef T_VBOX
NAssign(NWindowAccessors, &mainwindow, New_Window("window"))
->MakeRoot()
->Slot(NSlot(),
New_VBox("vbox")
->Slot(NSlot(),
New_Label("first_label")
->Label("first")
)
->Slot(NSlot(),
New_Label("second_label")
->Label("second")
)
);
#endif
#ifdef T_HBOX
NAssign(NWindowAccessors, &mainwindow, New_Window("window"))
->MakeRoot()
->Slot(NSlot(),
New_HBox("hbox")
->Slot(NSlot(),
New_Label("first_label")
->Label("first")
)
->Slot(NSlot(),
New_Label("second_label")
->Label("second")
)
);
#endif
#ifdef T_GRID
NAssign(NWindowAccessors, &mainwindow, New_Window("window"))
->MakeRoot()
->Slot(NSlot(),
New_VBox("vbox")
->Slot(NSlot(),
New_HBox("hbox1")
->Slot(NSlot(),
New_Label("l1")
->Label("first")
)
->Slot(NSlot(),
New_Label("l2")
->Label("second")
)
)
->Slot(NSlot(),
New_HBox("hbox2")
->Slot(NSlot(),
New_Label("l3")
->Label("third")
)
->Slot(NSlot(),
New_Label("l4")
->Label("fourth")
)
)
);
#endif
#ifdef T_BOX
NAssign(NWindowAccessors, &mainwindow, New_Window("window"))
->MakeRoot()
->Slot(NSlot(),
New_HBox("hbox")
->Slot(NSlot(),
New_Box("fillbox")
->Border(5, green)
->Size(Pt(100, 100))
->Padding(NMargin2(5, 5))
->Slot(NSlot(),
New_Label(nil)
->Label("fill")
->Align(CENTER)
)
)
->Slot(NSlotx(LEFT, 0),
New_Box("nofillbox")
->Border(5, green)
->Size(Pt(100, 100))
->Padding(NMargin2(5, 5))
->Slot(NSlot(),
New_Label(nil)
->Label("nofill")
->Align(CENTER)
)
)
->Slot(NSlotx(LEFT, FILLX),
New_Box("fillxbox")
->Border(5, green)
->Size(Pt(100, 100))
->Padding(NMargin2(5, 5))
->Slot(NSlot(),
New_Label(nil)
->Label("fillx")
->Align(CENTER)
)
)
->Slot(NSlotx(LEFT, FILLY),
New_Box("fillybox")
->Border(5, green)
->Size(Pt(100, 100))
->Padding(NMargin2(5, 5))
->Slot(NSlot(),
New_Label(nil)
->Label("filly")
->Align(CENTER)
)
)
);
#endif
/*
NAssign(NWindow, &mainwindow, New_Window("window"))
->MakeRoot()
->Slot(NSlot(),
New_VBox("outer_vbox")
->Slot(NSlot(),
New_HBox("first_hbox")
->Slot(NSlotx(LEFT, FILLX),
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(NSlotx(LEFT, FILLX),
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(NSlotx(LEFT, FILLX),
New_Box("image_box")
->Size(Pt(50, 50))
->Slot(NSlot(),
New_Image("image")
->Image(display->black)
)
)
)
->Slot(NSlotx(LEFT, FILLX),
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;
}
}
}