@@ -3,7 +3,61 @@ Module: Reflex.Vty.Widget.Input
33Description: User input widgets for reflex-vty
44-}
55module Reflex.Vty.Widget.Input
6− ( module Reflex.Vty.Widget.Input.Text
6+ ( module Export
7+ , module Reflex.Vty.Widget.Input
78 ) where
89
9−import Reflex.Vty.Widget.Input.Text
10+
11+import Reflex.Vty.Widget.Input.Text as Export
12+
13+import Data.Default
14+import Data.Text (Text)
15+import qualified Graphics.Vty as V
16+import Reflex
17+import Reflex.Vty.Widget
18+
19+-- | Configuration options for the 'button' widget
20+data ButtonConfig t = ButtonConfig
21+ { _buttonConfig_boxStyle :: Behavior t BoxStyle
22+ }
23+
24+instance Reflex t => Default (ButtonConfig t) where
25+ def = ButtonConfig (pure def)
26+
27+-- | A button widget that contains a sub-widget
28+button
29+ :: (Reflex t, Monad m)
30+ => ButtonConfig t
31+ -> VtyWidget t m ()
32+ -> VtyWidget t m (Event t MouseUp)
33+button cfg child = do
34+ box (_buttonConfig_boxStyle cfg) child
35+ mouseUp
36+
37+-- | A button widget that displays text that can change
38+textButton
39+ :: (Reflex t, Monad m)
40+ => ButtonConfig t
41+ -> Behavior t Text
42+ -> VtyWidget t m (Event t MouseUp)
43+textButton cfg = button cfg . text -- TODO Centering etc.
44+
45+-- | A button widget that displays a static bit of text
46+textButtonStatic
47+ :: (Reflex t, Monad m)
48+ => ButtonConfig t
49+ -> Text
50+ -> VtyWidget t m (Event t MouseUp)
51+textButtonStatic cfg = textButton cfg . pure
52+
53+-- | A clickable link widget
54+link
55+ :: (Reflex t, Monad m)
56+ => Behavior t Text
57+ -> VtyWidget t m (Event t MouseUp)
58+link t = do
59+ let cfg = RichTextConfig
60+ { _richTextConfig_attributes = pure $ V.withStyle V.defAttr V.underline
61+ }
62+ richText cfg t
63+ mouseUp