on develop help sign in
input: add set value event to checkbox configuration
158d77eAli Abrar
src/Reflex/Vty/Widget/Input.hs+6−3
@@ -108,12 +108,14 @@ checkboxStyleTick = CheckboxStyle
108data CheckboxConfig t = CheckboxConfig
108data CheckboxConfig t = CheckboxConfig
109 { _checkboxConfig_checkboxStyle :: Behavior t CheckboxStyle
109 { _checkboxConfig_checkboxStyle :: Behavior t CheckboxStyle
110 , _checkboxConfig_attributes :: Behavior t V.Attr
110 , _checkboxConfig_attributes :: Behavior t V.Attr
111+ , _checkboxConfig_setValue :: Event t Bool
111 }
112 }
112
113
113instance (Reflex t) => Default (CheckboxConfig t) where
114instance (Reflex t) => Default (CheckboxConfig t) where
114 def = CheckboxConfig
115 def = CheckboxConfig
115 { _checkboxConfig_checkboxStyle = pure def
116 { _checkboxConfig_checkboxStyle = pure def
116 , _checkboxConfig_attributes = pure V.defAttr
117 , _checkboxConfig_attributes = pure V.defAttr
118+ , _checkboxConfig_setValue = never
117 }
119 }
118
120
119-- | A checkbox widget
121-- | A checkbox widget
@@ -127,9 +129,10 @@ checkbox cfg v0 = do
127 mu <- mouseUp
129 mu <- mouseUp
128 space <- key (V.KChar ' ')
130 space <- key (V.KChar ' ')
129 f <- focus
131 f <- focus
130− v <- toggle v0 $ leftmost
132+ v <- foldDyn ($) v0 $ leftmost
131− [ () <$ mu
133+ [ not <$ mu
132− , () <$ space
134+ , not <$ space
135+ , const <$> _checkboxConfig_setValue cfg
133 ]
136 ]
134 let bold = V.withStyle mempty V.bold
137 let bold = V.withStyle mempty V.bold
135 depressed <- hold mempty $ leftmost
138 depressed <- hold mempty $ leftmost