Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scrollable child widgets to return a value #89

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, ())
Loading