Updating layout to work for horizontal too
This commit is contained in:
parent
6656b90717
commit
790258b386
1 changed files with 28 additions and 23 deletions
|
|
@ -381,47 +381,52 @@ measureText = config \
|
||||||
};
|
};
|
||||||
|
|
||||||
# new CG layout
|
# new CG layout
|
||||||
LayoutChild = Fixed Int (Int\ Int \ UI) | Flex Int (Int \ Int \ UI);
|
|
||||||
|
|
||||||
layout = constraints children \
|
LayoutChild = Fixed Int (Int\ Int \ UI) | Flex Int (Int \ Int \ UI);
|
||||||
|
Alignment = Start | Center | End;
|
||||||
|
Direction = Col | Row;
|
||||||
|
|
||||||
|
layoutDir = dir constraints children \
|
||||||
|
mainSize = dir | Col \ constraints.h | Row \ constraints.w;
|
||||||
|
crossSize = dir | Col \ constraints.w | Row \ constraints.h;
|
||||||
|
|
||||||
# Pass 1: sum fixed heights, total flex weight
|
# Pass 1: sum fixed heights, total flex weight
|
||||||
info = fold (acc child \ child
|
info = fold (acc child \ child
|
||||||
| Fixed h _ \ acc.{ fixedH = acc.fixedH + h }
|
| Fixed s _ \ acc.{ fixedMain = acc.fixedMain + s }
|
||||||
| Flex n _ \ acc.{ totalFlex = acc.totalFlex + n }
|
| Flex n _ \ acc.{ totalFlex = acc.totalFlex + n }
|
||||||
) { fixedH = 0, totalFlex = 0 } children;
|
) { fixedMain = 0, totalFlex = 0 } children;
|
||||||
|
|
||||||
remainingH = constraints.h - info.fixedH;
|
remaining = mainSize - info.fixedMain;
|
||||||
|
|
||||||
# Pass 2
|
# Pass 2
|
||||||
fold (acc child \
|
fold (acc child \
|
||||||
allocated = (child
|
allocated = (child
|
||||||
| Fixed h view \ { h = h, view = view }
|
| Fixed s view \ { s = s, view = view }
|
||||||
| Flex n view \ { h = remainingH * n / info.totalFlex, view = view });
|
| Flex n view \ { s = remaining * n / info.totalFlex, view = view });
|
||||||
|
|
||||||
rendered = ui.positioned {
|
childW = dir | Col \ crossSize | Row \ allocated.s;
|
||||||
x = 0,
|
childH = dir | Col \ allocated.s | Row \ crossSize;
|
||||||
y = acc.y,
|
posX = dir | Col \ 0 | Row \ acc.pos;
|
||||||
child = allocated.view constraints.w allocated.h
|
posY = dir | Col \ acc.pos | Row \ 0;
|
||||||
};
|
|
||||||
|
|
||||||
acc.{ y = acc.y + allocated.h, children = [...acc.children, rendered] }
|
rendered = ui.positioned {
|
||||||
) { y = 0, children = [] } children
|
x = posX, y = posY,
|
||||||
|
child = allocated.view childW childH
|
||||||
|
};
|
||||||
|
|
||||||
|
acc.{ pos = acc.pos + allocated.s, children = [...acc.children, rendered] }
|
||||||
|
) { pos = 0, children = [] } children
|
||||||
~ (r \ r.children)
|
~ (r \ r.children)
|
||||||
~ (c \ ui.stack { children = c });
|
~ (c \ ui.stack { children = c });
|
||||||
|
|
||||||
|
col = layoutDir Col;
|
||||||
|
rol = layoutDir Row;
|
||||||
|
|
||||||
testApp = name \
|
testApp = name \
|
||||||
{ view = ctx \
|
{ view = ctx \
|
||||||
# ui.rect { w = 10, h = 10 },
|
col { w = ctx.w, h = ctx.h } [
|
||||||
layout { w = ctx.w, h = ctx.h } [
|
|
||||||
Fixed 40 (w h \ box { w = w, h = h, color = "red", child = text "Header" }),
|
Fixed 40 (w h \ box { w = w, h = h, color = "red", child = text "Header" }),
|
||||||
Flex 1 (w h \ box { w = w, h = h, color = "#1a1a2e", child = text "Main content" }),
|
Flex 1 (w h \ box { w = w, h = h, color = "#1a1a2e", child = text "Main content" }),
|
||||||
Fixed 30 (w h \ box { w = w, h = h, color = "blue", child = text "Footer" }),
|
Fixed 30 (w h \ box { w = w, h = h, color = "blue", child = text "Footer" }),
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
testApp2 = ctx \
|
|
||||||
layout { w = ctx.w, h = ctx.h } [
|
|
||||||
Fixed 40 (w h \ box { w = w, h = h, color = "red", child = text "Header" }),
|
|
||||||
Flex 1 (w h \ box { w = w, h = h, color = "#1a1a2e", child = text "Main content" }),
|
|
||||||
Fixed 30 (w h \ box { w = w, h = h, color = "blue", child = text "Footer" }),
|
|
||||||
];
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue