Skip to content

Commit b7db037

Browse files
committedNov 10, 2024·
Allow scrollable child widgets to return a value
1 parent 400eb74 commit b7db037

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed
 

‎src/Reflex/Vty/Widget/Scroll.hs

+7-5
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ data Scrollable t = Scrollable
4747
-- | Scrollable widget. The output exposes the current scroll position and
4848
-- total number of lines (including those that are hidden)
4949
scrollable
50-
:: forall t m. (Reflex t, MonadHold t m, MonadFix m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasTheme t m)
50+
:: forall t m a.
51+
( Reflex t, MonadHold t m, MonadFix m
52+
, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasTheme t m)
5153
=> ScrollableConfig t
52-
-> (m (Behavior t V.Image, Event t ()))
53-
-> m (Scrollable t)
54+
-> (m (Behavior t V.Image, Event t (), a))
55+
-> m (Scrollable t, a)
5456
scrollable (ScrollableConfig scrollBy scrollTo startingPos onAppend) mkImg = do
55-
(img, update) <- mkImg
57+
(img, update, a) <- mkImg
5658
let sz = V.imageHeight <$> img
5759
kup <- key V.KUp
5860
kdown <- key V.KDown
@@ -85,7 +87,7 @@ scrollable (ScrollableConfig scrollBy scrollTo startingPos onAppend) mkImg = do
8587
ScrollPos_Top -> images -- take height images
8688
ScrollPos_Line n -> V.translateY ((-1) * n) images
8789
tellImages $ fmap (:[]) $ imgsToTell <$> current dh <*> current lineIndex <*> sz <*> img
88-
return $ Scrollable
90+
return $ (,a) $ Scrollable
8991
{ _scrollable_scrollPosition = current lineIndex
9092
, _scrollable_totalLines = sz
9193
, _scrollable_scrollHeight = current dh

‎src/Reflex/Vty/Widget/Text.hs

+3-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ scrollableText
7979
=> ScrollableConfig t
8080
-> Dynamic t Text
8181
-> m (Scrollable t)
82-
scrollableText cfg t = do
83-
scrollable cfg $ do
84-
((), images) <- runImageWriter $ text (current t)
85-
pure $ (V.vertCat <$> images, () <$ updated t)
82+
scrollableText cfg t = fmap fst $ scrollable cfg $ do
83+
((), images) <- runImageWriter $ text (current t)
84+
pure $ (V.vertCat <$> images, () <$ updated t, ())

0 commit comments

Comments
 (0)