diff options
author | Andrew Cady <d@jerkface.net> | 2022-10-20 14:04:16 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2022-10-20 15:51:32 -0400 |
commit | 9e13109221b93a9714e34e498a39f9bec5e73254 (patch) | |
tree | 752b1127daf8bb6116a6ec62a5e75a8f01cd4a57 | |
parent | 55747fcd5a9fa8f43b6a486e6bb1452a02de7f68 (diff) |
add scrolling
-rwxr-xr-x | repgoal.hs | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -45,6 +45,7 @@ import Brick.Main | |||
45 | , continue | 45 | , continue |
46 | , halt | 46 | , halt |
47 | ) | 47 | ) |
48 | import qualified Brick.Main as M | ||
48 | import Brick.AttrMap | 49 | import Brick.AttrMap |
49 | ( attrMap | 50 | ( attrMap |
50 | ) | 51 | ) |
@@ -114,7 +115,7 @@ showRational n = printf format $ (realToFrac :: Rational -> Float) $ n | |||
114 | format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.2f" | 115 | format = if floor (n * 10) `mod` 10 == (0 :: Integer) then "%.0f" else "%.2f" |
115 | 116 | ||
116 | drawUI :: St -> [Widget ()] | 117 | drawUI :: St -> [Widget ()] |
117 | drawUI (St lifts) = [vCenter $ vBox [hCenter oneRepMaxTable, hCenter lastSetTable]] | 118 | drawUI (St lifts) = [vCenter $ vBox [hCenter oneRepMaxTable, withVScrollBarHandles $ withVScrollBars OnRight $ viewport () Vertical $ hCenter lastSetTable]] |
118 | where | 119 | where |
119 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts | 120 | lastSetTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Week", "Last Set", "Goal", "Goal+1"] : concatMap toWeekRows lifts |
120 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts | 121 | oneRepMaxTable = renderTable $ table $ map (padLeftRight 1 . str) ["Lift", "Achieved Best", "Computed 1RM"] : map toRow lifts |
@@ -163,6 +164,8 @@ data CustomEvent = CustomEvent | |||
163 | handleEvent :: St -> BrickEvent () CustomEvent -> EventM () (Next St) | 164 | handleEvent :: St -> BrickEvent () CustomEvent -> EventM () (Next St) |
164 | handleEvent st e = case e of | 165 | handleEvent st e = case e of |
165 | VtyEvent (V.EvKey V.KEsc []) -> halt st | 166 | VtyEvent (V.EvKey V.KEsc []) -> halt st |
167 | VtyEvent (V.EvKey V.KDown _) -> M.vScrollBy (M.viewportScroll ()) 5 >> continue st | ||
168 | VtyEvent (V.EvKey V.KUp _) -> M.vScrollBy (M.viewportScroll ()) (-5) >> continue st | ||
166 | VtyEvent _ -> continue st | 169 | VtyEvent _ -> continue st |
167 | AppEvent _ -> continue st | 170 | AppEvent _ -> continue st |
168 | _ -> continue st | 171 | _ -> continue st |
@@ -179,6 +182,7 @@ theApp = | |||
179 | main :: IO () | 182 | main :: IO () |
180 | main = do | 183 | main = do |
181 | let buildVty = V.mkVty V.defaultConfig | 184 | let buildVty = V.mkVty V.defaultConfig |
182 | initialVty <- buildVty | 185 | vty <- buildVty |
186 | -- liftIO $ setMode (outputIface vty) Mouse True | ||
183 | chan <- newBChan 10 | 187 | chan <- newBChan 10 |
184 | void $ customMain initialVty buildVty (Just chan) (theApp) (St initial) | 188 | void $ customMain vty buildVty (Just chan) (theApp) (St initial) |