summaryrefslogtreecommitdiff
path: root/layout.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 00:04:31 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 00:04:31 +0000
commit7c6a945996a1d5510ff1412320ac7d07a0f82851 (patch)
treef77259f26b5c33307ba8ebc670951ed0acce1b00 /layout.c
parentb5a96b97ee2f3fd30e5935d2b3c2c6e0d96c4640 (diff)
Start working on it
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