From b04be8ccab085314e4e0027719e9266521797f51 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Wed, 8 Apr 2026 19:18:45 -0600 Subject: [PATCH] Views now take a ctx. OS can call them directly --- src/cg/layout.cg | 44 ++++++++++++++------------------------------ src/cg/ui.cg | 5 +---- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/cg/layout.cg b/src/cg/layout.cg index 5fe8237..1420204 100644 --- a/src/cg/layout.cg +++ b/src/cg/layout.cg @@ -28,7 +28,7 @@ layoutDir : Direction \ { w : Int, h : Int } \ List LayoutChild \ { ui : UI, w : posY = dir | Col \ acc.pos | 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; { ui = ui.stack { children = result.children }, @@ -55,34 +55,18 @@ align = hAlign vAlign w h child \ h = h }; - tableView = list \ w h \ - firstRow = unwrapOr "{}" (nth 0 list); - - columnNames = keys firstRow; - - colW = w / (len columnNames); - rowH = 24; - - rowFromRecord = r \ - (row { w = w, h = rowH } - (map (cn \ - cellValue = display (unwrapOr "" (getField cn r)); - Fixed 100 (cw ch \ (sizedText cellValue).ui) - ) columnNames) - ).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; - +tableView = list \ ctx \ + w = ctx.w; + h = ctx.h; + firstRow = unwrapOr "{}" (nth 0 list); + columnNames = keys firstRow; + colW = w / (len columnNames); + rowH = 24; + rowFromRecord = r \ (row { w = w, h = rowH } (map (cn \ + cellValue = display (unwrapOr "" (getField cn r)); + Fixed colW (ctx \ (sizedText cellValue).ui)) columnNames)).ui; + headerRow = (row { w = w, h = rowH } (map (cn \ Fixed colW (ctx \ (sizedText cn).ui)) columnNames)).ui; + bodyRows = map (r \ Fixed rowH (ctx \ rowFromRecord r)) list; + (col { w = w, h = h } [Fixed rowH (ctx \ headerRow), ...bodyRows]).ui; @ diff --git a/src/cg/ui.cg b/src/cg/ui.cg index 032063d..cb82311 100644 --- a/src/cg/ui.cg +++ b/src/cg/ui.cg @@ -386,10 +386,7 @@ sizedText = content \ size = measureText { content = content }; { ui = renderText { content = content }, w = size.width, h = size.height }; -# new CG layout -# move to layout module - -LayoutChild = Fixed Int (Int \ Int \ UI) | Flex Int (Int \ Int \ UI); +LayoutChild = Fixed Int (Ctx \ UI) | Flex Int (Ctx \ UI); Alignment = Start | Center | End; Direction = Col | Row;