gdritter repos brick-table / master
README + minor doc changes Getty Ritter 7 years ago
3 changed file(s) with 33 addition(s) and 2 deletion(s). Collapse all Expand all
1 # `brick-table`
2
3 This is a package for creating and manipulating simple spreadsheed-like table widgets in [`brick`](https://hackage.haskell.org/package/brick-0.17). These tables come equipped with a notion of selection/focus on a set of cells, as well as a handful of functions for accessing and manipulating that subset.
4
5 A `table` in this case wraps an underlying `array` value that's indexed with an `(Int, Int)` pair. We can create a new `table` with default values using the `table` function, and include it in our application's `state`.
6
7 ```.haskell
8 app :: App (Table TableElement MyName) MyEvent MyName
9 app = App
10 { appDraw = \ s -> renderTable True s
11 , appChooseCursor = \ _ _ -> Nothing
12 , appHandleEvent = \ s e -> case e of
13 VtyEvent (EvKey KEsc []) -> halt s
14 _ -> do
15 s' <- handleTableEvenArrowKeys ev s
16 continue s'
17 , appStartEvent = \s -> return s
18 , appAttrMap = \_ -> attrMap mempty []
19 }
20
21 main :: IO ()
22 main = do
23 let myTable = table myName (width, height) myDrawFunction myTableElement
24 _ <- Brick.defaultMain app myTable
25 return ()
26 ```
4141 main :: IO ()
4242 main = do
4343 let tb = table () (10, 10) drawElem 0
44 _ <- Brick.customMain (Vty.mkVty mempty) (Nothing) app tb
44 _ <- Brick.defaultMain app tb
4545 return ()
3030 -- ^ The array which represents the contents of the
3131 -- table. This always begins at index @(0,0)@.
3232 , tableCurIndex :: ((Int, Int), (Int, Int))
33 -- ^ The currently focused index
33 -- ^ The currently focused range of cells, of the form
34 -- @((minX, minY), (maxX, maxY))@. Be aware that this module maintains
35 -- the invariants that @minX <= minY && maxX <= maxY@, and that both
36 -- the min and max indices are within the range of the table. If
37 -- this value is modified without preserving that invariant, functions
38 -- in this module may produce anomalous results or even crash.
3439 , tableDraw :: e -> Bool -> Brick.Widget n
3540 -- ^ The function the table uses to draw its contents. The
3641 -- boolean parameter will be 'True' if the element is the