@@ -1,3 +1,7 @@
1+{-|
2+Module: Reflex.Vty.Widget
3+Description: Basic set of widgets and building blocks for reflex-vty applications
4+-}
15{-# LANGUAGE FlexibleContexts #-}
26{-# LANGUAGE FlexibleInstances #-}
37{-# LANGUAGE FunctionalDependencies #-}
@@ -167,6 +171,7 @@ instance (Reflex t, Monad m) => HasFocus t (VtyWidget t m) where
167171
168172-- | A class for widgets that can produce images to draw to the display
169173class (Reflex t, Monad m) => ImageWriter t m | m -> t where
174+ -- | Send images upstream for rendering
170175 tellImages :: Behavior t [Image] -> m ()
171176
172177instance (Reflex t, Monad m) => ImageWriter t (VtyWidget t m) where
@@ -174,6 +179,7 @@ instance (Reflex t, Monad m) => ImageWriter t (VtyWidget t m) where
174179
175180-- | A class for things that can shut down the vty application
176181class (Reflex t, Monad m) => Shutdown t m where
182+ -- | Signals that the vty application should shut down
177183 tellShutdown :: Event t () -> m ()
178184
179185instance (Reflex t, Monad m) => Shutdown t (VtyWidget t m) where
@@ -192,6 +198,22 @@ data Region = Region
192198regionSize :: Region -> (Int, Int)
193199regionSize (Region _ _ w h) = (w, h)
194200
201+
202+-- | Produces an 'Image' that fills a region with space characters
203+regionBlankImage :: Region -> Image
204+regionBlankImage r@(Region _ _ width height) =
205+ withinImage r $ V.charFill V.defAttr ' ' width height
206+
207+-- | Translates and crops an 'Image' so that it is contained by
208+-- the given 'Region'.
209+withinImage
210+ :: Region
211+ -> Image
212+ -> Image
213+withinImage (Region left top width height)
214+ | width < 0 || height < 0 = withinImage (Region left top 0 0)
215+ | otherwise = V.translate left top . V.crop width height
216+
195217-- | Low-level widget combinator that runs a child 'VtyWidget' within
196218-- a given region and context. This widget filters and modifies the input
197219-- that the child widget receives such that:
@@ -455,20 +477,12 @@ text msg = do
455477 . concatMap (fmap (V.string attrs . T.unpack) . TZ.wrapWithOffset maxWidth 0)
456478 . T.split (=='\n')
457479
480+-- | Renders any behavior whose value can be converted to
481+-- 'String' as text
458482display
459483 :: (Reflex t, Monad m, Show a)
460484 => Behavior t a
461485 -> VtyWidget t m ()
462486display a = text $ T.pack . show <$> a
463487
464−regionBlankImage :: Region -> Image
465−regionBlankImage r@(Region _ _ width height) =
466− withinImage r $ V.charFill V.defAttr ' ' width height
467488
468−withinImage
469− :: Region
470− -> Image
471− -> Image
472−withinImage (Region left top width height)
473− | width < 0 || height < 0 = withinImage (Region left top 0 0)
474− | otherwise = V.translate left top . V.crop width height