@@ -8,12 +8,12 @@ Description: Monad transformer and tools for arranging widgets and building scre
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9{-# LANGUAGE LambdaCase #-}
9{-# LANGUAGE LambdaCase #-}
10{-# LANGUAGE MultiParamTypeClasses #-}
10{-# LANGUAGE MultiParamTypeClasses #-}
11+{-# LANGUAGE RankNTypes #-}
11{-# LANGUAGE RecordWildCards #-}
12{-# LANGUAGE RecordWildCards #-}
12{-# LANGUAGE RecursiveDo #-}
13{-# LANGUAGE RecursiveDo #-}
14+{-# LANGUAGE ScopedTypeVariables #-}
15+{-# LANGUAGE TypeApplications #-}
13{-# LANGUAGE UndecidableInstances #-}
16{-# LANGUAGE UndecidableInstances #-}
14−{-# LANGUAGE TypeApplications #-}
15−{-# LANGUAGE RankNTypes #-}
16−{-# LANGUAGE ScopedTypeVariables #-}
19module Reflex.Vty.Widget.Layout
19module Reflex.Vty.Widget.Layout
@@ -50,7 +50,7 @@ import Data.Bimap (Bimap)
50import qualified Data.Bimap as Bimap
50import qualified Data.Bimap as Bimap
51import Data.Default (Default (..))
51import Data.Default (Default (..))
52import qualified Data.Dependent.Map as DMap
52import qualified Data.Dependent.Map as DMap
53−import Data.Dependent.Sum (DSum((:=>)))
53+import Data.Dependent.Sum (DSum ((:=>)))
54import Data.Functor.Misc
54import Data.Functor.Misc
55import Data.Map (Map)
55import Data.Map (Map)
56import qualified Data.Map as Map
56import qualified Data.Map as Map
@@ -68,20 +68,20 @@ import Reflex.Vty.Widget
69-- | The main-axis orientation of a 'Layout' widget
69-- | The main-axis orientation of a 'Layout' widget
70data Orientation = Orientation_Column
70data Orientation = Orientation_Column
71− | Orientation_Row
71+ | Orientation_Row
72− deriving (Show, Read, Eq, Ord)
72+ deriving (Show, Read, Eq, Ord)
74data LayoutSegment = LayoutSegment
74data LayoutSegment = LayoutSegment
75− { _layoutSegment_offset :: Int
75+ { _layoutSegment_offset :: Int
76− , _layoutSegment_size :: Int
76+ , _layoutSegment_size :: Int
79data LayoutCtx t = LayoutCtx
79data LayoutCtx t = LayoutCtx
80− { _layoutCtx_regions :: Dynamic t (Map NodeId LayoutSegment)
80+ { _layoutCtx_regions :: Dynamic t (Map NodeId LayoutSegment)
81− , _layoutCtx_focusSelfDemux :: Demux t (Maybe NodeId)
81+ , _layoutCtx_focusSelfDemux :: Demux t (Maybe NodeId)
82− , _layoutCtx_orientation :: Dynamic t Orientation
82+ , _layoutCtx_orientation :: Dynamic t Orientation
83− , _layoutCtx_focusChildSelector :: EventSelector t (Const2 NodeId (Maybe Int))
83+ , _layoutCtx_focusChildSelector :: EventSelector t (Const2 NodeId (Maybe Int))
87-- | The Layout monad transformer keeps track of the configuration (e.g., 'Orientation') and
87-- | The Layout monad transformer keeps track of the configuration (e.g., 'Orientation') and
@@ -138,7 +138,7 @@ fanFocusEv :: (Reflex t) => Behavior t (Maybe (NodeId, Int)) -> Event t (Maybe (
138fanFocusEv focussed focusReqIx = fan $ attachWith attachfn focussed focusReqIx where
138fanFocusEv focussed focusReqIx = fan $ attachWith attachfn focussed focusReqIx where
139 attachfn mkv0 mkv1 = case mkv1 of
139 attachfn mkv0 mkv1 = case mkv1 of
140 Nothing -> case mkv0 of
140 Nothing -> case mkv0 of
141− Nothing -> DMap.empty
141+ Nothing -> DMap.empty
142 Just (k0,_) -> DMap.fromList [Const2 k0 :=> Identity Nothing]
142 Just (k0,_) -> DMap.fromList [Const2 k0 :=> Identity Nothing]
143 Just (k1,v1) -> case mkv0 of
143 Just (k1,v1) -> case mkv0 of
144 Nothing -> DMap.fromList [Const2 k1 :=> Identity (Just v1)]
144 Nothing -> DMap.fromList [Const2 k1 :=> Identity (Just v1)]
@@ -307,11 +307,11 @@ tile = tile_
308-- | Configuration options for and constraints on 'tile_'
308-- | Configuration options for and constraints on 'tile_'
309data TileConfig t = TileConfig
309data TileConfig t = TileConfig
310− { _tileConfig_constraint :: Dynamic t Constraint
310+ { _tileConfig_constraint :: Dynamic t Constraint
311 -- ^ 'Constraint' on the tile_'s size
311 -- ^ 'Constraint' on the tile_'s size
312− , _tile_Config_focusable :: Dynamic t Bool
312+ , _tile_Config_focusable :: Dynamic t Bool
313 -- ^ Whether the tile_ is focusable
313 -- ^ Whether the tile_ is focusable
316instance Reflex t => Default (TileConfig t) where
316instance Reflex t => Default (TileConfig t) where
317 def = TileConfig (pure $ Constraint_Min 0) (pure True)
317 def = TileConfig (pure $ Constraint_Min 0) (pure True)
@@ -430,8 +430,8 @@ askOrientation = Layout $ asks _layoutCtx_orientation
431-- | Datatype representing constraints on a widget's size along the main axis (see 'Orientation')
431-- | Datatype representing constraints on a widget's size along the main axis (see 'Orientation')
432data Constraint = Constraint_Fixed Int
432data Constraint = Constraint_Fixed Int
433− | Constraint_Min Int
433+ | Constraint_Min Int
434− deriving (Show, Read, Eq, Ord)
434+ deriving (Show, Read, Eq, Ord)
436-- | Compute the size of each widget "@k@" based on the total set of 'Constraint's
436-- | Compute the size of each widget "@k@" based on the total set of 'Constraint's
437computeSizes
437computeSizes
@@ -460,7 +460,8 @@ computeEdges = fst . Map.foldlWithKey' (\(m, offset) k (a, sz) ->
460-- TODO FINISH
460-- TODO FINISH
461-- but it's weird cuz a leaf node won't know it's PosDim until combined with a Region...
461-- but it's weird cuz a leaf node won't know it's PosDim until combined with a Region...
462-- | Dynamic sizing information on a layout hierarchy (intended for testing)
462-- | Dynamic sizing information on a layout hierarchy (intended for testing)
463−data LayoutDebugTree t = LayoutDebugTree_Branch [LayoutDebugTree t] | LayoutDebugTree_Leaf
463+data LayoutDebugTree t = LayoutDebugTree_Branch [LayoutDebugTree t]
464+ | LayoutDebugTree_Leaf
465emptyLayoutDebugTree :: LayoutDebugTree t
466emptyLayoutDebugTree :: LayoutDebugTree t
466emptyLayoutDebugTree = LayoutDebugTree_Leaf
467emptyLayoutDebugTree = LayoutDebugTree_Leaf
@@ -471,12 +472,12 @@ class IsLayoutReturn t b a where
471 getLayoutFocussedDyn :: b -> Dynamic t (Maybe Int)
472 getLayoutFocussedDyn :: b -> Dynamic t (Maybe Int)
472 getLayoutTree :: b -> LayoutDebugTree t
473 getLayoutTree :: b -> LayoutDebugTree t
474−data LayoutReturnData t a = LayoutReturnData {
475+data LayoutReturnData t a = LayoutReturnData
475− _layoutReturnData_tree :: LayoutDebugTree t
476+ { _layoutReturnData_tree :: LayoutDebugTree t
476− , _layoutReturnData_focus :: Dynamic t (Maybe Int)
477+ , _layoutReturnData_focus :: Dynamic t (Maybe Int)
477 , _layoutReturnData_children :: Int
478 , _layoutReturnData_children :: Int
478− , _layoutReturnData_value :: a
479+ , _layoutReturnData_value :: a
481instance IsLayoutReturn t (LayoutReturnData t a) a where
482instance IsLayoutReturn t (LayoutReturnData t a) a where
482 getLayoutResult lrd = _layoutReturnData_value lrd
483 getLayoutResult lrd = _layoutReturnData_value lrd