{-# LANGUAGE TupleSections #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
module Brick.Widgets.List
( GenericList
, List
, list
, renderList
, renderListWithIndex
, handleListEvent
, handleListEventVi
, listElementsL
, listSelectedL
, listNameL
, listItemHeightL
, listSelectedElementL
, listElements
, listName
, listSelectedElement
, listSelected
, listItemHeight
, listMoveBy
, listMoveTo
, listMoveToElement
, listFindBy
, listMoveUp
, listMoveDown
, listMoveByPages
, listMovePageUp
, listMovePageDown
, listMoveToBeginning
, listMoveToEnd
, listInsert
, listRemove
, listReplace
, listClear
, listReverse
, listModify
, listAttr
, listSelectedAttr
, listSelectedFocusedAttr
, Splittable(..)
, Reversible(..)
)
where
import Prelude hiding (reverse, splitAt)
import Control.Applicative ((<|>))
import Data.Foldable (find, toList)
import Control.Monad.State (evalState)
import Lens.Micro (Traversal', (^.), (^?), (&), (.~), (%~), _2, set)
import Data.Functor (($>))
import Data.List.NonEmpty (NonEmpty((:|)))
import Data.Maybe (fromMaybe)
#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup (Semigroup, (<>))
#endif
import Data.Semigroup (sconcat)
import qualified Data.Sequence as Seq
import Graphics.Vty (Event(..), Key(..), Modifier(..))
import qualified Data.Vector as V
import GHC.Generics (Generic)
import Brick.Types
import Brick.Main (lookupViewport)
import Brick.Widgets.Core
import Brick.Util (clamp)
import Brick.AttrMap
data GenericList n t e =
List { forall n (t :: * -> *) e. GenericList n t e -> t e
listElements :: !(t e)
, forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
listSelected :: !(Maybe Int)
, forall n (t :: * -> *) e. GenericList n t e -> n
listName :: n
, forall n (t :: * -> *) e. GenericList n t e -> Int
listItemHeight :: Int
} deriving ((forall a b. (a -> b) -> GenericList n t a -> GenericList n t b)
-> (forall a b. a -> GenericList n t b -> GenericList n t a)
-> Functor (GenericList n t)
forall a b. a -> GenericList n t b -> GenericList n t a
forall a b. (a -> b) -> GenericList n t a -> GenericList n t b
forall n (t :: * -> *) a b.
Functor t =>
a -> GenericList n t b -> GenericList n t a
forall n (t :: * -> *) a b.
Functor t =>
(a -> b) -> GenericList n t a -> GenericList n t b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall n (t :: * -> *) a b.
Functor t =>
(a -> b) -> GenericList n t a -> GenericList n t b
fmap :: forall a b. (a -> b) -> GenericList n t a -> GenericList n t b
$c<$ :: forall n (t :: * -> *) a b.
Functor t =>
a -> GenericList n t b -> GenericList n t a
<$ :: forall a b. a -> GenericList n t b -> GenericList n t a
Functor, (forall m. Monoid m => GenericList n t m -> m)
-> (forall m a. Monoid m => (a -> m) -> GenericList n t a -> m)
-> (forall m a. Monoid m => (a -> m) -> GenericList n t a -> m)
-> (forall a b. (a -> b -> b) -> b -> GenericList n t a -> b)
-> (forall a b. (a -> b -> b) -> b -> GenericList n t a -> b)
-> (forall b a. (b -> a -> b) -> b -> GenericList n t a -> b)
-> (forall b a. (b -> a -> b) -> b -> GenericList n t a -> b)
-> (forall a. (a -> a -> a) -> GenericList n t a -> a)
-> (forall a. (a -> a -> a) -> GenericList n t a -> a)
-> (forall a. GenericList n t a -> [a])
-> (forall a. GenericList n t a -> Bool)
-> (forall a. GenericList n t a -> Int)
-> (forall a. Eq a => a -> GenericList n t a -> Bool)
-> (forall a. Ord a => GenericList n t a -> a)
-> (forall a. Ord a => GenericList n t a -> a)
-> (forall a. Num a => GenericList n t a -> a)
-> (forall a. Num a => GenericList n t a -> a)
-> Foldable (GenericList n t)
forall a. Eq a => a -> GenericList n t a -> Bool
forall a. Num a => GenericList n t a -> a
forall a. Ord a => GenericList n t a -> a
forall m. Monoid m => GenericList n t m -> m
forall a. GenericList n t a -> Bool
forall a. GenericList n t a -> Int
forall a. GenericList n t a -> [a]
forall a. (a -> a -> a) -> GenericList n t a -> a
forall m a. Monoid m => (a -> m) -> GenericList n t a -> m
forall b a. (b -> a -> b) -> b -> GenericList n t a -> b
forall a b. (a -> b -> b) -> b -> GenericList n t a -> b
forall n (t :: * -> *) a.
(Foldable t, Eq a) =>
a -> GenericList n t a -> Bool
forall n (t :: * -> *) a.
(Foldable t, Num a) =>
GenericList n t a -> a
forall n (t :: * -> *) a.
(Foldable t, Ord a) =>
GenericList n t a -> a
forall n (t :: * -> *) m.
(Foldable t, Monoid m) =>
GenericList n t m -> m
forall n (t :: * -> *) a. Foldable t => GenericList n t a -> Bool
forall n (t :: * -> *) a. Foldable t => GenericList n t a -> Int
forall n (t :: * -> *) a. Foldable t => GenericList n t a -> [a]
forall n (t :: * -> *) a.
Foldable t =>
(a -> a -> a) -> GenericList n t a -> a
forall n (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> GenericList n t a -> m
forall n (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> GenericList n t a -> b
forall n (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> GenericList n t a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall n (t :: * -> *) m.
(Foldable t, Monoid m) =>
GenericList n t m -> m
fold :: forall m. Monoid m => GenericList n t m -> m
$cfoldMap :: forall n (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> GenericList n t a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> GenericList n t a -> m
$cfoldMap' :: forall n (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> GenericList n t a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> GenericList n t a -> m
$cfoldr :: forall n (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> GenericList n t a -> b
foldr :: forall a b. (a -> b -> b) -> b -> GenericList n t a -> b
$cfoldr' :: forall n (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> GenericList n t a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> GenericList n t a -> b
$cfoldl :: forall n (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> GenericList n t a -> b
foldl :: forall b a. (b -> a -> b) -> b -> GenericList n t a -> b
$cfoldl' :: forall n (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> GenericList n t a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> GenericList n t a -> b
$cfoldr1 :: forall n (t :: * -> *) a.
Foldable t =>
(a -> a -> a) -> GenericList n t a -> a
foldr1 :: forall a. (a -> a -> a) -> GenericList n t a -> a
$cfoldl1 :: forall n (t :: * -> *) a.
Foldable t =>
(a -> a -> a) -> GenericList n t a -> a
foldl1 :: forall a. (a -> a -> a) -> GenericList n t a -> a
$ctoList :: forall n (t :: * -> *) a. Foldable t => GenericList n t a -> [a]
toList :: forall a. GenericList n t a -> [a]
$cnull :: forall n (t :: * -> *) a. Foldable t => GenericList n t a -> Bool
null :: forall a. GenericList n t a -> Bool
$clength :: forall n (t :: * -> *) a. Foldable t => GenericList n t a -> Int
length :: forall a. GenericList n t a -> Int
$celem :: forall n (t :: * -> *) a.
(Foldable t, Eq a) =>
a -> GenericList n t a -> Bool
elem :: forall a. Eq a => a -> GenericList n t a -> Bool
$cmaximum :: forall n (t :: * -> *) a.
(Foldable t, Ord a) =>
GenericList n t a -> a
maximum :: forall a. Ord a => GenericList n t a -> a
$cminimum :: forall n (t :: * -> *) a.
(Foldable t, Ord a) =>
GenericList n t a -> a
minimum :: forall a. Ord a => GenericList n t a -> a
$csum :: forall n (t :: * -> *) a.
(Foldable t, Num a) =>
GenericList n t a -> a
sum :: forall a. Num a => GenericList n t a -> a
$cproduct :: forall n (t :: * -> *) a.
(Foldable t, Num a) =>
GenericList n t a -> a
product :: forall a. Num a => GenericList n t a -> a
Foldable, Functor (GenericList n t)
Foldable (GenericList n t)
(Functor (GenericList n t), Foldable (GenericList n t)) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GenericList n t a -> f (GenericList n t b))
-> (forall (f :: * -> *) a.
Applicative f =>
GenericList n t (f a) -> f (GenericList n t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GenericList n t a -> m (GenericList n t b))
-> (forall (m :: * -> *) a.
Monad m =>
GenericList n t (m a) -> m (GenericList n t a))
-> Traversable (GenericList n t)
forall n (t :: * -> *). Traversable t => Functor (GenericList n t)
forall n (t :: * -> *). Traversable t => Foldable (GenericList n t)
forall n (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
GenericList n t (m a) -> m (GenericList n t a)
forall n (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
GenericList n t (f a) -> f (GenericList n t a)
forall n (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> GenericList n t a -> m (GenericList n t b)
forall n (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> GenericList n t a -> f (GenericList n t b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
GenericList n t (m a) -> m (GenericList n t a)
forall (f :: * -> *) a.
Applicative f =>
GenericList n t (f a) -> f (GenericList n t a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GenericList n t a -> m (GenericList n t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GenericList n t a -> f (GenericList n t b)
$ctraverse :: forall n (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> GenericList n t a -> f (GenericList n t b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GenericList n t a -> f (GenericList n t b)
$csequenceA :: forall n (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
GenericList n t (f a) -> f (GenericList n t a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
GenericList n t (f a) -> f (GenericList n t a)
$cmapM :: forall n (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> GenericList n t a -> m (GenericList n t b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GenericList n t a -> m (GenericList n t b)
$csequence :: forall n (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
GenericList n t (m a) -> m (GenericList n t a)
sequence :: forall (m :: * -> *) a.
Monad m =>
GenericList n t (m a) -> m (GenericList n t a)
Traversable, Int -> GenericList n t e -> ShowS
[GenericList n t e] -> ShowS
GenericList n t e -> String
(Int -> GenericList n t e -> ShowS)
-> (GenericList n t e -> String)
-> ([GenericList n t e] -> ShowS)
-> Show (GenericList n t e)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
Int -> GenericList n t e -> ShowS
forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
[GenericList n t e] -> ShowS
forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
GenericList n t e -> String
$cshowsPrec :: forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
Int -> GenericList n t e -> ShowS
showsPrec :: Int -> GenericList n t e -> ShowS
$cshow :: forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
GenericList n t e -> String
show :: GenericList n t e -> String
$cshowList :: forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
[GenericList n t e] -> ShowS
showList :: [GenericList n t e] -> ShowS
Show, (forall x. GenericList n t e -> Rep (GenericList n t e) x)
-> (forall x. Rep (GenericList n t e) x -> GenericList n t e)
-> Generic (GenericList n t e)
forall x. Rep (GenericList n t e) x -> GenericList n t e
forall x. GenericList n t e -> Rep (GenericList n t e) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n (t :: * -> *) e x.
Rep (GenericList n t e) x -> GenericList n t e
forall n (t :: * -> *) e x.
GenericList n t e -> Rep (GenericList n t e) x
$cfrom :: forall n (t :: * -> *) e x.
GenericList n t e -> Rep (GenericList n t e) x
from :: forall x. GenericList n t e -> Rep (GenericList n t e) x
$cto :: forall n (t :: * -> *) e x.
Rep (GenericList n t e) x -> GenericList n t e
to :: forall x. Rep (GenericList n t e) x -> GenericList n t e
Generic)
suffixLenses ''GenericList
type List n e = GenericList n V.Vector e
instance Named (GenericList n t e) n where
getName :: GenericList n t e -> n
getName = GenericList n t e -> n
forall n (t :: * -> *) e. GenericList n t e -> n
listName
class Splittable t where
{-# MINIMAL splitAt #-}
splitAt :: Int -> t a -> (t a, t a)
slice :: Int -> Int -> t a -> t a
slice Int
i Int
n = (t a, t a) -> t a
forall a b. (a, b) -> a
fst ((t a, t a) -> t a) -> (t a -> (t a, t a)) -> t a -> t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> t a -> (t a, t a)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
n (t a -> (t a, t a)) -> (t a -> t a) -> t a -> (t a, t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t a, t a) -> t a
forall a b. (a, b) -> b
snd ((t a, t a) -> t a) -> (t a -> (t a, t a)) -> t a -> t a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> t a -> (t a, t a)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
i
instance Splittable V.Vector where
splitAt :: forall a. Int -> Vector a -> (Vector a, Vector a)
splitAt = Int -> Vector a -> (Vector a, Vector a)
forall a. Int -> Vector a -> (Vector a, Vector a)
V.splitAt
instance Splittable Seq.Seq where
splitAt :: forall a. Int -> Seq a -> (Seq a, Seq a)
splitAt = Int -> Seq a -> (Seq a, Seq a)
forall a. Int -> Seq a -> (Seq a, Seq a)
Seq.splitAt
class Reversible t where
{-# MINIMAL reverse #-}
reverse :: t a -> t a
instance Reversible V.Vector where
reverse :: forall a. Vector a -> Vector a
reverse = Vector a -> Vector a
forall a. Vector a -> Vector a
V.reverse
instance Reversible Seq.Seq where
reverse :: forall a. Seq a -> Seq a
reverse = Seq a -> Seq a
forall a. Seq a -> Seq a
Seq.reverse
handleListEvent :: (Foldable t, Splittable t, Ord n)
=> Event
-> EventM n (GenericList n t e) ()
handleListEvent :: forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
Event -> EventM n (GenericList n t e) ()
handleListEvent Event
e =
case Event
e of
EvKey Key
KUp [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveUp
EvKey Key
KDown [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown
EvKey Key
KHome [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveToBeginning
EvKey Key
KEnd [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveToEnd
EvKey Key
KPageDown [] -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
EventM n (GenericList n t e) ()
listMovePageDown
EvKey Key
KPageUp [] -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
EventM n (GenericList n t e) ()
listMovePageUp
Event
_ -> () -> EventM n (GenericList n t e) ()
forall a. a -> EventM n (GenericList n t e) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
handleListEventVi :: (Foldable t, Splittable t, Ord n)
=> (Event -> EventM n (GenericList n t e) ())
-> Event
-> EventM n (GenericList n t e) ()
handleListEventVi :: forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
(Event -> EventM n (GenericList n t e) ())
-> Event -> EventM n (GenericList n t e) ()
handleListEventVi Event -> EventM n (GenericList n t e) ()
fallback Event
e =
case Event
e of
EvKey (KChar Char
'k') [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveUp
EvKey (KChar Char
'j') [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown
EvKey (KChar Char
'g') [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveToBeginning
EvKey (KChar Char
'G') [] -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveToEnd
EvKey (KChar Char
'f') [Modifier
MCtrl] -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
EventM n (GenericList n t e) ()
listMovePageDown
EvKey (KChar Char
'b') [Modifier
MCtrl] -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
EventM n (GenericList n t e) ()
listMovePageUp
EvKey (KChar Char
'd') [Modifier
MCtrl] -> Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> EventM n (GenericList n t e) ()
listMoveByPages (Double
0.5::Double)
EvKey (KChar Char
'u') [Modifier
MCtrl] -> Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> EventM n (GenericList n t e) ()
listMoveByPages (-Double
0.5::Double)
Event
_ -> Event -> EventM n (GenericList n t e) ()
fallback Event
e
listMoveToBeginning :: (Foldable t, Splittable t)
=> GenericList n t e
-> GenericList n t e
listMoveToBeginning :: forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveToBeginning = Int -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
0
listMoveToEnd :: (Foldable t, Splittable t)
=> GenericList n t e
-> GenericList n t e
listMoveToEnd :: forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveToEnd GenericList n t e
l = Int -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ t e -> Int
forall a. t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (GenericList n t e -> t e
forall n (t :: * -> *) e. GenericList n t e -> t e
listElements GenericList n t e
l) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) GenericList n t e
l
listAttr :: AttrName
listAttr :: AttrName
listAttr = String -> AttrName
attrName String
"list"
listSelectedAttr :: AttrName
listSelectedAttr :: AttrName
listSelectedAttr = AttrName
listAttr AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> String -> AttrName
attrName String
"selected"
listSelectedFocusedAttr :: AttrName
listSelectedFocusedAttr :: AttrName
listSelectedFocusedAttr = AttrName
listSelectedAttr AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> String -> AttrName
attrName String
"focused"
list :: (Foldable t)
=> n
-> t e
-> Int
-> GenericList n t e
list :: forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list n
name t e
es Int
h =
let selIndex :: Maybe Int
selIndex = if t e -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t e
es then Maybe Int
forall a. Maybe a
Nothing else Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0
safeHeight :: Int
safeHeight = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
h
in t e -> Maybe Int -> n -> Int -> GenericList n t e
forall n (t :: * -> *) e.
t e -> Maybe Int -> n -> Int -> GenericList n t e
List t e
es Maybe Int
selIndex n
name Int
safeHeight
renderList :: (Traversable t, Splittable t, Ord n, Show n)
=> (Bool -> e -> Widget n)
-> Bool
-> GenericList n t e
-> Widget n
renderList :: forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
(Bool -> e -> Widget n) -> Bool -> GenericList n t e -> Widget n
renderList Bool -> e -> Widget n
drawElem = (Int -> Bool -> e -> Widget n)
-> Bool -> GenericList n t e -> Widget n
forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
(Int -> Bool -> e -> Widget n)
-> Bool -> GenericList n t e -> Widget n
renderListWithIndex ((Int -> Bool -> e -> Widget n)
-> Bool -> GenericList n t e -> Widget n)
-> (Int -> Bool -> e -> Widget n)
-> Bool
-> GenericList n t e
-> Widget n
forall a b. (a -> b) -> a -> b
$ (Bool -> e -> Widget n) -> Int -> Bool -> e -> Widget n
forall a b. a -> b -> a
const Bool -> e -> Widget n
drawElem
renderListWithIndex :: (Traversable t, Splittable t, Ord n, Show n)
=> (Int -> Bool -> e -> Widget n)
-> Bool
-> GenericList n t e
-> Widget n
renderListWithIndex :: forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
(Int -> Bool -> e -> Widget n)
-> Bool -> GenericList n t e -> Widget n
renderListWithIndex Int -> Bool -> e -> Widget n
drawElem Bool
foc GenericList n t e
l =
AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
listAttr (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$
Bool
-> GenericList n t e -> (Int -> Bool -> e -> Widget n) -> Widget n
forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
Bool
-> GenericList n t e -> (Int -> Bool -> e -> Widget n) -> Widget n
drawListElements Bool
foc GenericList n t e
l Int -> Bool -> e -> Widget n
drawElem
imap :: (Traversable t) => (Int -> a -> b) -> t a -> t b
imap :: forall (t :: * -> *) a b.
Traversable t =>
(Int -> a -> b) -> t a -> t b
imap Int -> a -> b
f t a
xs =
let act :: StateT Int Identity (t b)
act = (a -> StateT Int Identity b) -> t a -> StateT Int Identity (t b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b)
traverse (\a
a -> StateT Int Identity Int
forall s (m :: * -> *). MonadState s m => m s
get StateT Int Identity Int
-> (Int -> StateT Int Identity b) -> StateT Int Identity b
forall a b.
StateT Int Identity a
-> (a -> StateT Int Identity b) -> StateT Int Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
i -> Int -> StateT Int Identity ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) StateT Int Identity () -> b -> StateT Int Identity b
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Int -> a -> b
f Int
i a
a) t a
xs
in StateT Int Identity (t b) -> Int -> t b
forall s a. State s a -> s -> a
evalState StateT Int Identity (t b)
act Int
0
drawListElements :: (Traversable t, Splittable t, Ord n, Show n)
=> Bool
-> GenericList n t e
-> (Int -> Bool -> e -> Widget n)
-> Widget n
drawListElements :: forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
Bool
-> GenericList n t e -> (Int -> Bool -> e -> Widget n) -> Widget n
drawListElements Bool
foc GenericList n t e
l Int -> Bool -> e -> Widget n
drawElem =
Size -> Size -> RenderM n (Result n) -> Widget n
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Greedy (RenderM n (Result n) -> Widget n)
-> RenderM n (Result n) -> Widget n
forall a b. (a -> b) -> a -> b
$ do
Context n
c <- RenderM n (Context n)
forall n. RenderM n (Context n)
getContext
let es :: t e
es = Int -> Int -> t e -> t e
forall a. Int -> Int -> t a -> t a
forall (t :: * -> *) a. Splittable t => Int -> Int -> t a -> t a
slice Int
start (Int
numPerHeight Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2) (GenericList n t e
lGenericList n t e -> Getting (t e) (GenericList n t e) (t e) -> t e
forall s a. s -> Getting a s a -> a
^.Getting (t e) (GenericList n t e) (t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL)
idx :: Int
idx = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
0 (GenericList n t e
lGenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL)
start :: Int
start = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
idx Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
numPerHeight Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
initialNumPerHeight :: Int
initialNumPerHeight = (Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` (GenericList n t e
lGenericList n t e -> Getting Int (GenericList n t e) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (GenericList n t e) Int
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Int -> f Int) -> GenericList n t e -> f (GenericList n t e)
listItemHeightL)
numPerHeight :: Int
numPerHeight = Int
initialNumPerHeight Int -> Int -> Int
forall a. Num a => a -> a -> a
+
if Int
initialNumPerHeight Int -> Int -> Int
forall a. Num a => a -> a -> a
* (GenericList n t e
lGenericList n t e -> Getting Int (GenericList n t e) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (GenericList n t e) Int
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Int -> f Int) -> GenericList n t e -> f (GenericList n t e)
listItemHeightL) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL
then Int
0
else Int
1
off :: Int
off = Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
* (GenericList n t e
lGenericList n t e -> Getting Int (GenericList n t e) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (GenericList n t e) Int
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Int -> f Int) -> GenericList n t e -> f (GenericList n t e)
listItemHeightL)
drawnElements :: t (Widget n)
drawnElements = ((Int -> e -> Widget n) -> t e -> t (Widget n))
-> t e -> (Int -> e -> Widget n) -> t (Widget n)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int -> e -> Widget n) -> t e -> t (Widget n)
forall (t :: * -> *) a b.
Traversable t =>
(Int -> a -> b) -> t a -> t b
imap t e
es ((Int -> e -> Widget n) -> t (Widget n))
-> (Int -> e -> Widget n) -> t (Widget n)
forall a b. (a -> b) -> a -> b
$ \Int
i e
e ->
let j :: Int
j = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
start
isSelected :: Bool
isSelected = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
j Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== GenericList n t e
lGenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL
elemWidget :: Widget n
elemWidget = Int -> Bool -> e -> Widget n
drawElem Int
j Bool
isSelected e
e
selItemAttr :: Widget n -> Widget n
selItemAttr = if Bool
foc
then AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
listSelectedFocusedAttr
else AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
listSelectedAttr
makeVisible :: Widget n -> Widget n
makeVisible = if Bool
isSelected
then Widget n -> Widget n
forall n. Widget n -> Widget n
visible (Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Widget n -> Widget n
forall n. Widget n -> Widget n
selItemAttr
else Widget n -> Widget n
forall a. a -> a
id
in Widget n -> Widget n
forall n. Widget n -> Widget n
makeVisible Widget n
elemWidget
Widget n -> RenderM n (Result n)
forall n. Widget n -> RenderM n (Result n)
render (Widget n -> RenderM n (Result n))
-> Widget n -> RenderM n (Result n)
forall a b. (a -> b) -> a -> b
$ n -> ViewportType -> Widget n -> Widget n
forall n.
(Ord n, Show n) =>
n -> ViewportType -> Widget n -> Widget n
viewport (GenericList n t e
lGenericList n t e -> Getting n (GenericList n t e) n -> n
forall s a. s -> Getting a s a -> a
^.Getting n (GenericList n t e) n
forall n (t :: * -> *) e n (f :: * -> *).
Functor f =>
(n -> f n) -> GenericList n t e -> f (GenericList n t e)
listNameL) ViewportType
Vertical (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$
Location -> Widget n -> Widget n
forall n. Location -> Widget n -> Widget n
translateBy ((Int, Int) -> Location
Location (Int
0, Int
off)) (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$
[Widget n] -> Widget n
forall n. [Widget n] -> Widget n
vBox ([Widget n] -> Widget n) -> [Widget n] -> Widget n
forall a b. (a -> b) -> a -> b
$ t (Widget n) -> [Widget n]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList t (Widget n)
drawnElements
listInsert :: (Splittable t, Applicative t, Semigroup (t e))
=> Int
-> e
-> GenericList n t e
-> GenericList n t e
listInsert :: forall (t :: * -> *) e n.
(Splittable t, Applicative t, Semigroup (t e)) =>
Int -> e -> GenericList n t e -> GenericList n t e
listInsert Int
pos e
e GenericList n t e
l =
let es :: t e
es = GenericList n t e
lGenericList n t e -> Getting (t e) (GenericList n t e) (t e) -> t e
forall s a. s -> Getting a s a -> a
^.Getting (t e) (GenericList n t e) (t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL
newSel :: Int
newSel = case GenericList n t e
lGenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL of
Maybe Int
Nothing -> Int
0
Just Int
s -> if Int
pos Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
s
then Int
s Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
else Int
s
(t e
front, t e
back) = Int -> t e -> (t e, t e)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
pos t e
es
in GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Maybe Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int -> Maybe Int
forall a. a -> Maybe a
Just Int
newSel
GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL ((t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e))
-> t e -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ NonEmpty (t e) -> t e
forall a. Semigroup a => NonEmpty a -> a
sconcat (t e
front t e -> [t e] -> NonEmpty (t e)
forall a. a -> [a] -> NonEmpty a
:| [e -> t e
forall a. a -> t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure e
e, t e
back])
listRemove :: (Splittable t, Foldable t, Semigroup (t e))
=> Int
-> GenericList n t e
-> GenericList n t e
listRemove :: forall (t :: * -> *) e n.
(Splittable t, Foldable t, Semigroup (t e)) =>
Int -> GenericList n t e -> GenericList n t e
listRemove Int
pos GenericList n t e
l | GenericList n t e -> Bool
forall a. GenericList n t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null GenericList n t e
l = GenericList n t e
l
| Int
pos Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= GenericList n t e -> Int -> Int
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> Int -> Int
splitClamp GenericList n t e
l Int
pos = GenericList n t e
l
| Bool
otherwise =
let newSel :: Int
newSel = case GenericList n t e
lGenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL of
Maybe Int
Nothing -> Int
0
Just Int
s | Int
pos Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Int
0
| Int
pos Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
s -> Int
pos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
| Int
pos Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
s -> Int
s Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
| Bool
otherwise -> Int
s
(t e
front, t e
rest) = Int -> t e -> (t e, t e)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
pos t e
es
(t e
_, t e
back) = Int -> t e -> (t e, t e)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
1 t e
rest
es' :: t e
es' = t e
front t e -> t e -> t e
forall a. Semigroup a => a -> a -> a
<> t e
back
es :: t e
es = GenericList n t e
lGenericList n t e -> Getting (t e) (GenericList n t e) (t e) -> t e
forall s a. s -> Getting a s a -> a
^.Getting (t e) (GenericList n t e) (t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL
in GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Maybe Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (if t e -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t e
es' then Maybe Int
forall a. Maybe a
Nothing else Int -> Maybe Int
forall a. a -> Maybe a
Just Int
newSel)
GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL ((t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e))
-> t e -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ t e
es'
listReplace :: (Foldable t, Splittable t)
=> t e
-> Maybe Int
-> GenericList n t e
-> GenericList n t e
listReplace :: forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
t e -> Maybe Int -> GenericList n t e -> GenericList n t e
listReplace t e
es Maybe Int
idx GenericList n t e
l =
let l' :: GenericList n t e
l' = GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL ((t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e))
-> t e -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ t e
es
newSel :: Maybe Int
newSel = if t e -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t e
es then Maybe Int
forall a. Maybe a
Nothing else Int -> Int
inBoundsOrZero (Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Int
idx
inBoundsOrZero :: Int -> Int
inBoundsOrZero Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== GenericList n t e -> Int -> Int
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> Int -> Int
splitClamp GenericList n t e
l' Int
i = Int
i
| Bool
otherwise = Int
0
in GenericList n t e
l' GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Maybe Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe Int
newSel
listMoveUp :: (Foldable t, Splittable t)
=> GenericList n t e
-> GenericList n t e
listMoveUp :: forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveUp = Int -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveBy (-Int
1)
listMovePageUp :: (Foldable t, Splittable t, Ord n)
=> EventM n (GenericList n t e) ()
listMovePageUp :: forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
EventM n (GenericList n t e) ()
listMovePageUp = Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> EventM n (GenericList n t e) ()
listMoveByPages (-Double
1::Double)
listMoveDown :: (Foldable t, Splittable t)
=> GenericList n t e
-> GenericList n t e
listMoveDown :: forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown = Int -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveBy Int
1
listMovePageDown :: (Foldable t, Splittable t, Ord n)
=> EventM n (GenericList n t e) ()
listMovePageDown :: forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
EventM n (GenericList n t e) ()
listMovePageDown = Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> EventM n (GenericList n t e) ()
listMoveByPages (Double
1::Double)
listMoveByPages :: (Foldable t, Splittable t, Ord n, RealFrac m)
=> m
-> EventM n (GenericList n t e) ()
listMoveByPages :: forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> EventM n (GenericList n t e) ()
listMoveByPages m
pages = do
GenericList n t e
theList <- EventM n (GenericList n t e) (GenericList n t e)
forall s (m :: * -> *). MonadState s m => m s
get
Maybe Viewport
v <- n -> EventM n (GenericList n t e) (Maybe Viewport)
forall n s. Ord n => n -> EventM n s (Maybe Viewport)
lookupViewport (GenericList n t e
theListGenericList n t e -> Getting n (GenericList n t e) n -> n
forall s a. s -> Getting a s a -> a
^.Getting n (GenericList n t e) n
forall n (t :: * -> *) e n (f :: * -> *).
Functor f =>
(n -> f n) -> GenericList n t e -> f (GenericList n t e)
listNameL)
case Maybe Viewport
v of
Maybe Viewport
Nothing -> () -> EventM n (GenericList n t e) ()
forall a. a -> EventM n (GenericList n t e) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just Viewport
vp -> do
let nElems :: Int
nElems = m -> Int
forall b. Integral b => m -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (m -> Int) -> m -> Int
forall a b. (a -> b) -> a -> b
$ m
pages m -> m -> m
forall a. Num a => a -> a -> a
* Int -> m
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Viewport
vpViewport -> Getting Int Viewport Int -> Int
forall s a. s -> Getting a s a -> a
^.((Int, Int) -> Const Int (Int, Int))
-> Viewport -> Const Int Viewport
Lens' Viewport (Int, Int)
vpSize(((Int, Int) -> Const Int (Int, Int))
-> Viewport -> Const Int Viewport)
-> ((Int -> Const Int Int) -> (Int, Int) -> Const Int (Int, Int))
-> Getting Int Viewport Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Int -> Const Int Int) -> (Int, Int) -> Const Int (Int, Int)
forall s t a b. Field2 s t a b => Lens s t a b
Lens (Int, Int) (Int, Int) Int Int
_2) m -> m -> m
forall a. Fractional a => a -> a -> a
/
Int -> m
forall a b. (Integral a, Num b) => a -> b
fromIntegral (GenericList n t e
theListGenericList n t e -> Getting Int (GenericList n t e) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (GenericList n t e) Int
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Int -> f Int) -> GenericList n t e -> f (GenericList n t e)
listItemHeightL)
(GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ())
-> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ Int -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveBy Int
nElems
listMoveBy :: (Foldable t, Splittable t)
=> Int
-> GenericList n t e
-> GenericList n t e
listMoveBy :: forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveBy Int
amt GenericList n t e
l =
let target :: Int
target = case GenericList n t e
l GenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL of
Maybe Int
Nothing
| Int
amt Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 -> Int
0
| Bool
otherwise -> GenericList n t e -> Int
forall a. GenericList n t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length GenericList n t e
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
Just Int
i -> Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
amt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i)
in Int -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
target GenericList n t e
l
listMoveTo :: (Foldable t, Splittable t)
=> Int
-> GenericList n t e
-> GenericList n t e
listMoveTo :: forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
pos GenericList n t e
l =
let len :: Int
len = GenericList n t e -> Int
forall a. GenericList n t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length GenericList n t e
l
i :: Int
i = if Int
pos Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 then Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
pos else Int
pos
newSel :: Int
newSel = GenericList n t e -> Int -> Int
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> Int -> Int
splitClamp GenericList n t e
l Int
i
in GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Maybe Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ if GenericList n t e -> Bool
forall a. GenericList n t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null GenericList n t e
l then Maybe Int
forall a. Maybe a
Nothing else Int -> Maybe Int
forall a. a -> Maybe a
Just Int
newSel
splitClamp :: (Foldable t, Splittable t) => GenericList n t e -> Int -> Int
splitClamp :: forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> Int -> Int
splitClamp GenericList n t e
l Int
i =
let (t e
_, t e
t) = Int -> t e -> (t e, t e)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
i (GenericList n t e
l GenericList n t e -> Getting (t e) (GenericList n t e) (t e) -> t e
forall s a. s -> Getting a s a -> a
^. Getting (t e) (GenericList n t e) (t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL)
in
Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
0 (if t e -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t e
t then GenericList n t e -> Int
forall a. GenericList n t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length GenericList n t e
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 else Int
i) Int
i
listMoveToElement :: (Eq e, Foldable t, Splittable t)
=> e
-> GenericList n t e
-> GenericList n t e
listMoveToElement :: forall e (t :: * -> *) n.
(Eq e, Foldable t, Splittable t) =>
e -> GenericList n t e -> GenericList n t e
listMoveToElement e
e = (e -> Bool) -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listFindBy (e -> e -> Bool
forall a. Eq a => a -> a -> Bool
== e
e) (GenericList n t e -> GenericList n t e)
-> (GenericList n t e -> GenericList n t e)
-> GenericList n t e
-> GenericList n t e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
(GenericList n t e) (GenericList n t e) (Maybe Int) (Maybe Int)
-> Maybe Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter
(GenericList n t e) (GenericList n t e) (Maybe Int) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL Maybe Int
forall a. Maybe a
Nothing
listFindBy :: (Foldable t, Splittable t)
=> (e -> Bool)
-> GenericList n t e
-> GenericList n t e
listFindBy :: forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listFindBy e -> Bool
test GenericList n t e
l =
let start :: Int
start = Int -> (Int -> Int) -> Maybe Int -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (GenericList n t e
l GenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL)
(t e
h, t e
t) = Int -> t e -> (t e, t e)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
start (GenericList n t e
l GenericList n t e -> Getting (t e) (GenericList n t e) (t e) -> t e
forall s a. s -> Getting a s a -> a
^. Getting (t e) (GenericList n t e) (t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL)
tailResult :: Maybe (Int, e)
tailResult = ((Int, e) -> Bool) -> [(Int, e)] -> Maybe (Int, e)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (e -> Bool
test (e -> Bool) -> ((Int, e) -> e) -> (Int, e) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, e) -> e
forall a b. (a, b) -> b
snd) ([(Int, e)] -> Maybe (Int, e))
-> (t e -> [(Int, e)]) -> t e -> Maybe (Int, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [e] -> [(Int, e)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
start..] ([e] -> [(Int, e)]) -> (t e -> [e]) -> t e -> [(Int, e)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t e -> [e]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (t e -> Maybe (Int, e)) -> t e -> Maybe (Int, e)
forall a b. (a -> b) -> a -> b
$ t e
t
headResult :: Maybe (Int, e)
headResult = ((Int, e) -> Bool) -> [(Int, e)] -> Maybe (Int, e)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (e -> Bool
test (e -> Bool) -> ((Int, e) -> e) -> (Int, e) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, e) -> e
forall a b. (a, b) -> b
snd) ([(Int, e)] -> Maybe (Int, e))
-> (t e -> [(Int, e)]) -> t e -> Maybe (Int, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [e] -> [(Int, e)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] ([e] -> [(Int, e)]) -> (t e -> [e]) -> t e -> [(Int, e)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t e -> [e]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (t e -> Maybe (Int, e)) -> t e -> Maybe (Int, e)
forall a b. (a -> b) -> a -> b
$ t e
h
result :: Maybe (Int, e)
result = Maybe (Int, e)
tailResult Maybe (Int, e) -> Maybe (Int, e) -> Maybe (Int, e)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (Int, e)
headResult
in (GenericList n t e -> GenericList n t e)
-> ((Int, e) -> GenericList n t e -> GenericList n t e)
-> Maybe (Int, e)
-> GenericList n t e
-> GenericList n t e
forall b a. b -> (a -> b) -> Maybe a -> b
maybe GenericList n t e -> GenericList n t e
forall a. a -> a
id (ASetter
(GenericList n t e) (GenericList n t e) (Maybe Int) (Maybe Int)
-> Maybe Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter
(GenericList n t e) (GenericList n t e) (Maybe Int) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL (Maybe Int -> GenericList n t e -> GenericList n t e)
-> ((Int, e) -> Maybe Int)
-> (Int, e)
-> GenericList n t e
-> GenericList n t e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> ((Int, e) -> Int) -> (Int, e) -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, e) -> Int
forall a b. (a, b) -> a
fst) Maybe (Int, e)
result GenericList n t e
l
listSelectedElementL :: (Splittable t, Traversable t, Semigroup (t e))
=> Traversal' (GenericList n t e) e
listSelectedElementL :: forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
Traversal' (GenericList n t e) e
listSelectedElementL e -> f e
f GenericList n t e
l =
case GenericList n t e
l GenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL of
Maybe Int
Nothing -> GenericList n t e -> f (GenericList n t e)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GenericList n t e
l
Just Int
i -> (t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL t e -> f (t e)
forall {t :: * -> *}.
(Semigroup (t e), Traversable t, Splittable t) =>
t e -> f (t e)
go GenericList n t e
l
where
go :: t e -> f (t e)
go t e
l' = let (t e
left, t e
rest) = Int -> t e -> (t e, t e)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
i t e
l'
(t e
middle, t e
right) = Int -> t e -> (t e, t e)
forall a. Int -> t a -> (t a, t a)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
1 t e
rest
in (\t e
m -> t e
left t e -> t e -> t e
forall a. Semigroup a => a -> a -> a
<> t e
m t e -> t e -> t e
forall a. Semigroup a => a -> a -> a
<> t e
right) (t e -> t e) -> f (t e) -> f (t e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((e -> f e) -> t e -> f (t e)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b)
traverse e -> f e
f t e
middle)
listSelectedElement :: (Splittable t, Traversable t, Semigroup (t e))
=> GenericList n t e
-> Maybe (Int, e)
listSelectedElement :: forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement GenericList n t e
l =
(,) (Int -> e -> (Int, e)) -> Maybe Int -> Maybe (e -> (Int, e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList n t e
lGenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL Maybe (e -> (Int, e)) -> Maybe e -> Maybe (Int, e)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GenericList n t e
lGenericList n t e
-> Getting (First e) (GenericList n t e) e -> Maybe e
forall s a. s -> Getting (First a) s a -> Maybe a
^?Getting (First e) (GenericList n t e) e
Traversal' (GenericList n t e) e
forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
Traversal' (GenericList n t e) e
listSelectedElementL
listClear :: (Monoid (t e)) => GenericList n t e -> GenericList n t e
listClear :: forall (t :: * -> *) e n.
Monoid (t e) =>
GenericList n t e -> GenericList n t e
listClear GenericList n t e
l = GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL ((t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e))
-> t e -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ t e
forall a. Monoid a => a
mempty GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Maybe Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe Int
forall a. Maybe a
Nothing
listReverse :: (Reversible t, Foldable t)
=> GenericList n t e
-> GenericList n t e
listReverse :: forall (t :: * -> *) n e.
(Reversible t, Foldable t) =>
GenericList n t e -> GenericList n t e
listReverse GenericList n t e
l =
GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (t :: * -> *) e (f :: * -> *).
Functor f =>
(t e -> f (t e)) -> GenericList n t e -> f (GenericList n t e)
listElementsL ((t e -> Identity (t e))
-> GenericList n t e -> Identity (GenericList n t e))
-> (t e -> t e) -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ t e -> t e
forall a. t a -> t a
forall (t :: * -> *) a. Reversible t => t a -> t a
reverse
GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> (Maybe Int -> Maybe Int)
-> GenericList n t e
-> GenericList n t e
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Int -> Int) -> Maybe Int -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GenericList n t e -> Int
forall a. GenericList n t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length GenericList n t e
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
-)
listModify :: (Traversable t, Splittable t, Semigroup (t e))
=> (e -> e)
-> GenericList n t e
-> GenericList n t e
listModify :: forall (t :: * -> *) e n.
(Traversable t, Splittable t, Semigroup (t e)) =>
(e -> e) -> GenericList n t e -> GenericList n t e
listModify e -> e
f = (e -> Identity e)
-> GenericList n t e -> Identity (GenericList n t e)
Traversal' (GenericList n t e) e
forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
Traversal' (GenericList n t e) e
listSelectedElementL ((e -> Identity e)
-> GenericList n t e -> Identity (GenericList n t e))
-> (e -> e) -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ e -> e
f