Views now take a ctx. OS can call them directly

This commit is contained in:
Dustin Swan 2026-04-08 19:18:45 -06:00
parent de515f35e9
commit b04be8ccab
No known key found for this signature in database
GPG key ID: 30D46587E2100467
2 changed files with 15 additions and 34 deletions

View file

@ -28,7 +28,7 @@ layoutDir : Direction \ { w : Int, h : Int } \ List LayoutChild \ { ui : UI, w :
posY = dir posY = dir
| Col \ acc.pos | Col \ acc.pos
| Row \ 0; | Row \ 0;
rendered = ui.positioned { x = posX, y = posY, child = allocated.view childW childH }; rendered = ui.positioned { x = posX, y = posY, child = allocated.view { w = childW, h = childH } };
acc.{ pos = acc.pos + allocated.s, children = [...acc.children, rendered] }) { pos = 0, children = [] } children; acc.{ pos = acc.pos + allocated.s, children = [...acc.children, rendered] }) { pos = 0, children = [] } children;
{ {
ui = ui.stack { children = result.children }, ui = ui.stack { children = result.children },
@ -55,34 +55,18 @@ align = hAlign vAlign w h child \
h = h h = h
}; };
tableView = list \ w h \ tableView = list \ ctx \
w = ctx.w;
h = ctx.h;
firstRow = unwrapOr "{}" (nth 0 list); firstRow = unwrapOr "{}" (nth 0 list);
columnNames = keys firstRow; columnNames = keys firstRow;
colW = w / (len columnNames); colW = w / (len columnNames);
rowH = 24; rowH = 24;
rowFromRecord = r \ (row { w = w, h = rowH } (map (cn \
rowFromRecord = r \
(row { w = w, h = rowH }
(map (cn \
cellValue = display (unwrapOr "" (getField cn r)); cellValue = display (unwrapOr "" (getField cn r));
Fixed 100 (cw ch \ (sizedText cellValue).ui) Fixed colW (ctx \ (sizedText cellValue).ui)) columnNames)).ui;
) columnNames) headerRow = (row { w = w, h = rowH } (map (cn \ Fixed colW (ctx \ (sizedText cn).ui)) columnNames)).ui;
).ui; bodyRows = map (r \ Fixed rowH (ctx \ rowFromRecord r)) list;
(col { w = w, h = h } [Fixed rowH (ctx \ headerRow), ...bodyRows]).ui;
headerRow = (row { w = w, h = rowH }
(map (cn \
Fixed colW (cw ch \ (sizedText cn).ui)
) columnNames)
).ui;
bodyRows = map (r \ Fixed rowH (cw cch \ rowFromRecord r)) list;
(col { w = 500, h = 500 } [
Fixed rowH (cw ch \ headerRow),
...bodyRows
]).ui;
@ @

View file

@ -386,10 +386,7 @@ sizedText = content \
size = measureText { content = content }; size = measureText { content = content };
{ ui = renderText { content = content }, w = size.width, h = size.height }; { ui = renderText { content = content }, w = size.width, h = size.height };
# new CG layout LayoutChild = Fixed Int (Ctx \ UI) | Flex Int (Ctx \ UI);
# move to layout module
LayoutChild = Fixed Int (Int \ Int \ UI) | Flex Int (Int \ Int \ UI);
Alignment = Start | Center | End; Alignment = Start | Center | End;
Direction = Col | Row; Direction = Col | Row;