Skip to content

Commit

Permalink
Merge pull request #89 from reflex-frp/aa/scrollable-return
Browse files Browse the repository at this point in the history
Allow scrollable child widgets to return a value
  • Loading branch information
ali-abrar authored Nov 10, 2024
2 parents 400eb74 + f492633 commit 78284f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for reflex-vty

## Unreleased

* *Breaking Change*: `Reflex.Vty.Widget.Scroll.scrollable` now require child widgets to return a value in addition to their images and update events. Specifically, the child widget type has gone from `m (Behavior t Image, Event t ())` to `m (Behavior t Image, Event t (), a)`.

## 0.5.2.1
* Extend version bounds

Expand Down
12 changes: 7 additions & 5 deletions src/Reflex/Vty/Widget/Scroll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ data Scrollable t = Scrollable
-- | Scrollable widget. The output exposes the current scroll position and
-- total number of lines (including those that are hidden)
scrollable
:: forall t m. (Reflex t, MonadHold t m, MonadFix m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasTheme t m)
:: forall t m a.
( Reflex t, MonadHold t m, MonadFix m
, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasTheme t m)
=> ScrollableConfig t
-> (m (Behavior t V.Image, Event t ()))
-> m (Scrollable t)
-> (m (Behavior t V.Image, Event t (), a))
-> m (Scrollable t, a)
scrollable (ScrollableConfig scrollBy scrollTo startingPos onAppend) mkImg = do
(img, update) <- mkImg
(img, update, a) <- mkImg
let sz = V.imageHeight <$> img
kup <- key V.KUp
kdown <- key V.KDown
Expand Down Expand Up @@ -85,7 +87,7 @@ scrollable (ScrollableConfig scrollBy scrollTo startingPos onAppend) mkImg = do
ScrollPos_Top -> images -- take height images
ScrollPos_Line n -> V.translateY ((-1) * n) images
tellImages $ fmap (:[]) $ imgsToTell <$> current dh <*> current lineIndex <*> sz <*> img
return $ Scrollable
return $ (,a) $ Scrollable
{ _scrollable_scrollPosition = current lineIndex
, _scrollable_totalLines = sz
, _scrollable_scrollHeight = current dh
Expand Down
7 changes: 3 additions & 4 deletions src/Reflex/Vty/Widget/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ scrollableText
=> ScrollableConfig t
-> Dynamic t Text
-> m (Scrollable t)
scrollableText cfg t = do
scrollable cfg $ do
((), images) <- runImageWriter $ text (current t)
pure $ (V.vertCat <$> images, () <$ updated t)
scrollableText cfg t = fmap fst $ scrollable cfg $ do
((), images) <- runImageWriter $ text (current t)
pure $ (V.vertCat <$> images, () <$ updated t, ())

0 comments on commit 78284f9

Please sign in to comment.