diff --git a/src/cg/layout.cg b/src/cg/layout.cg index 1420204..abda551 100644 --- a/src/cg/layout.cg +++ b/src/cg/layout.cg @@ -55,17 +55,44 @@ align = hAlign vAlign w h child \ 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 \ 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 \ + rowH = 30; + rowFromRecord = r \ (row { w = w, h = rowH } (mapWithIndex (cn idx \ 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; + Fixed colW (ctx \ tableCell False idx ctx cellValue)) 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; (col { w = w, h = h } [Fixed rowH (ctx \ headerRow), ...bodyRows]).ui;