on develop help sign in
Remove extra MonadNodeId constraints; Fix a few things pointed out in review
commit478b1f0d5280c9012df64d6917150fc1958a4c96 authorAli Abrar <aliabrar@gmail.com> dateFri 9 Apr 2021, 21:33 (6 years ago) parent3f34308
8 files changed+25−28
src-bin/Example/CPU.hs−2 src-bin/example.hs+1−3 src/Reflex/Vty/Widget.hs+5−1 src/Reflex/Vty/Widget/Box.hs+3−4 src/Reflex/Vty/Widget/Input.hs+3−4 src/Reflex/Vty/Widget/Input/Text.hs+1−2 src/Reflex/Vty/Widget/Layout.hs+9−8 src/Reflex/Vty/Widget/Split.hs+3−4
src-bin/Example/CPU.hs−2
@@ -99,7 +99,6 @@ cpuStats
9999 , HasImageWriter t m
100100 , HasLayout t m
101101 , HasFocus t m
102− , MonadNodeId m
103102 , HasInput t m
104103 , HasFocusReader t m
105104 )
@@ -120,7 +119,6 @@ chart
120119 :: ( MonadFix m
121120 , HasFocus t m
122121 , HasLayout t m
123− , MonadNodeId m
124122 , HasImageWriter t m
125123 , HasInput t m
126124 , HasDisplayRegion t m
src-bin/example.hs+1−3
@@ -1,7 +1,6 @@
11import Control.Applicative
22import Control.Monad
33import Control.Monad.Fix
4−import Control.Monad.NodeId
54import Data.Functor
65import Data.Functor.Misc
76import Data.Map (Map)
@@ -22,7 +21,6 @@ type VtyExample t m =
2221 , Reflex t
2322 , HasInput t m
2423 , HasImageWriter t m
25− , MonadNodeId m
2624 , HasDisplayRegion t m
2725 , HasFocus t m
2826 , HasFocusReader t m
@@ -235,7 +233,7 @@ scrolling = col $ do
235233-- * Text editor example with resizable boxes
236234
237235testBoxes
238− :: (MonadHold t m, MonadNodeId m, VtyExample t m)
236+ :: (MonadHold t m, VtyExample t m)
239237 => m ()
240238testBoxes = do
241239 dw <- displayWidth
src/Reflex/Vty/Widget.hs+5−1
@@ -224,6 +224,10 @@ data Region = Region
224224 }
225225 deriving (Show, Read, Eq, Ord)
226226
227+-- | A region that occupies no space.
228+nilRegion :: Region
229+nilRegion = Region 0 0 0 0
230+
227231-- | The width and height of a 'Region'
228232regionSize :: Region -> (Int, Int)
229233regionSize (Region _ _ w h) = (w, h)
@@ -467,7 +471,7 @@ imagesInRegion reg = liftA2 (\r is -> map (withinImage r) is) reg
467471-- * mouse inputs inside the region have their coordinates translated such
468472-- that (0,0) is the top-left corner of the region
469473pane
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)
471475 => Dynamic t Region
472476 -> Dynamic t Bool -- ^ Whether the widget should be focused when the parent is.
473477 -> m a
src/Reflex/Vty/Widget/Box.hs+3−4
@@ -3,7 +3,6 @@
33-}
44module Reflex.Vty.Widget.Box where
55
6−import Control.Monad.NodeId
76import Data.Default
87import Data.Text (Text)
98import qualified Data.Text as T
@@ -55,7 +54,7 @@ roundedBoxStyle :: BoxStyle
5554roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
5655
5756-- | 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)
5958 => Behavior t BoxStyle
6059 -> Behavior t Text
6160 -> m a
@@ -107,7 +106,7 @@ boxTitle boxStyle title child = do
107106 right = mkHalf delta
108107
109108-- | 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)
111110 => Behavior t BoxStyle
112111 -> m a
113112 -> m a
@@ -115,7 +114,7 @@ box boxStyle = boxTitle boxStyle mempty
115114
116115-- | A box whose style is static
117116boxStatic
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)
119118 => BoxStyle
120119 -> m a
121120 -> m a
src/Reflex/Vty/Widget/Input.hs+3−4
@@ -13,7 +13,6 @@ import Reflex.Vty.Widget.Input.Text as Export
1313
1414import Control.Monad (join)
1515import Control.Monad.Fix (MonadFix)
16−import Control.Monad.NodeId (MonadNodeId)
1716import Data.Default (Default(..))
1817import Data.Text (Text)
1918import qualified Graphics.Vty as V
@@ -35,7 +34,7 @@ instance Reflex t => Default (ButtonConfig t) where
3534
3635-- | A button widget that contains a sub-widget
3736button
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)
3938 => ButtonConfig t
4039 -> m ()
4140 -> m (Event t ())
@@ -53,7 +52,7 @@ button cfg child = do
5352
5453-- | A button widget that displays text that can change
5554textButton
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)
5756 => ButtonConfig t
5857 -> Behavior t Text
5958 -> m (Event t ())
@@ -61,7 +60,7 @@ textButton cfg = button cfg . text -- TODO Centering etc.
6160
6261-- | A button widget that displays a static bit of text
6362textButtonStatic
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)
6564 => ButtonConfig t
6665 -> Text
6766 -> m (Event t ())
src/Reflex/Vty/Widget/Input/Text.hs+1−2
@@ -9,7 +9,6 @@ module Reflex.Vty.Widget.Input.Text
99
1010import Control.Monad (join)
1111import Control.Monad.Fix (MonadFix)
12−import Control.Monad.NodeId (MonadNodeId)
1312import Data.Default (Default(..))
1413import Data.Text (Text)
1514import Data.Text.Zipper
@@ -100,7 +99,7 @@ multilineTextInput cfg = do
10099-- the computed line count to greedily size the tile when vertically
101100-- oriented, and uses the fallback width when horizontally oriented.
102101textInputTile
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)
104103 => m (TextInput t)
105104 -> Dynamic t Int
106105 -> m (TextInput t)
src/Reflex/Vty/Widget/Layout.hs+9−8
@@ -184,7 +184,7 @@ anyChildFocused f = do
184184
185185-- | Request focus be shifted backward and forward based on tab presses. <Tab>
186186-- 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 ()
188188tabNavigation = do
189189 fwd <- fmap (const 1) <$> key (V.KChar '\t')
190190 back <- fmap (const (-1)) <$> key V.KBackTab
@@ -242,14 +242,14 @@ data Orientation = Orientation_Column
242242
243243-- | Create a row-oriented 'axis'
244244row
245− :: (Reflex t, MonadNodeId m, MonadFix m, HasLayout t m)
245+ :: (Reflex t, MonadFix m, HasLayout t m)
246246 => m a
247247 -> m a
248248row = axis (pure Orientation_Row) flex
249249
250250-- | Create a column-oriented 'axis'
251251col
252− :: (Reflex t, MonadNodeId m, MonadFix m, HasLayout t m)
252+ :: (Reflex t, MonadFix m, HasLayout t m)
253253 => m a
254254 -> m a
255255col = axis (pure Orientation_Column) flex
@@ -433,14 +433,15 @@ instance (HasFocusReader t m, Monad m) => HasFocusReader t (Layout t m)
433433instance (Monad m, MonadNodeId m, Reflex t, MonadFix m) => HasLayout t (Layout t m) where
434434 axis o c (Layout x) = Layout $ do
435435 nodeId <- getNextNodeId
436− (result, forest) <- lift $ local (\t -> fromMaybe (LayoutTree (Region 0 0 0 0, Orientation_Column) mempty) . lookupLF nodeId . childrenLT <$> t) $ runDynamicWriterT x
436+ let dummyParentLayout = LayoutTree (nilRegion, Orientation_Column) mempty
437+ (result, forest) <- lift $ local (\t -> fromMaybe dummyParentLayout . lookupLF nodeId . childrenLT <$> t) $ runDynamicWriterT x
437438 tellDyn $ singletonLF nodeId <$> (LayoutTree <$> ((,) <$> c <*> o) <*> forest)
438439 pure result
439440 region c = do
440441 nodeId <- lift getNextNodeId
441442 Layout $ tellDyn $ ffor c $ \c' -> singletonLF nodeId $ LayoutTree (c', Orientation_Row) mempty
442443 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
444445 askOrientation = Layout $ asks $ fmap (snd . rootLT)
445446
446447instance (MonadFix m, HasFocus t m) => HasFocus t (Layout t m) where
@@ -505,7 +506,7 @@ initManager_ = fmap fst . initManager
505506-- provided constraint. Returns the 'FocusId' allowing for manual focus
506507-- management.
507508tile'
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)
509510 => Dynamic t Constraint
510511 -> m a
511512 -> m (FocusId, a)
@@ -524,7 +525,7 @@ tile' c w = do
524525-- | A widget that is focusable and occupies a layout region based on the
525526-- provided constraint.
526527tile
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)
528529 => Dynamic t Constraint
529530 -> m a
530531 -> m a
@@ -535,7 +536,7 @@ tile c = fmap snd . tile' c
535536-- | A widget that is not focusable and occupies a layout region based on the
536537-- provided constraint.
537538grout
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)
539540 => Dynamic t Constraint
540541 -> m a
541542 -> m a
src/Reflex/Vty/Widget/Split.hs+3−4
@@ -5,7 +5,6 @@ module Reflex.Vty.Widget.Split where
55
66import Control.Applicative
77import Control.Monad.Fix
8−import Control.Monad.NodeId
98import Graphics.Vty as V
109import Reflex
1110import Reflex.Vty.Widget
@@ -14,7 +13,7 @@ import Reflex.Vty.Widget.Input.Mouse
1413-- | A split of the available space into two parts with a draggable separator.
1514-- Starts with half the space allocated to each, and the first pane has focus.
1615-- 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)
1817 => m ()
1918 -> m a
2019 -> m b
@@ -53,7 +52,7 @@ splitVDrag wS wA wB = do
5352
5453-- | A plain split of the available space into vertically stacked panes.
5554-- 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)
5756 => Dynamic t (Int -> Int)
5857 -- ^ Function used to determine size of first pane based on available size
5958 -> Dynamic t (Bool, Bool)
@@ -74,7 +73,7 @@ splitV sizeFunD focD wA wB = do
7473
7574-- | A plain split of the available space into horizontally stacked panes.
7675-- 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)
7877 => Dynamic t (Int -> Int)
7978 -- ^ Function used to determine size of first pane based on available size
8079 -> Dynamic t (Bool, Bool)