From 2182c80ab3a2ee4ae94e7c690d7e415dc2805ad9 Mon Sep 17 00:00:00 2001 From: Jonathan Daugherty Date: Sun, 31 Jan 2021 19:39:22 -0800 Subject: [PATCH] table: raise exception if any contents use Greedy policy --- src/Brick/Widgets/Table.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Brick/Widgets/Table.hs b/src/Brick/Widgets/Table.hs index 78e72a6..d1bf5a5 100644 --- a/src/Brick/Widgets/Table.hs +++ b/src/Brick/Widgets/Table.hs @@ -38,12 +38,19 @@ data Table n = table :: [[Widget n]] -> Table n table rows = - Table { columnAlignments = mempty - , tableRows = rows - , drawSurroundingBorder = True - , drawRowBorders = True - , drawColumnBorders = True - } + if not allFixed + then error "table: all cells must have Fixed horizontal and vertical growth policies" + else t + where + allFixed = all (== Fixed) $ concat $ getPolicies <$> rows + getPolicies row = concat $ getCellPolicies <$> row + getCellPolicies w = [hSize w, vSize w] + t = Table { columnAlignments = mempty + , tableRows = rows + , drawSurroundingBorder = True + , drawRowBorders = True + , drawColumnBorders = True + } surroundingBorder :: Bool -> Table n -> Table n surroundingBorder b t =