summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-10-20 14:04:16 -0400
committerAndrew Cady <d@jerkface.net>2022-10-20 15:51:32 -0400
commit9e13109221b93a9714e34e498a39f9bec5e73254 (patch)
tree752b1127daf8bb6116a6ec62a5e75a8f01cd4a57
parent55747fcd5a9fa8f43b6a486e6bb1452a02de7f68 (diff)
add scrolling
-rwxr-xr-xrepgoal.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/repgoal.hs b/repgoal.hs
index a82aaa3..bef5c88 100755
--- a/repgoal.hs
+++ b/repgoal.hs
@@ -45,6 +45,7 @@ import Brick.Main
45 , continue 45 , continue
46 , halt 46 , halt
47 ) 47 )
48import qualified Brick.Main as M
48import Brick.AttrMap 49import 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
116drawUI :: St -> [Widget ()] 117drawUI :: St -> [Widget ()]
117drawUI (St lifts) = [vCenter $ vBox [hCenter oneRepMaxTable, hCenter lastSetTable]] 118drawUI (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
163handleEvent :: St -> BrickEvent () CustomEvent -> EventM () (Next St) 164handleEvent :: St -> BrickEvent () CustomEvent -> EventM () (Next St)
164handleEvent st e = case e of 165handleEvent 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 =
179main :: IO () 182main :: IO ()
180main = do 183main = 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)