on develop help sign in
input/text theme usage
commit873c59a37aa44160d023b24b8f095c1203b1d013 authorpdlla <chippermonky@gmail.com> dateSun 11 Apr 2021, 16:59 (6 years ago) parent9862dfb
3 files changed+26−18
src/Reflex/Vty/Widget/Box.hs+1−1 src/Reflex/Vty/Widget/Input.hs+8−7 src/Reflex/Vty/Widget/Text.hs+17−10
src/Reflex/Vty/Widget/Box.hs+1−1
@@ -13,7 +13,7 @@ import Reflex.Vty.Widget
1313import Reflex.Vty.Widget.Text
1414
1515-- | Fill the background with the bottom box style
16−hRule :: (HasDisplayRegion t m, HasImageWriter t m) => BoxStyle -> m ()
16+hRule :: (HasDisplayRegion t m, HasImageWriter t m, HasTheme t m) => BoxStyle -> m ()
1717hRule boxStyle = fill $ pure (_boxStyle_s boxStyle)
1818
1919-- | Defines a set of symbols to use to draw the outlines of boxes
src/Reflex/Vty/Widget/Input.hs+8−7
@@ -34,7 +34,7 @@ instance Reflex t => Default (ButtonConfig t) where
3434
3535-- | A button widget that contains a sub-widget
3636button
37− :: (Reflex t, Monad m, HasFocusReader t m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m)
37+ :: (Reflex t, Monad m, HasFocusReader t m, HasTheme t m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m)
3838 => ButtonConfig t
3939 -> m ()
4040 -> m (Event t ())
@@ -52,7 +52,7 @@ button cfg child = do
5252
5353-- | A button widget that displays text that can change
5454textButton
55− :: (Reflex t, Monad m, HasDisplayRegion t m, HasFocusReader t m, HasImageWriter t m, HasInput t m)
55+ :: (Reflex t, Monad m, HasDisplayRegion t m, HasFocusReader t m, HasTheme t m, HasImageWriter t m, HasInput t m)
5656 => ButtonConfig t
5757 -> Behavior t Text
5858 -> m (Event t ())
@@ -60,7 +60,7 @@ textButton cfg = button cfg . text -- TODO Centering etc.
6060
6161-- | A button widget that displays a static bit of text
6262textButtonStatic
63− :: (Reflex t, Monad m, HasDisplayRegion t m, HasFocusReader t m, HasImageWriter t m, HasInput t m)
63+ :: (Reflex t, Monad m, HasDisplayRegion t m, HasFocusReader t m, HasTheme t m, HasImageWriter t m, HasInput t m)
6464 => ButtonConfig t
6565 -> Text
6666 -> m (Event t ())
@@ -70,19 +70,20 @@ textButtonStatic cfg = textButton cfg . pure
7070
7171-- | A clickable link widget
7272link
73− :: (Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m)
73+ :: (Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasTheme t m)
7474 => Behavior t Text
7575 -> m (Event t MouseUp)
7676link t = do
77+ bt <- theme
7778 let cfg = RichTextConfig
78− { _richTextConfig_attributes = pure $ V.withStyle V.defAttr V.underline
79+ { _richTextConfig_attributes = fmap (\attr -> V.withStyle attr V.underline) bt
7980 }
8081 richText cfg t
8182 mouseUp
8283
8384-- | A clickable link widget with a static label
8485linkStatic
85− :: (Reflex t, Monad m, HasImageWriter t m, HasDisplayRegion t m, HasInput t m)
86+ :: (Reflex t, Monad m, HasImageWriter t m, HasDisplayRegion t m, HasInput t m, HasTheme t m)
8687 => Text
8788 -> m (Event t MouseUp)
8889linkStatic = link . pure
@@ -128,7 +129,7 @@ instance (Reflex t) => Default (CheckboxConfig t) where
128129
129130-- | A checkbox widget
130131checkbox
131− :: (MonadHold t m, MonadFix m, Reflex t, HasInput t m, HasDisplayRegion t m, HasImageWriter t m, HasFocusReader t m)
132+ :: (MonadHold t m, MonadFix m, Reflex t, HasInput t m, HasDisplayRegion t m, HasImageWriter t m, HasFocusReader t m, HasTheme t m)
132133 => CheckboxConfig t
133134 -> Bool
134135 -> m (Dynamic t Bool)
src/Reflex/Vty/Widget/Text.hs+17−10
@@ -14,13 +14,15 @@ import Reflex.Vty.Widget
1414import Reflex.Vty.Widget.Input.Mouse
1515
1616-- | Fill the background with a particular character.
17−fill :: (HasDisplayRegion t m, HasImageWriter t m) => Behavior t Char -> m ()
17+fill :: (HasDisplayRegion t m, HasImageWriter t m, HasTheme t m) => Behavior t Char -> m ()
1818fill bc = do
1919 dw <- displayWidth
2020 dh <- displayHeight
21+ bt <- theme
2122 let fillImg =
22− (\w h c -> [V.charFill V.defAttr c w h])
23− <$> current dw
23+ (\attr w h c -> [V.charFill attr c w h])
24+ <$> bt
25+ <*> current dw
2426 <*> current dh
2527 <*> bc
2628 tellImages fillImg
@@ -33,9 +35,11 @@ data RichTextConfig t = RichTextConfig
3335instance Reflex t => Default (RichTextConfig t) where
3436 def = RichTextConfig $ pure V.defAttr
3537
38+
39+-- TODO delete this and use new local theming
3640-- | A widget that displays text with custom time-varying attributes
3741richText
38− :: (Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m)
42+ :: (Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m, HasTheme t m)
3943 => RichTextConfig t
4044 -> Behavior t Text
4145 -> m ()
@@ -53,15 +57,17 @@ richText cfg t = do
5357
5458-- | Renders text, wrapped to the container width
5559text
56− :: (Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m)
60+ :: (Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m, HasTheme t m)
5761 => Behavior t Text
5862 -> m ()
59−text = richText def
63+text t = do
64+ bt <- theme
65+ richText (RichTextConfig bt) t
6066
6167-- | Scrollable text widget. The output pair exposes the current scroll position and total number of lines (including those
6268-- that are hidden)
6369scrollableText
64− :: forall t m. (Reflex t, MonadHold t m, MonadFix m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m)
70+ :: forall t m. (Reflex t, MonadHold t m, MonadFix m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasTheme t m)
6571 => Event t Int
6672 -- ^ Number of lines to scroll by
6773 -> Behavior t Text
@@ -69,7 +75,8 @@ scrollableText
6975 -- ^ (Current scroll position, total number of lines)
7076scrollableText scrollBy t = do
7177 dw <- displayWidth
72− let imgs = wrap <$> current dw <*> t
78+ bt <- theme
79+ let imgs = wrap <$> bt <*> current dw <*> t
7380 kup <- key V.KUp
7481 kdown <- key V.KDown
7582 m <- mouseScroll
@@ -88,12 +95,12 @@ scrollableText scrollBy t = do
8895 tellImages $ fmap ((:[]) . V.vertCat) $ drop <$> current lineIndex <*> imgs
8996 return $ (,) <$> ((+) <$> current lineIndex <*> pure 1) <*> (length <$> imgs)
9097 where
91− wrap maxWidth = concatMap (fmap (V.string V.defAttr . T.unpack) . TZ.wrapWithOffset maxWidth 0) . T.split (=='\n')
98+ wrap attr maxWidth = concatMap (fmap (V.string attr . T.unpack) . TZ.wrapWithOffset maxWidth 0) . T.split (=='\n')
9299
93100-- | Renders any behavior whose value can be converted to
94101-- 'String' as text
95102display
96− :: (Reflex t, Monad m, Show a, HasDisplayRegion t m, HasImageWriter t m)
103+ :: (Reflex t, Monad m, Show a, HasDisplayRegion t m, HasImageWriter t m, HasTheme t m)
97104 => Behavior t a
98105 -> m ()
99106display a = text $ T.pack . show <$> a