summaryrefslogtreecommitdiff
path: root/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/layout.c b/layout.c
new file mode 100644
index 0000000..76df9c7
--- /dev/null
+++ b/layout.c
@@ -0,0 +1,43 @@
+#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));
+ }
+} \ No newline at end of file