More layout, tableView stuff

This commit is contained in:
Dustin Swan 2026-04-08 21:44:34 -06:00
parent 3886228f4a
commit cd7565261a
No known key found for this signature in database
GPG key ID: 30D46587E2100467

View file

@ -55,17 +55,44 @@ align = hAlign vAlign w h child \
h = h h = h
}; };
tableCell = isHeader idx ctx content \
padding = 2;
innerW = ctx.w - 2 * padding;
innerH = ctx.h - 2 * padding;
hAlign = isHeader | True \ Center | False \ Start;
alignedContent = align hAlign Center innerW innerH (sizedText content);
ui.stack {
children = [
ui.rect {
w = ctx.w,
h = ctx.h,
color = isHeader | True \ "rgba(255,255,255,0.2)" | False \ "transparent",
strokeColor = "rgba(255,255,255,0.3)",
strokeWidth = isHeader | True \ 0 | False \ 1
},
ui.positioned {
x = padding,
y = padding,
child = ui.clip {
w = innerW,
h = innerH,
child = alignedContent.ui
}
}
]
};
tableView = list \ ctx \ tableView = list \ ctx \
w = ctx.w; w = ctx.w;
h = ctx.h; 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 = 30;
rowFromRecord = r \ (row { w = w, h = rowH } (map (cn \ rowFromRecord = r \ (row { w = w, h = rowH } (mapWithIndex (cn idx \
cellValue = display (unwrapOr "" (getField cn r)); cellValue = display (unwrapOr "" (getField cn r));
Fixed colW (ctx \ (sizedText cellValue).ui)) columnNames)).ui; Fixed colW (ctx \ tableCell False idx ctx cellValue)) columnNames)).ui;
headerRow = (row { w = w, h = rowH } (map (cn \ Fixed colW (ctx \ (sizedText cn).ui)) columnNames)).ui; headerRow = (row { w = w, h = rowH } (mapWithIndex (cn idx \ Fixed colW (ctx \ tableCell True idx ctx cn)) columnNames)).ui;
bodyRows = map (r \ Fixed rowH (ctx \ rowFromRecord r)) list; bodyRows = map (r \ Fixed rowH (ctx \ rowFromRecord r)) list;
(col { w = w, h = h } [Fixed rowH (ctx \ headerRow), ...bodyRows]).ui; (col { w = w, h = h } [Fixed rowH (ctx \ headerRow), ...bodyRows]).ui;