{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Brick.Panes
(
Pane
, PaneState
, InitConstraints
, initPaneState
, DrawConstraints
, drawPane
, EventConstraints
, EventType
, DispatchEvent
, focusable
, handlePaneEvent
, UpdateType
, updatePane
, focus1If
, HasFocus
, getFocus
, Focused(Focused)
, focused
, Panel
, basePanel
, addToPanel
, PaneFocus( Always, Never, WhenFocused, WhenFocusedModal
, WhenFocusedModalHandlingAllEvents
)
, onPane
, onBaseState
, panelDraw
, handleFocusAndPanelEvents
, focusRingUpdate
, isPanelModal
, enteredModal
, exitedModal
, PanelMode(Normal, Modal)
, PanelTransition
, PanelOps(..)
, PaneNumber
)
where
import Control.Applicative ( (<|>) )
import qualified Data.Foldable as F
import Data.Kind ( Constraint, Type )
import qualified Data.List as L
import Data.Maybe ( fromMaybe )
import Data.Sequence ( Seq, (><) )
import qualified Data.Sequence as Seq
import Data.Type.Equality
import Data.Void ( Void, absurd )
import GHC.TypeLits
import qualified Graphics.Vty as Vty
import Lens.Micro
#if !MIN_VERSION_base(4,16,0)
import Numeric.Natural ( Natural )
#endif
import Brick
import Brick.Focus
class Pane n appEv pane | pane -> n where
data PaneState pane appEv
type UpdateType pane
type InitConstraints pane initctxt :: Constraint
initPaneState :: (InitConstraints pane i) => i -> PaneState pane appEv
type DrawConstraints pane drwctxt n :: Constraint
drawPane :: (DrawConstraints pane drawcontext n, Eq n)
=> PaneState pane appEv -> drawcontext -> Maybe (Widget n)
type EventConstraints pane evctxt :: Constraint
type EventType pane n appEv
focusable :: (EventConstraints pane eventcontext, Eq n)
=> eventcontext -> PaneState pane appEv -> Seq.Seq n
handlePaneEvent :: (EventConstraints pane eventcontext, Eq n)
=> eventcontext
-> EventType pane n appEv
-> PaneState pane appEv
-> EventM n es (PaneState pane appEv)
updatePane :: UpdateType pane
-> PaneState pane appEv
-> PaneState pane appEv
type UpdateType pane = ()
type InitConstraints pane initctxt = ()
type DrawConstraints pane drwctxt n = ()
type EventConstraints pane evctxt = ()
type EventType pane n appev = Vty.Event
focusable eventcontext
_ PaneState pane appEv
_ = forall a. Monoid a => a
mempty
handlePaneEvent eventcontext
_ EventType pane n appEv
_ = forall (m :: * -> *) a. Monad m => a -> m a
return
updatePane UpdateType pane
_ = forall a. a -> a
id
focus1If :: n -> Bool -> Seq.Seq n
focus1If :: forall n. n -> Bool -> Seq n
focus1If n
n Bool
b = if Bool
b then forall a. a -> Seq a
Seq.singleton n
n else forall a. Monoid a => a
mempty
class HasFocus b n | b -> n where
getFocus :: Lens' b (Focused n)
getFocus Focused n -> f (Focused n)
f b
x = forall a b. a -> b -> a
const b
x forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Focused n -> f (Focused n)
f (forall n. Maybe n -> Focused n
Focused forall a. Maybe a
Nothing)
newtype Focused n = Focused { forall n. Focused n -> Maybe n
focused :: Maybe n
}
class DispatchEvent n appev pane evtype where
dispEv :: ( Pane n appev pane
, EventConstraints pane base
, Eq n
)
=> EventType pane n appev :~: evtype
-> base -> BrickEvent n appev -> PaneState pane appev
-> EventM n es (PaneState pane appev)
instance DispatchEvent n appev pane (BrickEvent n appev) where
dispEv :: forall base es.
(Pane n appev pane, EventConstraints pane base, Eq n) =>
(EventType pane n appev :~: BrickEvent n appev)
-> base
-> BrickEvent n appev
-> PaneState pane appev
-> EventM n es (PaneState pane appev)
dispEv EventType pane n appev :~: BrickEvent n appev
Refl base
base BrickEvent n appev
ev PaneState pane appev
s = forall n appEv pane eventcontext es.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext
-> EventType pane n appEv
-> PaneState pane appEv
-> EventM n es (PaneState pane appEv)
handlePaneEvent base
base BrickEvent n appev
ev PaneState pane appev
s
instance DispatchEvent n appev pane Vty.Event where
dispEv :: forall base es.
(Pane n appev pane, EventConstraints pane base, Eq n) =>
(EventType pane n appev :~: Event)
-> base
-> BrickEvent n appev
-> PaneState pane appev
-> EventM n es (PaneState pane appev)
dispEv EventType pane n appev :~: Event
Refl base
base BrickEvent n appev
ev PaneState pane appev
s = case BrickEvent n appev
ev of
VtyEvent Event
vev -> forall n appEv pane eventcontext es.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext
-> EventType pane n appEv
-> PaneState pane appEv
-> EventM n es (PaneState pane appEv)
handlePaneEvent base
base Event
vev PaneState pane appev
s
BrickEvent n appev
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return PaneState pane appev
s
data Panel n appev state (panes :: [Type]) where
Panel :: state -> Panel n appev state '[]
PanelWith :: ( Pane n appev pane
, DrawConstraints pane (Panel n appev state panes) n
, EventConstraints pane (Panel n appev state panes)
, DispatchEvent n appev pane (EventType pane n appev)
)
=> PaneState pane appev -> PaneFocus n
-> Panel n appev state panes -> Panel n appev state (pane ': panes)
basePanel :: state -> Panel n appev state '[]
basePanel :: forall state n appev. state -> Panel n appev state '[]
basePanel = forall state n appev. state -> Panel n appev state '[]
Panel
addToPanel :: Pane n appev pane
=> InitConstraints pane (Panel n appev state panes)
=> DrawConstraints pane (Panel n appev state panes) n
=> EventConstraints pane (Panel n appev state panes)
=> DispatchEvent n appev pane (EventType pane n appev)
=> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane ': panes)
addToPanel :: forall n appev pane state (panes :: [*]).
(Pane n appev pane,
InitConstraints pane (Panel n appev state panes),
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneFocus n
-> Panel n appev state panes -> Panel n appev state (pane : panes)
addToPanel PaneFocus n
n Panel n appev state panes
pnl = forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith (forall n appEv pane i.
(Pane n appEv pane, InitConstraints pane i) =>
i -> PaneState pane appEv
initPaneState Panel n appev state panes
pnl) PaneFocus n
n Panel n appev state panes
pnl
data PaneFocus n =
Always
| Never
| WhenFocused
| WhenFocusedModal
| WhenFocusedModal' (FocusRing n)
| WhenFocusedModalHandlingAllEvents
| WhenFocusedModalHandlingAllEvents' (FocusRing n)
instance HasFocus appState n => HasFocus (Panel n appEv appState panes) n where
getFocus :: Lens' (Panel n appEv appState panes) (Focused n)
getFocus = forall n appev state (panes :: [*]).
Lens' (Panel n appev state panes) state
onBaseState forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b n. HasFocus b n => Lens' b (Focused n)
getFocus
onBaseState :: Lens' (Panel n appev state panes) state
onBaseState :: forall n appev state (panes :: [*]).
Lens' (Panel n appev state panes) state
onBaseState state -> f state
f (Panel state
s) = forall state n appev. state -> Panel n appev state '[]
Panel forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> state -> f state
f state
s
onBaseState state -> f state
f (PanelWith PaneState pane appev
p PaneFocus n
n Panel n appev state panes
i) = forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
p PaneFocus n
n forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n appev state (panes :: [*]).
Lens' (Panel n appev state panes) state
onBaseState state -> f state
f Panel n appev state panes
i
onPane :: forall pane n appev state panes .
PanelOps pane n appev panes state
=> Lens' (Panel n appev state panes) (PaneState pane appev)
onPane :: forall pane n appev state (panes :: [*]).
PanelOps pane n appev panes state =>
Lens' (Panel n appev state panes) (PaneState pane appev)
onPane = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes -> PaneState pane appev
panelState @pane) (forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes
-> PaneState pane appev -> Panel n appev s panes
panelStateUpdate @pane)
class PanelOps pane n appev panes s | pane -> n where
handlePanelEvent :: (EventConstraints pane s, Eq n)
=> s -> pane -> Panel n appev s panes -> BrickEvent n appev
-> EventM n es (Panel n appev s panes)
panelState :: Panel n appev s panes -> PaneState pane appev
panelStateUpdate :: Panel n appev s panes -> PaneState pane appev
-> Panel n appev s panes
paneNumber :: Panel n appev s panes -> PaneNumber
instance (Pane n appev pane) => PanelOps pane n appev (pane ': panes) s where
handlePanelEvent :: forall es.
(EventConstraints pane s, Eq n) =>
s
-> pane
-> Panel n appev s (pane : panes)
-> BrickEvent n appev
-> EventM n es (Panel n appev s (pane : panes))
handlePanelEvent s
s pane
_p (PanelWith PaneState pane appev
pd PaneFocus n
n Panel n appev s panes
r) BrickEvent n appev
ev =
(\PaneState pane appev
pd' -> forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd' PaneFocus n
n Panel n appev s panes
r) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n appev pane evtype base es.
(DispatchEvent n appev pane evtype, Pane n appev pane,
EventConstraints pane base, Eq n) =>
(EventType pane n appev :~: evtype)
-> base
-> BrickEvent n appev
-> PaneState pane appev
-> EventM n es (PaneState pane appev)
dispEv forall {k} (a :: k). a :~: a
Refl s
s BrickEvent n appev
ev PaneState pane appev
pd
panelState :: Panel n appev s (pane : panes) -> PaneState pane appev
panelState (PanelWith PaneState pane appev
pd PaneFocus n
_ Panel n appev s panes
_) = PaneState pane appev
pd
panelStateUpdate :: Panel n appev s (pane : panes)
-> PaneState pane appev -> Panel n appev s (pane : panes)
panelStateUpdate (PanelWith PaneState pane appev
_pd PaneFocus n
n Panel n appev s panes
r) = \PaneState pane appev
pd' -> forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd' PaneFocus n
n Panel n appev s panes
r
paneNumber :: Panel n appev s (pane : panes) -> PaneNumber
paneNumber Panel n appev s (pane : panes)
_ = Natural -> PaneNumber
PaneNo Natural
0
instance {-# OVERLAPPABLE #-} (PanelOps pane n appev panes s) =>
PanelOps pane n appev (o ': panes) s where
handlePanelEvent :: forall es.
(EventConstraints pane s, Eq n) =>
s
-> pane
-> Panel n appev s (o : panes)
-> BrickEvent n appev
-> EventM n es (Panel n appev s (o : panes))
handlePanelEvent s
s pane
p (PanelWith PaneState pane appev
pd PaneFocus n
n Panel n appev s panes
r) BrickEvent n appev
ev =
forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd PaneFocus n
n forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall pane n appev (panes :: [*]) s es.
(PanelOps pane n appev panes s, EventConstraints pane s, Eq n) =>
s
-> pane
-> Panel n appev s panes
-> BrickEvent n appev
-> EventM n es (Panel n appev s panes)
handlePanelEvent s
s pane
p Panel n appev s panes
r BrickEvent n appev
ev
panelState :: Panel n appev s (o : panes) -> PaneState pane appev
panelState (PanelWith PaneState pane appev
_ PaneFocus n
_ Panel n appev s panes
r) = forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes -> PaneState pane appev
panelState Panel n appev s panes
r
panelStateUpdate :: Panel n appev s (o : panes)
-> PaneState pane appev -> Panel n appev s (o : panes)
panelStateUpdate (PanelWith PaneState pane appev
pd PaneFocus n
n Panel n appev s panes
r) =
\PaneState pane appev
pd' -> forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd PaneFocus n
n forall a b. (a -> b) -> a -> b
$ forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes
-> PaneState pane appev -> Panel n appev s panes
panelStateUpdate Panel n appev s panes
r PaneState pane appev
pd'
paneNumber :: Panel n appev s (o : panes) -> PaneNumber
paneNumber (PanelWith PaneState pane appev
_ PaneFocus n
_ Panel n appev s panes
r) = forall a. Enum a => a -> a
succ forall a b. (a -> b) -> a -> b
$ forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes -> PaneNumber
paneNumber @pane Panel n appev s panes
r
instance ( TypeError
('Text "No " ':<>: 'ShowType pane ':<>: 'Text " in Panel"
':$$: 'Text "Add this pane to your Panel (or move it lower)"
':$$: 'Text "(Possibly driven by DrawConstraints)"
)
, Pane n appev pane
)
=> PanelOps pane n appev '[] s where
handlePanelEvent :: forall es.
(EventConstraints pane s, Eq n) =>
s
-> pane
-> Panel n appev s '[]
-> BrickEvent n appev
-> EventM n es (Panel n appev s '[])
handlePanelEvent = forall a. Void -> a
absurd (forall a. HasCallStack => a
undefined :: Void)
panelState :: Panel n appev s '[] -> PaneState pane appev
panelState = forall a. Void -> a
absurd (forall a. HasCallStack => a
undefined :: Void)
panelStateUpdate :: Panel n appev s '[] -> PaneState pane appev -> Panel n appev s '[]
panelStateUpdate = forall a. Void -> a
absurd (forall a. HasCallStack => a
undefined :: Void)
paneNumber :: Panel n appev s '[] -> PaneNumber
paneNumber = forall a. Void -> a
absurd (forall a. HasCallStack => a
undefined :: Void)
panelDraw :: forall pane n appev s panes .
( DrawConstraints pane (Panel n appev s panes) n
, PanelOps pane n appev panes s
, Pane n appev pane
, Eq n
)
=> Panel n appev s panes -> Maybe (Widget n)
panelDraw :: forall pane n appev s (panes :: [*]).
(DrawConstraints pane (Panel n appev s panes) n,
PanelOps pane n appev panes s, Pane n appev pane, Eq n) =>
Panel n appev s panes -> Maybe (Widget n)
panelDraw Panel n appev s panes
panel = forall n appEv pane drawcontext.
(Pane n appEv pane, DrawConstraints pane drawcontext n, Eq n) =>
PaneState pane appEv -> drawcontext -> Maybe (Widget n)
drawPane (forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes -> PaneState pane appev
panelState @pane Panel n appev s panes
panel) Panel n appev s panes
panel
handlePanelEvents :: Eq n
=> Panel n appev s panes
-> BrickEvent n appev
-> Focused n
-> EventM n es (Panel n appev s panes)
handlePanelEvents :: forall n appev s (panes :: [*]) es.
Eq n =>
Panel n appev s panes
-> BrickEvent n appev
-> Focused n
-> EventM n es (Panel n appev s panes)
handlePanelEvents Panel n appev s panes
panel BrickEvent n appev
ev (Focused Maybe n
focus) =
case Maybe n
focus of
Maybe n
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return Panel n appev s panes
panel
Just n
fcs -> forall n appev s (panes :: [*]) es.
Eq n =>
n
-> Panel n appev s panes
-> BrickEvent n appev
-> EventM n es (Panel n appev s panes)
go n
fcs Panel n appev s panes
panel BrickEvent n appev
ev
where
go :: Eq n
=> n -> Panel n appev s panes -> BrickEvent n appev
-> EventM n es (Panel n appev s panes)
go :: forall n appev s (panes :: [*]) es.
Eq n =>
n
-> Panel n appev s panes
-> BrickEvent n appev
-> EventM n es (Panel n appev s panes)
go n
_ p :: Panel n appev s panes
p@(Panel {}) BrickEvent n appev
_ = forall (m :: * -> *) a. Monad m => a -> m a
return Panel n appev s panes
p
go n
fcs (PanelWith PaneState pane appev
pd PaneFocus n
pf Panel n appev s panes
r) BrickEvent n appev
evnt =
let handleIt :: EventM n es (PaneState pane appev)
handleIt = forall n appev pane evtype base es.
(DispatchEvent n appev pane evtype, Pane n appev pane,
EventConstraints pane base, Eq n) =>
(EventType pane n appev :~: evtype)
-> base
-> BrickEvent n appev
-> PaneState pane appev
-> EventM n es (PaneState pane appev)
dispEv forall {k} (a :: k). a :~: a
Refl Panel n appev s panes
r BrickEvent n appev
evnt PaneState pane appev
pd
skipIt :: EventM n es (PaneState pane appev)
skipIt = forall (m :: * -> *) a. Monad m => a -> m a
return PaneState pane appev
pd
in do PaneState pane appev
pd' <- case PaneFocus n
pf of
PaneFocus n
Never -> EventM n es (PaneState pane appev)
skipIt
PaneFocus n
Always -> EventM n es (PaneState pane appev)
handleIt
PaneFocus n
WhenFocused -> if n
fcs forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
then EventM n es (PaneState pane appev)
handleIt
else EventM n es (PaneState pane appev)
skipIt
PaneFocus n
WhenFocusedModal -> if n
fcs forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
then EventM n es (PaneState pane appev)
handleIt
else EventM n es (PaneState pane appev)
skipIt
WhenFocusedModal' FocusRing n
_ -> if n
fcs forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
then EventM n es (PaneState pane appev)
handleIt
else EventM n es (PaneState pane appev)
skipIt
PaneFocus n
WhenFocusedModalHandlingAllEvents ->
if n
fcs forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
then EventM n es (PaneState pane appev)
handleIt
else EventM n es (PaneState pane appev)
skipIt
WhenFocusedModalHandlingAllEvents' FocusRing n
_ ->
if n
fcs forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
then EventM n es (PaneState pane appev)
handleIt
else EventM n es (PaneState pane appev)
skipIt
forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd' PaneFocus n
pf forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n appev s (panes :: [*]) es.
Eq n =>
n
-> Panel n appev s panes
-> BrickEvent n appev
-> EventM n es (Panel n appev s panes)
go n
fcs Panel n appev s panes
r BrickEvent n appev
evnt
handleFocusAndPanelEvents :: Eq n => Ord n
=> Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> BrickEvent n appev
-> EventM n es (PanelTransition, Panel n appev s panes)
handleFocusAndPanelEvents :: forall n appev s (panes :: [*]) es.
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> BrickEvent n appev
-> EventM n es (PanelTransition, Panel n appev s panes)
handleFocusAndPanelEvents Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel =
let fcs :: Maybe n
fcs = forall n. FocusRing n -> Maybe n
focusGetCurrent (Panel n appev s panes
panel forall s a. s -> Getting a s a -> a
^. Lens' (Panel n appev s panes) (FocusRing n)
focusL)
doPanelEvHandling :: Bool
doPanelEvHandling = case Maybe n
fcs of
Maybe n
Nothing -> Bool
True
Just n
curFcs -> forall n appev s (panes :: [*]).
Eq n =>
n -> Panel n appev s panes -> Bool
chkEv n
curFcs Panel n appev s panes
panel
in \case
VtyEvent (Vty.EvKey (Vty.KChar Char
'\t') []) | Bool
doPanelEvHandling ->
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Maybe a
Nothing, Panel n appev s panes
panel forall a b. a -> (a -> b) -> b
& Lens' (Panel n appev s panes) (FocusRing n)
focusL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall n. FocusRing n -> FocusRing n
focusNext)
VtyEvent (Vty.EvKey Key
Vty.KBackTab []) | Bool
doPanelEvHandling ->
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Maybe a
Nothing, Panel n appev s panes
panel forall a b. a -> (a -> b) -> b
& Lens' (Panel n appev s panes) (FocusRing n)
focusL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall n. FocusRing n -> FocusRing n
focusPrev)
BrickEvent n appev
panelEv -> do
Panel n appev s panes
u <- forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> Panel n appev s panes
focusRingUpdate Lens' (Panel n appev s panes) (FocusRing n)
focusL forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n appev s (panes :: [*]) es.
Eq n =>
Panel n appev s panes
-> BrickEvent n appev
-> Focused n
-> EventM n es (Panel n appev s panes)
handlePanelEvents Panel n appev s panes
panel BrickEvent n appev
panelEv (forall n. Maybe n -> Focused n
Focused Maybe n
fcs)
let fcs' :: Maybe n
fcs' = forall n. FocusRing n -> Maybe n
focusGetCurrent (Panel n appev s panes
u forall s a. s -> Getting a s a -> a
^. Lens' (Panel n appev s panes) (FocusRing n)
focusL)
if Maybe n
fcs forall a. Eq a => a -> a -> Bool
== Maybe n
fcs'
then forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Maybe a
Nothing, Panel n appev s panes
u)
else let m0 :: PanelMode
m0 = forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> PanelMode
panelMode Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel
m1 :: PanelMode
m1 = forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> PanelMode
panelMode Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
u
in forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if PanelMode
m0 forall a. Eq a => a -> a -> Bool
== PanelMode
m1
then (forall a. Maybe a
Nothing, Panel n appev s panes
u)
else (forall a. a -> Maybe a
Just (PanelMode
m0, PanelMode
m1), Panel n appev s panes
u)
where
chkEv :: Eq n => n -> Panel n appev s panes -> Bool
chkEv :: forall n appev s (panes :: [*]).
Eq n =>
n -> Panel n appev s panes -> Bool
chkEv n
curFcs = \case
Panel {} -> Bool
True
PanelWith PaneState pane appev
pd PaneFocus n
WhenFocusedModalHandlingAllEvents Panel n appev s panes
r ->
(Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ n
curFcs forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd) Bool -> Bool -> Bool
&& forall n appev s (panes :: [*]).
Eq n =>
n -> Panel n appev s panes -> Bool
chkEv n
curFcs Panel n appev s panes
r
PanelWith PaneState pane appev
pd (WhenFocusedModalHandlingAllEvents' FocusRing n
_) Panel n appev s panes
r ->
(Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ n
curFcs forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd) Bool -> Bool -> Bool
&& forall n appev s (panes :: [*]).
Eq n =>
n -> Panel n appev s panes -> Bool
chkEv n
curFcs Panel n appev s panes
r
PanelWith PaneState pane appev
_ PaneFocus n
_ Panel n appev s panes
r -> forall n appev s (panes :: [*]).
Eq n =>
n -> Panel n appev s panes -> Bool
chkEv n
curFcs Panel n appev s panes
r
panelMode :: Eq n
=> Ord n
=> Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> PanelMode
panelMode :: forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> PanelMode
panelMode Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel =
forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s panes -> PanelMode
modalTgt (forall a. Ord a => [a] -> [a]
L.sort forall a b. (a -> b) -> a -> b
$ forall n. FocusRing n -> [n]
focusRingToList (Panel n appev s panes
panel forall s a. s -> Getting a s a -> a
^. Lens' (Panel n appev s panes) (FocusRing n)
focusL)) Panel n appev s panes
panel
where
modalTgt :: Eq n
=> Ord n
=> [n] -> Panel n appev s panes -> PanelMode
modalTgt :: forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s panes -> PanelMode
modalTgt [n]
fcsRing = \case
Panel {} -> PanelMode
Normal
PanelWith PaneState pane appev
pd PaneFocus n
WhenFocusedModal Panel n appev s panes
r ->
forall n appev s (pnlpanes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s pnlpanes -> Seq n -> PanelMode
matchOrRecurse [n]
fcsRing Panel n appev s panes
r forall a b. (a -> b) -> a -> b
$ forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
PanelWith PaneState pane appev
pd (WhenFocusedModal' FocusRing n
_) Panel n appev s panes
r ->
forall n appev s (pnlpanes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s pnlpanes -> Seq n -> PanelMode
matchOrRecurse [n]
fcsRing Panel n appev s panes
r forall a b. (a -> b) -> a -> b
$ forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
PanelWith PaneState pane appev
pd PaneFocus n
WhenFocusedModalHandlingAllEvents Panel n appev s panes
r ->
forall n appev s (pnlpanes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s pnlpanes -> Seq n -> PanelMode
matchOrRecurse [n]
fcsRing Panel n appev s panes
r forall a b. (a -> b) -> a -> b
$ forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
PanelWith PaneState pane appev
pd (WhenFocusedModalHandlingAllEvents' FocusRing n
_) Panel n appev s panes
r ->
forall n appev s (pnlpanes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s pnlpanes -> Seq n -> PanelMode
matchOrRecurse [n]
fcsRing Panel n appev s panes
r forall a b. (a -> b) -> a -> b
$ forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
PanelWith PaneState pane appev
_ PaneFocus n
_ Panel n appev s panes
r -> case forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s panes -> PanelMode
modalTgt [n]
fcsRing Panel n appev s panes
r of
PanelMode
Normal -> PanelMode
Normal
Modal PaneNumber
p -> PaneNumber -> PanelMode
Modal forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> a
succ PaneNumber
p
matchOrRecurse :: Eq n => Ord n
=> [n] -> Panel n appev s pnlpanes -> Seq.Seq n -> PanelMode
matchOrRecurse :: forall n appev s (pnlpanes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s pnlpanes -> Seq n -> PanelMode
matchOrRecurse [n]
fcsRing Panel n appev s pnlpanes
r Seq n
f =
if [n]
fcsRing forall a. Eq a => a -> a -> Bool
== forall a. Ord a => [a] -> [a]
L.sort (forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList Seq n
f)
then PaneNumber -> PanelMode
Modal (Natural -> PaneNumber
PaneNo Natural
0)
else case forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
[n] -> Panel n appev s panes -> PanelMode
modalTgt [n]
fcsRing Panel n appev s pnlpanes
r of
PanelMode
Normal -> PanelMode
Normal
Modal PaneNumber
p -> PaneNumber -> PanelMode
Modal forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> a
succ PaneNumber
p
isPanelModal :: Eq n
=> Ord n
=> Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> Bool
isPanelModal :: forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> Bool
isPanelModal Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel = PanelMode
Normal forall a. Eq a => a -> a -> Bool
/= forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> PanelMode
panelMode Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel
data PanelMode = Normal | Modal PaneNumber deriving (PanelMode -> PanelMode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PanelMode -> PanelMode -> Bool
$c/= :: PanelMode -> PanelMode -> Bool
== :: PanelMode -> PanelMode -> Bool
$c== :: PanelMode -> PanelMode -> Bool
Eq)
newtype PaneNumber = PaneNo Natural deriving (PaneNumber -> PaneNumber -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PaneNumber -> PaneNumber -> Bool
$c/= :: PaneNumber -> PaneNumber -> Bool
== :: PaneNumber -> PaneNumber -> Bool
$c== :: PaneNumber -> PaneNumber -> Bool
Eq, Int -> PaneNumber
PaneNumber -> Int
PaneNumber -> [PaneNumber]
PaneNumber -> PaneNumber
PaneNumber -> PaneNumber -> [PaneNumber]
PaneNumber -> PaneNumber -> PaneNumber -> [PaneNumber]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: PaneNumber -> PaneNumber -> PaneNumber -> [PaneNumber]
$cenumFromThenTo :: PaneNumber -> PaneNumber -> PaneNumber -> [PaneNumber]
enumFromTo :: PaneNumber -> PaneNumber -> [PaneNumber]
$cenumFromTo :: PaneNumber -> PaneNumber -> [PaneNumber]
enumFromThen :: PaneNumber -> PaneNumber -> [PaneNumber]
$cenumFromThen :: PaneNumber -> PaneNumber -> [PaneNumber]
enumFrom :: PaneNumber -> [PaneNumber]
$cenumFrom :: PaneNumber -> [PaneNumber]
fromEnum :: PaneNumber -> Int
$cfromEnum :: PaneNumber -> Int
toEnum :: Int -> PaneNumber
$ctoEnum :: Int -> PaneNumber
pred :: PaneNumber -> PaneNumber
$cpred :: PaneNumber -> PaneNumber
succ :: PaneNumber -> PaneNumber
$csucc :: PaneNumber -> PaneNumber
Enum)
type PanelTransition = Maybe (PanelMode, PanelMode)
enteredModal :: forall pane n appev state panes
. PanelOps pane n appev panes state
=> PanelTransition -> Panel n appev state panes -> Bool
enteredModal :: forall pane n appev state (panes :: [*]).
PanelOps pane n appev panes state =>
PanelTransition -> Panel n appev state panes -> Bool
enteredModal = \case
Just (PanelMode
_, Modal PaneNumber
pnum) -> (PaneNumber
pnum forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes -> PaneNumber
paneNumber @pane
PanelTransition
_ -> forall a b. a -> b -> a
const Bool
False
exitedModal :: forall pane n appev state panes
. PanelOps pane n appev panes state
=> PanelTransition -> Panel n appev state panes -> Bool
exitedModal :: forall pane n appev state (panes :: [*]).
PanelOps pane n appev panes state =>
PanelTransition -> Panel n appev state panes -> Bool
exitedModal = \case
Just (Modal PaneNumber
pnum, PanelMode
_) -> (PaneNumber
pnum forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall pane n appev (panes :: [*]) s.
PanelOps pane n appev panes s =>
Panel n appev s panes -> PaneNumber
paneNumber @pane
PanelTransition
_ -> forall a b. a -> b -> a
const Bool
False
focusRingUpdate :: (Eq n, Ord n)
=> Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> Panel n appev s panes
focusRingUpdate :: forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> Panel n appev s panes
focusRingUpdate Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel = let (Panel n appev s panes
p', [n]
r) = forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> (Panel n appev s panes, [n])
focusableNames Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel
in Panel n appev s panes
p' forall a b. a -> (a -> b) -> b
& Lens' (Panel n appev s panes) (FocusRing n)
focusL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall n. Eq n => [n] -> FocusRing n -> FocusRing n
updRing [n]
r
where
updRing :: Eq n => [n] -> FocusRing n -> FocusRing n
updRing :: forall n. Eq n => [n] -> FocusRing n -> FocusRing n
updRing [n]
nl FocusRing n
fcs =
case [n]
nl of
[] -> forall n. [n] -> FocusRing n
focusRing []
(n
n : [n]
_) ->
case forall n. FocusRing n -> Maybe n
focusGetCurrent FocusRing n
fcs of
Maybe n
Nothing ->
forall n. Eq n => n -> FocusRing n -> FocusRing n
focusSetCurrent n
n forall a b. (a -> b) -> a -> b
$ forall n. [n] -> FocusRing n
focusRing [n]
nl
Just n
e ->
case forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
L.find ((n
e forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> a
head) forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [[a]]
rotations [n]
nl of
Just [n]
r ->
forall n. [n] -> FocusRing n
focusRing [n]
r
Maybe [n]
Nothing ->
forall n. Eq n => n -> FocusRing n -> FocusRing n
focusSetCurrent n
n forall a b. (a -> b) -> a -> b
$ forall n. [n] -> FocusRing n
focusRing [n]
nl
focusableNames :: (Eq n, Ord n)
=> Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> (Panel n appev s panes, [n])
focusableNames :: forall n appev s (panes :: [*]).
(Eq n, Ord n) =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> (Panel n appev s panes, [n])
focusableNames Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel = forall {a} {a}.
Ord a =>
((Maybe [a], a), (Seq a, Seq a)) -> (a, [a])
finish forall a b. (a -> b) -> a -> b
$ forall n appev s (panes :: [*]) (rempanes :: [*]).
Eq n =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> Panel n appev s rempanes
-> ((Maybe [n], Panel n appev s rempanes), (Seq n, Seq n))
subFocusable Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
panel Panel n appev s panes
panel
where
finish :: ((Maybe [a], a), (Seq a, Seq a)) -> (a, [a])
finish ((Maybe [a]
prvFcs, a
pnl), (Seq a
mdlFcs, Seq a
regFcs)) =
let reorder :: Seq a -> [a]
reorder = forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => Seq a -> Seq a
Seq.sort
fr :: [a]
fr = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null Seq a
mdlFcs
then forall a. a -> Maybe a -> a
fromMaybe (Seq a -> [a]
reorder Seq a
regFcs) Maybe [a]
prvFcs
else Seq a -> [a]
reorder Seq a
mdlFcs
in (a
pnl, [a]
fr)
subFocusable :: Eq n
=> Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes -> Panel n appev s rempanes
-> ((Maybe [n], Panel n appev s rempanes), (Seq n, Seq n))
subFocusable :: forall n appev s (panes :: [*]) (rempanes :: [*]).
Eq n =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> Panel n appev s rempanes
-> ((Maybe [n], Panel n appev s rempanes), (Seq n, Seq n))
subFocusable Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
base = \case
i :: Panel n appev s rempanes
i@(Panel {}) -> ((forall a. Maybe a
Nothing, Panel n appev s rempanes
i), (forall a. Monoid a => a
mempty, forall a. Monoid a => a
mempty))
PanelWith PaneState pane appev
pd PaneFocus n
WhenFocused Panel n appev s panes
r ->
let ((Maybe [n], Panel n appev s panes)
i', (Seq n, Seq n)
ns) = forall n appev s (panes :: [*]) (rempanes :: [*]).
Eq n =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> Panel n appev s rempanes
-> ((Maybe [n], Panel n appev s rempanes), (Seq n, Seq n))
subFocusable Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
base Panel n appev s panes
r
ns' :: (Seq n, Seq n)
ns' = let pf :: Seq n
pf = forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable Panel n appev s panes
r PaneState pane appev
pd
in (forall a b. (a, b) -> a
fst (Seq n, Seq n)
ns, Seq n
pf forall a. Seq a -> Seq a -> Seq a
>< forall a b. (a, b) -> b
snd (Seq n, Seq n)
ns)
in (forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd forall n. PaneFocus n
WhenFocused forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe [n], Panel n appev s panes)
i', (Seq n, Seq n)
ns')
PanelWith PaneState pane appev
pd PaneFocus n
WhenFocusedModal Panel n appev s panes
r ->
let (Maybe [n]
f', Maybe (FocusRing n)
pf', Panel n appev s panes
i', (Seq n, Seq n)
ns') = forall fullpanel n appev s (panes :: [*]) rempanel
(rempanes :: [*]) pane.
(fullpanel ~ Panel n appev s panes,
rempanel ~ Panel n appev s rempanes,
EventConstraints pane rempanel, Pane n appev pane, Eq n) =>
Lens' fullpanel (FocusRing n)
-> fullpanel
-> PaneState pane appev
-> Maybe (FocusRing n)
-> rempanel
-> (Maybe [n], Maybe (FocusRing n), rempanel, (Seq n, Seq n))
goModal Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
base PaneState pane appev
pd forall a. Maybe a
Nothing Panel n appev s panes
r
pfNew :: PaneFocus n
pfNew = case Maybe (FocusRing n)
pf' of
Maybe (FocusRing n)
Nothing -> forall n. PaneFocus n
WhenFocusedModal
Just FocusRing n
x -> forall n. FocusRing n -> PaneFocus n
WhenFocusedModal' FocusRing n
x
in ((Maybe [n]
f', forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd PaneFocus n
pfNew Panel n appev s panes
i'), (Seq n, Seq n)
ns')
PanelWith PaneState pane appev
pd (WhenFocusedModal' FocusRing n
pf) Panel n appev s panes
r ->
let (Maybe [n]
f', Maybe (FocusRing n)
pf', Panel n appev s panes
i', (Seq n, Seq n)
ns') = forall fullpanel n appev s (panes :: [*]) rempanel
(rempanes :: [*]) pane.
(fullpanel ~ Panel n appev s panes,
rempanel ~ Panel n appev s rempanes,
EventConstraints pane rempanel, Pane n appev pane, Eq n) =>
Lens' fullpanel (FocusRing n)
-> fullpanel
-> PaneState pane appev
-> Maybe (FocusRing n)
-> rempanel
-> (Maybe [n], Maybe (FocusRing n), rempanel, (Seq n, Seq n))
goModal Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
base PaneState pane appev
pd (forall a. a -> Maybe a
Just FocusRing n
pf) Panel n appev s panes
r
pfNew :: PaneFocus n
pfNew = case Maybe (FocusRing n)
pf' of
Maybe (FocusRing n)
Nothing -> forall n. PaneFocus n
WhenFocusedModal
Just FocusRing n
x -> forall n. FocusRing n -> PaneFocus n
WhenFocusedModal' FocusRing n
x
in ((Maybe [n]
f', forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd PaneFocus n
pfNew Panel n appev s panes
i'), (Seq n, Seq n)
ns')
PanelWith PaneState pane appev
pd PaneFocus n
WhenFocusedModalHandlingAllEvents Panel n appev s panes
r ->
let (Maybe [n]
f', Maybe (FocusRing n)
pf', Panel n appev s panes
i', (Seq n, Seq n)
ns') = forall fullpanel n appev s (panes :: [*]) rempanel
(rempanes :: [*]) pane.
(fullpanel ~ Panel n appev s panes,
rempanel ~ Panel n appev s rempanes,
EventConstraints pane rempanel, Pane n appev pane, Eq n) =>
Lens' fullpanel (FocusRing n)
-> fullpanel
-> PaneState pane appev
-> Maybe (FocusRing n)
-> rempanel
-> (Maybe [n], Maybe (FocusRing n), rempanel, (Seq n, Seq n))
goModal Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
base PaneState pane appev
pd forall a. Maybe a
Nothing Panel n appev s panes
r
pfNew :: PaneFocus n
pfNew = case Maybe (FocusRing n)
pf' of
Maybe (FocusRing n)
Nothing -> forall n. PaneFocus n
WhenFocusedModalHandlingAllEvents
Just FocusRing n
x -> forall n. FocusRing n -> PaneFocus n
WhenFocusedModalHandlingAllEvents' FocusRing n
x
in ((Maybe [n]
f', forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd PaneFocus n
pfNew Panel n appev s panes
i'), (Seq n, Seq n)
ns')
PanelWith PaneState pane appev
pd (WhenFocusedModalHandlingAllEvents' FocusRing n
pf) Panel n appev s panes
r ->
let (Maybe [n]
f', Maybe (FocusRing n)
pf', Panel n appev s panes
i', (Seq n, Seq n)
ns') = forall fullpanel n appev s (panes :: [*]) rempanel
(rempanes :: [*]) pane.
(fullpanel ~ Panel n appev s panes,
rempanel ~ Panel n appev s rempanes,
EventConstraints pane rempanel, Pane n appev pane, Eq n) =>
Lens' fullpanel (FocusRing n)
-> fullpanel
-> PaneState pane appev
-> Maybe (FocusRing n)
-> rempanel
-> (Maybe [n], Maybe (FocusRing n), rempanel, (Seq n, Seq n))
goModal Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
base PaneState pane appev
pd (forall a. a -> Maybe a
Just FocusRing n
pf) Panel n appev s panes
r
pfNew :: PaneFocus n
pfNew = case Maybe (FocusRing n)
pf' of
Maybe (FocusRing n)
Nothing -> forall n. PaneFocus n
WhenFocusedModalHandlingAllEvents
Just FocusRing n
x -> forall n. FocusRing n -> PaneFocus n
WhenFocusedModalHandlingAllEvents' FocusRing n
x
in ((Maybe [n]
f', forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
pd PaneFocus n
pfNew Panel n appev s panes
i'), (Seq n, Seq n)
ns')
PanelWith PaneState pane appev
x PaneFocus n
y Panel n appev s panes
r -> let ((Maybe [n], Panel n appev s panes)
i', (Seq n, Seq n)
ns) = forall n appev s (panes :: [*]) (rempanes :: [*]).
Eq n =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> Panel n appev s rempanes
-> ((Maybe [n], Panel n appev s rempanes), (Seq n, Seq n))
subFocusable Lens' (Panel n appev s panes) (FocusRing n)
focusL Panel n appev s panes
base Panel n appev s panes
r
in (forall n appev pane state (panes :: [*]).
(Pane n appev pane,
DrawConstraints pane (Panel n appev state panes) n,
EventConstraints pane (Panel n appev state panes),
DispatchEvent n appev pane (EventType pane n appev)) =>
PaneState pane appev
-> PaneFocus n
-> Panel n appev state panes
-> Panel n appev state (pane : panes)
PanelWith PaneState pane appev
x PaneFocus n
y forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe [n], Panel n appev s panes)
i', (Seq n, Seq n)
ns)
goModal :: fullpanel ~ Panel n appev s panes
=> rempanel ~ Panel n appev s rempanes
=> EventConstraints pane rempanel
=> Pane n appev pane
=> Eq n
=> Lens' fullpanel (FocusRing n)
-> fullpanel
-> PaneState pane appev
-> Maybe (FocusRing n)
-> rempanel
-> (Maybe [n], Maybe (FocusRing n), rempanel, (Seq n, Seq n))
goModal :: forall fullpanel n appev s (panes :: [*]) rempanel
(rempanes :: [*]) pane.
(fullpanel ~ Panel n appev s panes,
rempanel ~ Panel n appev s rempanes,
EventConstraints pane rempanel, Pane n appev pane, Eq n) =>
Lens' fullpanel (FocusRing n)
-> fullpanel
-> PaneState pane appev
-> Maybe (FocusRing n)
-> rempanel
-> (Maybe [n], Maybe (FocusRing n), rempanel, (Seq n, Seq n))
goModal Lens' fullpanel (FocusRing n)
focusL fullpanel
base PaneState pane appev
pd Maybe (FocusRing n)
pf rempanel
r =
let ((Maybe [n]
f, Panel n appev s rempanes
i'), (Seq n, Seq n)
ns) = forall n appev s (panes :: [*]) (rempanes :: [*]).
Eq n =>
Lens' (Panel n appev s panes) (FocusRing n)
-> Panel n appev s panes
-> Panel n appev s rempanes
-> ((Maybe [n], Panel n appev s rempanes), (Seq n, Seq n))
subFocusable Lens' fullpanel (FocusRing n)
focusL fullpanel
base rempanel
r
fnms :: Seq n
fnms = forall n appEv pane eventcontext.
(Pane n appEv pane, EventConstraints pane eventcontext, Eq n) =>
eventcontext -> PaneState pane appEv -> Seq n
focusable rempanel
r PaneState pane appev
pd
fpred :: Bool
fpred = Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall a. Seq a -> Bool
Seq.null Seq n
fnms
ns' :: (Seq n, Seq n)
ns' = (Seq n
fnms forall a. Seq a -> Seq a -> Seq a
>< forall a b. (a, b) -> a
fst (Seq n, Seq n)
ns, forall a b. (a, b) -> b
snd (Seq n, Seq n)
ns)
f' :: Maybe [n]
f' = if Bool
fpred then forall a. Maybe a
Nothing else Maybe [n]
f forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall n. FocusRing n -> [n]
focusRingToList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (FocusRing n)
pf)
pf' :: Maybe (FocusRing n)
pf' = if Bool
fpred then Maybe (FocusRing n)
pf forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. a -> Maybe a
Just (fullpanel
baseforall s a. s -> Getting a s a -> a
^.Lens' fullpanel (FocusRing n)
focusL) else forall a. Maybe a
Nothing
in (Maybe [n]
f', Maybe (FocusRing n)
pf', Panel n appev s rempanes
i', (Seq n, Seq n)
ns')
rotations :: [a] -> [ [a] ]
rotations :: forall a. [a] -> [[a]]
rotations [a]
l = forall a b. (a -> b) -> [a] -> [b]
map Int -> [a]
rotateBy forall a b. (a -> b) -> a -> b
$ [Int
0..forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
l forall a. Num a => a -> a -> a
- Int
1]
where rotateBy :: Int -> [a]
rotateBy Int
n = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Semigroup a => a -> a -> a
(<>)) forall a b. (a -> b) -> a -> b
$ forall a. Int -> [a] -> ([a], [a])
L.splitAt Int
n [a]
l