on develop help sign in
Remove extra MonadNodeId constraints; Fix a few things pointed out in review
478b1f0Ali Abrar
src-bin/Example/CPU.hs−2
@@ -99,7 +99,6 @@ cpuStats
99 , HasImageWriter t m
99 , HasImageWriter t m
100 , HasLayout t m
100 , HasLayout t m
101 , HasFocus t m
101 , HasFocus t m
102− , MonadNodeId m
103 , HasInput t m
102 , HasInput t m
104 , HasFocusReader t m
103 , HasFocusReader t m
105 )
104 )
@@ -120,7 +119,6 @@ chart
120 :: ( MonadFix m
119 :: ( MonadFix m
121 , HasFocus t m
120 , HasFocus t m
122 , HasLayout t m
121 , HasLayout t m
123− , MonadNodeId m
124 , HasImageWriter t m
122 , HasImageWriter t m
125 , HasInput t m
123 , HasInput t m
126 , HasDisplayRegion t m
124 , HasDisplayRegion t m
src-bin/example.hs+1−3
@@ -1,7 +1,6 @@
1import Control.Applicative
1import Control.Applicative
2import Control.Monad
2import Control.Monad
3import Control.Monad.Fix
3import Control.Monad.Fix
4−import Control.Monad.NodeId
5import Data.Functor
4import Data.Functor
6import Data.Functor.Misc
5import Data.Functor.Misc
7import Data.Map (Map)
6import Data.Map (Map)
@@ -22,7 +21,6 @@ type VtyExample t m =
22 , Reflex t
21 , Reflex t
23 , HasInput t m
22 , HasInput t m
24 , HasImageWriter t m
23 , HasImageWriter t m
25− , MonadNodeId m
26 , HasDisplayRegion t m
24 , HasDisplayRegion t m
27 , HasFocus t m
25 , HasFocus t m
28 , HasFocusReader t m
26 , HasFocusReader t m
@@ -235,7 +233,7 @@ scrolling = col $ do
235-- * Text editor example with resizable boxes
233-- * Text editor example with resizable boxes
236
234
237testBoxes
235testBoxes
238− :: (MonadHold t m, MonadNodeId m, VtyExample t m)
236+ :: (MonadHold t m, VtyExample t m)
239 => m ()
237 => m ()
240testBoxes = do
238testBoxes = do
241 dw <- displayWidth
239 dw <- displayWidth
src/Reflex/Vty/Widget.hs+5−1
@@ -224,6 +224,10 @@ data Region = Region
224 }
224 }
225 deriving (Show, Read, Eq, Ord)
225 deriving (Show, Read, Eq, Ord)
226
226
227+-- | A region that occupies no space.
228+nilRegion :: Region
229+nilRegion = Region 0 0 0 0
230+
227-- | The width and height of a 'Region'
231-- | The width and height of a 'Region'
228regionSize :: Region -> (Int, Int)
232regionSize :: Region -> (Int, Int)
229regionSize (Region _ _ w h) = (w, h)
233regionSize (Region _ _ w h) = (w, h)
@@ -467,7 +471,7 @@ imagesInRegion reg = liftA2 (\r is -> map (withinImage r) is) reg
467-- * mouse inputs inside the region have their coordinates translated such
471-- * mouse inputs inside the region have their coordinates translated such
468-- that (0,0) is the top-left corner of the region
472-- that (0,0) is the top-left corner of the region
469pane
473pane
470− :: (Reflex t, Monad m, MonadNodeId m, HasInput t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
474+ :: (Reflex t, Monad m, HasInput t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
471 => Dynamic t Region
475 => Dynamic t Region
472 -> Dynamic t Bool -- ^ Whether the widget should be focused when the parent is.
476 -> Dynamic t Bool -- ^ Whether the widget should be focused when the parent is.
473 -> m a
477 -> m a
src/Reflex/Vty/Widget/Box.hs+3−4
@@ -3,7 +3,6 @@
3-}
3-}
4module Reflex.Vty.Widget.Box where
4module Reflex.Vty.Widget.Box where
5
5
6−import Control.Monad.NodeId
7import Data.Default
6import Data.Default
8import Data.Text (Text)
7import Data.Text (Text)
9import qualified Data.Text as T
8import qualified Data.Text as T
@@ -55,7 +54,7 @@ roundedBoxStyle :: BoxStyle
55roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
54roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
56
55
57-- | Draws a titled box in the provided style and a child widget inside of that box
56-- | Draws a titled box in the provided style and a child widget inside of that box
58−boxTitle :: (Monad m, Reflex t, MonadNodeId m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
57+boxTitle :: (Monad m, Reflex t ,HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
59 => Behavior t BoxStyle
58 => Behavior t BoxStyle
60 -> Behavior t Text
59 -> Behavior t Text
61 -> m a
60 -> m a
@@ -107,7 +106,7 @@ boxTitle boxStyle title child = do
107 right = mkHalf delta
106 right = mkHalf delta
108
107
109-- | A box without a title
108-- | A box without a title
110−box :: (Monad m, Reflex t, MonadNodeId m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
109+box :: (Monad m, Reflex t, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
111 => Behavior t BoxStyle
110 => Behavior t BoxStyle
112 -> m a
111 -> m a
113 -> m a
112 -> m a
@@ -115,7 +114,7 @@ box boxStyle = boxTitle boxStyle mempty
115
114
116-- | A box whose style is static
115-- | A box whose style is static
117boxStatic
116boxStatic
118− :: (Monad m, Reflex t, MonadNodeId m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
117+ :: (Monad m, Reflex t, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
119 => BoxStyle
118 => BoxStyle
120 -> m a
119 -> m a
121 -> m a
120 -> m a
src/Reflex/Vty/Widget/Input.hs+3−4
@@ -13,7 +13,6 @@ import Reflex.Vty.Widget.Input.Text as Export
13
13
14import Control.Monad (join)
14import Control.Monad (join)
15import Control.Monad.Fix (MonadFix)
15import Control.Monad.Fix (MonadFix)
16−import Control.Monad.NodeId (MonadNodeId)
17import Data.Default (Default(..))
16import Data.Default (Default(..))
18import Data.Text (Text)
17import Data.Text (Text)
19import qualified Graphics.Vty as V
18import qualified Graphics.Vty as V
@@ -35,7 +34,7 @@ instance Reflex t => Default (ButtonConfig t) where
35
34
36-- | A button widget that contains a sub-widget
35-- | A button widget that contains a sub-widget
37button
36button
38− :: (Reflex t, Monad m, MonadNodeId m, HasFocusReader t m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m)
37+ :: (Reflex t, Monad m, HasFocusReader t m, HasDisplayRegion t m, HasImageWriter t m, HasInput t m)
39 => ButtonConfig t
38 => ButtonConfig t
40 -> m ()
39 -> m ()
41 -> m (Event t ())
40 -> m (Event t ())
@@ -53,7 +52,7 @@ button cfg child = do
53
52
54-- | A button widget that displays text that can change
53-- | A button widget that displays text that can change
55textButton
54textButton
56− :: (Reflex t, Monad m, MonadNodeId m, HasDisplayRegion t m, HasFocusReader t m, HasImageWriter t m, HasInput t m)
55+ :: (Reflex t, Monad m, HasDisplayRegion t m, HasFocusReader t m, HasImageWriter t m, HasInput t m)
57 => ButtonConfig t
56 => ButtonConfig t
58 -> Behavior t Text
57 -> Behavior t Text
59 -> m (Event t ())
58 -> m (Event t ())
@@ -61,7 +60,7 @@ textButton cfg = button cfg . text -- TODO Centering etc.
61
60
62-- | A button widget that displays a static bit of text
61-- | A button widget that displays a static bit of text
63textButtonStatic
62textButtonStatic
64− :: (Reflex t, Monad m, MonadNodeId m, HasDisplayRegion t m, HasFocusReader t m, HasImageWriter t m, HasInput t m)
63+ :: (Reflex t, Monad m, HasDisplayRegion t m, HasFocusReader t m, HasImageWriter t m, HasInput t m)
65 => ButtonConfig t
64 => ButtonConfig t
66 -> Text
65 -> Text
67 -> m (Event t ())
66 -> m (Event t ())
src/Reflex/Vty/Widget/Input/Text.hs+1−2
@@ -9,7 +9,6 @@ module Reflex.Vty.Widget.Input.Text
9
9
10import Control.Monad (join)
10import Control.Monad (join)
11import Control.Monad.Fix (MonadFix)
11import Control.Monad.Fix (MonadFix)
12−import Control.Monad.NodeId (MonadNodeId)
13import Data.Default (Default(..))
12import Data.Default (Default(..))
14import Data.Text (Text)
13import Data.Text (Text)
15import Data.Text.Zipper
14import Data.Text.Zipper
@@ -100,7 +99,7 @@ multilineTextInput cfg = do
100-- the computed line count to greedily size the tile when vertically
99-- the computed line count to greedily size the tile when vertically
101-- oriented, and uses the fallback width when horizontally oriented.
100-- oriented, and uses the fallback width when horizontally oriented.
102textInputTile
101textInputTile
103− :: (Monad m, MonadNodeId m, Reflex t, MonadFix m, HasLayout t m, HasInput t m, HasFocus t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
102+ :: (Monad m, Reflex t, MonadFix m, HasLayout t m, HasInput t m, HasFocus t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
104 => m (TextInput t)
103 => m (TextInput t)
105 -> Dynamic t Int
104 -> Dynamic t Int
106 -> m (TextInput t)
105 -> m (TextInput t)
src/Reflex/Vty/Widget/Layout.hs+9−8
@@ -184,7 +184,7 @@ anyChildFocused f = do
184
184
185-- | Request focus be shifted backward and forward based on tab presses. <Tab>
185-- | Request focus be shifted backward and forward based on tab presses. <Tab>
186-- shifts focus forward and <Shift+Tab> shifts focus backward.
186-- shifts focus forward and <Shift+Tab> shifts focus backward.
187−tabNavigation :: (Reflex t, MonadNodeId m, HasInput t m, HasFocus t m) => m ()
187+tabNavigation :: (Reflex t, HasInput t m, HasFocus t m) => m ()
188tabNavigation = do
188tabNavigation = do
189 fwd <- fmap (const 1) <$> key (V.KChar '\t')
189 fwd <- fmap (const 1) <$> key (V.KChar '\t')
190 back <- fmap (const (-1)) <$> key V.KBackTab
190 back <- fmap (const (-1)) <$> key V.KBackTab
@@ -242,14 +242,14 @@ data Orientation = Orientation_Column
242
242
243-- | Create a row-oriented 'axis'
243-- | Create a row-oriented 'axis'
244row
244row
245− :: (Reflex t, MonadNodeId m, MonadFix m, HasLayout t m)
245+ :: (Reflex t, MonadFix m, HasLayout t m)
246 => m a
246 => m a
247 -> m a
247 -> m a
248row = axis (pure Orientation_Row) flex
248row = axis (pure Orientation_Row) flex
249
249
250-- | Create a column-oriented 'axis'
250-- | Create a column-oriented 'axis'
251col
251col
252− :: (Reflex t, MonadNodeId m, MonadFix m, HasLayout t m)
252+ :: (Reflex t, MonadFix m, HasLayout t m)
253 => m a
253 => m a
254 -> m a
254 -> m a
255col = axis (pure Orientation_Column) flex
255col = axis (pure Orientation_Column) flex
@@ -433,14 +433,15 @@ instance (HasFocusReader t m, Monad m) => HasFocusReader t (Layout t m)
433instance (Monad m, MonadNodeId m, Reflex t, MonadFix m) => HasLayout t (Layout t m) where
433instance (Monad m, MonadNodeId m, Reflex t, MonadFix m) => HasLayout t (Layout t m) where
434 axis o c (Layout x) = Layout $ do
434 axis o c (Layout x) = Layout $ do
435 nodeId <- getNextNodeId
435 nodeId <- getNextNodeId
436+ let dummyParentLayout = LayoutTree (nilRegion, Orientation_Column) mempty
436− (result, forest) <- lift $ local (\t -> fromMaybe (LayoutTree (Region 0 0 0 0, Orientation_Column) mempty) . lookupLF nodeId . childrenLT <$> t) $ runDynamicWriterT x
437+ (result, forest) <- lift $ local (\t -> fromMaybe dummyParentLayout . lookupLF nodeId . childrenLT <$> t) $ runDynamicWriterT x
437 tellDyn $ singletonLF nodeId <$> (LayoutTree <$> ((,) <$> c <*> o) <*> forest)
438 tellDyn $ singletonLF nodeId <$> (LayoutTree <$> ((,) <$> c <*> o) <*> forest)
438 pure result
439 pure result
439 region c = do
440 region c = do
440 nodeId <- lift getNextNodeId
441 nodeId <- lift getNextNodeId
441 Layout $ tellDyn $ ffor c $ \c' -> singletonLF nodeId $ LayoutTree (c', Orientation_Row) mempty
442 Layout $ tellDyn $ ffor c $ \c' -> singletonLF nodeId $ LayoutTree (c', Orientation_Row) mempty
442 solutions <- Layout ask
443 solutions <- Layout ask
443− pure $ maybe (Region 0 0 0 0) (fst . rootLT) . lookupLF nodeId . childrenLT <$> solutions
444+ pure $ maybe nilRegion (fst . rootLT) . lookupLF nodeId . childrenLT <$> solutions
444 askOrientation = Layout $ asks $ fmap (snd . rootLT)
445 askOrientation = Layout $ asks $ fmap (snd . rootLT)
445
446
446instance (MonadFix m, HasFocus t m) => HasFocus t (Layout t m) where
447instance (MonadFix m, HasFocus t m) => HasFocus t (Layout t m) where
@@ -505,7 +506,7 @@ initManager_ = fmap fst . initManager
505-- provided constraint. Returns the 'FocusId' allowing for manual focus
506-- provided constraint. Returns the 'FocusId' allowing for manual focus
506-- management.
507-- management.
507tile'
508tile'
508− :: (MonadNodeId m, MonadFix m, Reflex t, HasInput t m, HasFocus t m, HasLayout t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
509+ :: (MonadFix m, Reflex t, HasInput t m, HasFocus t m, HasLayout t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
509 => Dynamic t Constraint
510 => Dynamic t Constraint
510 -> m a
511 -> m a
511 -> m (FocusId, a)
512 -> m (FocusId, a)
@@ -524,7 +525,7 @@ tile' c w = do
524-- | A widget that is focusable and occupies a layout region based on the
525-- | A widget that is focusable and occupies a layout region based on the
525-- provided constraint.
526-- provided constraint.
526tile
527tile
527− :: (MonadNodeId m, MonadFix m, Reflex t, HasInput t m, HasFocus t m, HasLayout t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
528+ :: (MonadFix m, Reflex t, HasInput t m, HasFocus t m, HasLayout t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
528 => Dynamic t Constraint
529 => Dynamic t Constraint
529 -> m a
530 -> m a
530 -> m a
531 -> m a
@@ -535,7 +536,7 @@ tile c = fmap snd . tile' c
535-- | A widget that is not focusable and occupies a layout region based on the
536-- | A widget that is not focusable and occupies a layout region based on the
536-- provided constraint.
537-- provided constraint.
537grout
538grout
538− :: (Reflex t, MonadNodeId m, HasLayout t m, HasInput t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
539+ :: (Reflex t, HasLayout t m, HasInput t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
539 => Dynamic t Constraint
540 => Dynamic t Constraint
540 -> m a
541 -> m a
541 -> m a
542 -> m a
src/Reflex/Vty/Widget/Split.hs+3−4
@@ -5,7 +5,6 @@ module Reflex.Vty.Widget.Split where
5
5
6import Control.Applicative
6import Control.Applicative
7import Control.Monad.Fix
7import Control.Monad.Fix
8−import Control.Monad.NodeId
9import Graphics.Vty as V
8import Graphics.Vty as V
10import Reflex
9import Reflex
11import Reflex.Vty.Widget
10import Reflex.Vty.Widget
@@ -14,7 +13,7 @@ import Reflex.Vty.Widget.Input.Mouse
14-- | A split of the available space into two parts with a draggable separator.
13-- | A split of the available space into two parts with a draggable separator.
15-- Starts with half the space allocated to each, and the first pane has focus.
14-- Starts with half the space allocated to each, and the first pane has focus.
16-- Clicking in a pane switches focus.
15-- Clicking in a pane switches focus.
17−splitVDrag :: (Reflex t, MonadFix m, MonadHold t m, MonadNodeId m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasFocusReader t m)
16+splitVDrag :: (Reflex t, MonadFix m, MonadHold t m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasFocusReader t m)
18 => m ()
17 => m ()
19 -> m a
18 -> m a
20 -> m b
19 -> m b
@@ -53,7 +52,7 @@ splitVDrag wS wA wB = do
53
52
54-- | A plain split of the available space into vertically stacked panes.
53-- | A plain split of the available space into vertically stacked panes.
55-- No visual separator is built in here.
54-- No visual separator is built in here.
56−splitV :: (Reflex t, Monad m, MonadNodeId m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasFocusReader t m)
55+splitV :: (Reflex t, Monad m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasFocusReader t m)
57 => Dynamic t (Int -> Int)
56 => Dynamic t (Int -> Int)
58 -- ^ Function used to determine size of first pane based on available size
57 -- ^ Function used to determine size of first pane based on available size
59 -> Dynamic t (Bool, Bool)
58 -> Dynamic t (Bool, Bool)
@@ -74,7 +73,7 @@ splitV sizeFunD focD wA wB = do
74
73
75-- | A plain split of the available space into horizontally stacked panes.
74-- | A plain split of the available space into horizontally stacked panes.
76-- No visual separator is built in here.
75-- No visual separator is built in here.
77−splitH :: (Reflex t, Monad m, MonadNodeId m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasFocusReader t m)
76+splitH :: (Reflex t, Monad m, HasDisplayRegion t m, HasInput t m, HasImageWriter t m, HasFocusReader t m)
78 => Dynamic t (Int -> Int)
77 => Dynamic t (Int -> Int)
79 -- ^ Function used to determine size of first pane based on available size
78 -- ^ Function used to determine size of first pane based on available size
80 -> Dynamic t (Bool, Bool)
79 -> Dynamic t (Bool, Bool)