Table: add API to disable column borders

This commit is contained in:
Jonathan Daugherty 2021-01-31 19:26:21 -08:00
parent 3fb27849a3
commit 20ec0b6bbf
2 changed files with 15 additions and 5 deletions

View File

@ -15,8 +15,6 @@ myTable :: Table ()
myTable =
alignCenter 1 $
alignRight 2 $
noBorder $
noRowBorders $
table [ [txt "Left", txt "Center", txt "Right"]
, [txt "X", txt "Some things", txt "A"]
, [txt "Y", txt "are", txt "B"]

View File

@ -6,6 +6,7 @@ module Brick.Widgets.Table
, alignCenter
, noBorder
, noRowBorders
, noColumnBorders
, renderTable
)
@ -32,6 +33,7 @@ data Table n =
, tableRows :: [[Widget n]]
, surroundingBorder :: Bool
, rowBorders :: Bool
, columnBorders :: Bool
}
table :: [[Widget n]] -> Table n
@ -40,6 +42,7 @@ table rows =
, tableRows = rows
, surroundingBorder = True
, rowBorders = True
, columnBorders = True
}
noBorder :: Table n -> Table n
@ -50,6 +53,10 @@ noRowBorders :: Table n -> Table n
noRowBorders t =
t { rowBorders = False }
noColumnBorders :: Table n -> Table n
noColumnBorders t =
t { columnBorders = False }
alignRight :: Int -> Table n -> Table n
alignRight col =
setAlignment col AlignRight
@ -97,6 +104,11 @@ renderTable t =
render $ vBox $ maybeRowBorders $
toW <$> paddedCells
columns <- mapM mkColumn $ zip3 [0..] colWidths byColumn
render $ hBox $
intersperse (vLimit (totalHeight + (length rows - 1)) vBorder) $
toW <$> columns
let maybeColumnBorders =
if columnBorders t
then let rowBorderHeight = if rowBorders t
then length rows - 1
else 0
in intersperse (vLimit (totalHeight + rowBorderHeight) vBorder)
else id
render $ hBox $ maybeColumnBorders $ toW <$> columns