@@ -132,14 +132,11 @@ class HasVtyWidgetCtx t m | m -> t where
132132 askCtx :: m (VtyWidgetCtx t)
133133 default askCtx :: (f m' ~ m, Monad m', MonadTrans f, HasVtyWidgetCtx t m') => m (VtyWidgetCtx t)
134134 askCtx = lift askCtx
135− localCtx :: (VtyWidgetCtx t -> VtyWidgetCtx t) -> (Behavior t [Image] -> Behavior t [Image]) -> m a -> m a
135+ localCtx :: (VtyWidgetCtx t -> VtyWidgetCtx t) -> m a -> m a
136136
137137instance (Monad m, Reflex t) => HasVtyWidgetCtx t (VtyWidget t m) where
138138 askCtx = VtyWidget $ lift ask
139− localCtx f g (VtyWidget x) = VtyWidget $ do
140− (a, images) :: (a, Behavior t [Image]) <- lift $ local f $ runBehaviorWriterT x
141− tellImages $ g images
142− pure a
139+ localCtx f (VtyWidget x) = VtyWidget $ local f x
143140
144141-- | Runs a 'VtyWidget' with a given context
145142runVtyWidget
@@ -243,9 +240,15 @@ class (Reflex t, Monad m) => ImageWriter t m | m -> t where
243240 tellImages :: Behavior t [Image] -> m ()
244241 default tellImages :: (f m' ~ m, Monad m', MonadTrans f, ImageWriter t m') => Behavior t [Image] -> m ()
245242 tellImages = lift . tellImages
243+ -- | Apply a transformation to the images produced by the child actions
244+ mapImages :: (Behavior t [Image] -> Behavior t [Image]) -> m a -> m a
246245
247246instance (Monad m, Reflex t) => ImageWriter t (BehaviorWriterT t [Image] m) where
248247 tellImages = tellBehavior
248+ mapImages f x = do
249+ (a, images) <- lift $ runBehaviorWriterT x
250+ tellImages $ f images
251+ pure a
249252
250253-- | A chunk of the display area
251254data Region = Region
@@ -283,7 +286,7 @@ withinImage (Region left top width height)
283286-- * mouse inputs inside the region have their coordinates translated such
284287-- that (0,0) is the top-left corner of the region
285288pane
286− :: (Reflex t, Monad m, MonadNodeId m, HasVtyWidgetCtx t m, HasVtyInput t m)
289+ :: (Reflex t, Monad m, MonadNodeId m, HasVtyWidgetCtx t m, HasVtyInput t m, ImageWriter t m)
287290 => Dynamic t Region
288291 -> Dynamic t Bool -- ^ Whether the widget should be focused when the parent is.
289292 -> m a
@@ -299,7 +302,7 @@ pane dr foc child = do
299302 attachWith (\(r,f) e -> filterInput r f e)
300303 (liftA2 (,) reg (current foc))
301304 let imagesWithinRegion images = liftA2 (\is r -> map (withinImage r) is) images reg
302− localInput inputFilter $ localCtx subContext imagesWithinRegion child
305+ mapImages imagesWithinRegion $ localInput inputFilter $ localCtx subContext child
303306 where
304307 filterInput :: Region -> Bool -> VtyEvent -> Maybe VtyEvent
305308 filterInput (Region l t w h) focused e = case e of
@@ -444,7 +447,7 @@ keyCombos ks = do
444447
445448-- | A plain split of the available space into vertically stacked panes.
446449-- No visual separator is built in here.
447−splitV :: (Reflex t, Monad m, MonadNodeId m, HasVtyWidgetCtx t m, HasDisplaySize t m, HasVtyInput t m)
450+splitV :: (Reflex t, Monad m, MonadNodeId m, HasVtyWidgetCtx t m, HasDisplaySize t m, HasVtyInput t m, ImageWriter t m)
448451 => Dynamic t (Int -> Int)
449452 -- ^ Function used to determine size of first pane based on available size
450453 -> Dynamic t (Bool, Bool)
@@ -465,7 +468,7 @@ splitV sizeFunD focD wA wB = do
465468
466469-- | A plain split of the available space into horizontally stacked panes.
467470-- No visual separator is built in here.
468−splitH :: (Reflex t, Monad m, MonadNodeId m, HasDisplaySize t m, HasVtyWidgetCtx t m, HasVtyInput t m)
471+splitH :: (Reflex t, Monad m, MonadNodeId m, HasDisplaySize t m, HasVtyWidgetCtx t m, HasVtyInput t m, ImageWriter t m)
469472 => Dynamic t (Int -> Int)
470473 -- ^ Function used to determine size of first pane based on available size
471474 -> Dynamic t (Bool, Bool)
@@ -485,7 +488,7 @@ splitH sizeFunD focD wA wB = do
485488-- | A split of the available space into two parts with a draggable separator.
486489-- Starts with half the space allocated to each, and the first pane has focus.
487490-- Clicking in a pane switches focus.
488−splitVDrag :: (Reflex t, MonadFix m, MonadHold t m, MonadNodeId m, HasDisplaySize t m, HasVtyInput t m, HasVtyWidgetCtx t m)
491+splitVDrag :: (Reflex t, MonadFix m, MonadHold t m, MonadNodeId m, HasDisplaySize t m, HasVtyInput t m, HasVtyWidgetCtx t m, ImageWriter t m)
489492 => m ()
490493 -> m a
491494 -> m b