summaryrefslogtreecommitdiff
path: root/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c61
1 files changed, 43 insertions, 18 deletions
diff --git a/layout.c b/layout.c
index 76df9c7..d294234 100644
--- a/layout.c
+++ b/layout.c
@@ -4,40 +4,65 @@
#include "guifs.h"
-void
-layout(GuiElement *g, Rectangle r)
+Rectangle
+subspacing(Rectangle r, Spacing *s)
{
- GuiSpec spec = guispecs[g->type];
-
- g->rect = r;
- spec.layout(g, r);
+ r.min.x += s->left;
+ r.min.y += s->up;
+ r.max.x -= s->right;
+ r.max.y -= s->down;
+ return r;
}
void
-layoutnone(GuiElement *g, Rectangle r)
+layout(GuiElement *g, Rectangle r0)
{
- USED(g);
- USED(r);
+ GuiSpec spec = guispecs[g->type];
+
+ Spacing *margin = getprop(g, Pmargin).spacing;
+ Spacing *border = getprop(g, Pborder).spacing;
+ Spacing *padding = getprop(g, Ppadding).spacing;
+
+ /* Subtract margin to get the outer border rect */
+ Rectangle r1 = subspacing(r0, margin);
+
+ /* Subtract border widths to get the inner border rect */
+ Rectangle r2 = subspacing(r1, border);
+
+ /* Subtract padding to get the content rect */
+ Rectangle r3 = subspacing(r2, padding);
+
+ wlock(&g->lock);
+ g->border = r1;
+ g->rect = r2;
+ wunlock(&g->lock);
+
+ rlock(&g->lock);
+ spec.layout(g, r3);
+ runlock(&g->lock);
}
void
layoutcontainer(GuiElement *g, Rectangle r)
{
- USED(g);
- USED(r);
-
if(g->nchildren == 0)
return;
- int margin = 10;
+ int orientation = getprop(g, Porientation).orientation;
- r = insetrect(r, 10);
- int width = Dx(r) - (margin * (g->nchildren - 1));
- width = width / g->nchildren;
- r.max.x = r.min.x + width;
+ int dx = 0;
+ int dy = 0;
+
+ if(orientation == Horizontal){
+ dx = Dx(r) / g->nchildren;
+ r.max.x = r.min.x + dx;
+ }else if(orientation == Vertical){
+ dy = Dy(r) / g->nchildren;
+ r.max.y = r.min.y + dy;
+ }
for(int i = 0; i < g->nchildren; i++){
layout(g->children[i], r);
- r = rectaddpt(r, Pt(width+margin, 0));
+ r = rectaddpt(r, Pt(dx, dy));
}
} \ No newline at end of file