ref: 1890aeca379976e46deabb0ce844aefc8be1a2c5
dir: /n_vbox.c/
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>
#include "nate_construct.h"
#include "n_vbox.h"
#define N_TYPE NVBox_Type
char* NVBox_Type = "NVBox";
typedef struct csizep csizep;
struct csizep {
Rectangle crect;
Rectangle frect;
Image *screen;
};
static void
vbox_childsize(Nelem* nelem, int, void *aux)
{
csizep *p = (csizep*)aux;
Rectangle r = ncallcalcsize(nelem, p->screen, p->crect);
combinerect(&p->frect, r);
p->crect.min.y = r.max.y;
}
static Rectangle
vbox_calcsize(Nelem* nelem, Image* img, Rectangle r)
{
csizep params;
NVBox* b = (NVBox*)nelem;
GUARD(b);
params.crect = r;
params.screen = img;
params.frect.min = r.min;
params.frect.max.x = b->autowidth ? r.min.x : r.max.x;
params.frect.max.y = r.min.y;
lforeach(&b->children, vbox_childsize, ¶ms);
b->r = params.frect;
return b->r;
}
static void
vbox_childdraw(Nelem* elem, int, void *aux)
{
ncalldraw(elem, (Image*)aux);
}
static void
vbox_draw(Nelem* nelem, Image* img)
{
NVBox* b = (NVBox*)nelem;
GUARD(b);
lforeach(&b->children, vbox_childdraw, img);
}
static Nelemfunctions Nvboxfunctions = {
.calcsize = vbox_calcsize,
.draw = vbox_draw,
};
DEF_SLOTFUNC(NVBox, vbox_slot);
DEF_ACCESSOR_OneParam(NVBox, vbox_autowidth, int, autowidth);
NVBox*
New_VBox(char *name)
{
NVBox *b = MakeNelem(NVBox, NVBox_Type, &Nvboxfunctions, name, -1);
b->Slot = vbox_slot;
b->AutoWidth = vbox_autowidth;
linit(&b->children);
b->autowidth = 0;
nc_push(b);
return b;
}