shithub: guifs

ref: 7c6a945996a1d5510ff1412320ac7d07a0f82851
dir: /layout.c/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>

#include "guifs.h"

void
layout(GuiElement *g, Rectangle r)
{
	GuiSpec spec = guispecs[g->type];

	g->rect = r;
	spec.layout(g, r);
}

void
layoutnone(GuiElement *g, Rectangle r)
{
	USED(g);
	USED(r);
}

void
layoutcontainer(GuiElement *g, Rectangle r)
{
	USED(g);
	USED(r);

	if(g->nchildren == 0)
		return;

	int margin = 10;

	r = insetrect(r, 10);
	int width = Dx(r) - (margin * (g->nchildren - 1));
	width = width / g->nchildren;
	r.max.x = r.min.x + width;

	for(int i = 0; i < g->nchildren; i++){
		layout(g->children[i], r);
		r = rectaddpt(r, Pt(width+margin, 0));
	}
}