ref: 7d7806db6cd48b8ebd565f636eebc59939e72c53
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 = r.min; 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_sizetocontent, int, sizetocontent); NVBox* New_VBox(char *name) { NVBox *b = MakeNelem(NVBox, NVBox_Type, &Nvboxfunctions, name, -1); b->Slot = vbox_slot; b->SizeToContent = vbox_sizetocontent; linit(&b->children); b->sizetocontent = 0; nc_push(b); return b; }