module Graphics.Vty.Widgets.WrappedText
( WrappedText
, wrappedText
)
where
import Text.Trans.Wrap ( wrap )
import Graphics.Vty
( Attr
, region_width
, region_height
, vert_cat
)
import Graphics.Vty.Widgets.Base
( Widget(..)
, text
, hFill
, anyWidget
)
data WrappedText = WrappedText Attr String
wrappedText :: Attr -> String -> WrappedText
wrappedText = WrappedText
instance Widget WrappedText where
growHorizontal _ = True
growVertical _ = False
primaryAttribute (WrappedText att _) = att
withAttribute (WrappedText _ t) att = WrappedText att t
render s (WrappedText attr str) =
let images = map (render s . convert) $ lines wrapped
wrapped = wrap (fromEnum $ region_width s) str
convert [] = anyWidget $ hFill attr ' ' 1
convert line = anyWidget $ text attr line
in vert_cat $ take (fromEnum $ region_height s) images