{-# LANGUAGE TupleSections #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable#-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
module Brick.Widgets.List
( GenericList
, List
, list
, renderList
, renderListWithIndex
, handleListEvent
, handleListEventVi
, listElementsL
, listSelectedL
, listNameL
, listItemHeightL
, 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 ((<|>))
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>), (<*>), pure)
import Data.Foldable (Foldable, find, toList)
import Data.Traversable (Traversable)
#else
import Data.Foldable (find, toList)
#endif
import Control.Monad.Trans.State (evalState, get, put)
import Lens.Micro ((^.), (^?), (&), (.~), (%~), _2, _head, 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 { GenericList n t e -> t e
listElements :: !(t e)
, GenericList n t e -> Maybe Int
listSelected :: !(Maybe Int)
, GenericList n t e -> n
listName :: n
, GenericList n t e -> Int
listItemHeight :: Int
} deriving (a -> GenericList n t b -> GenericList n t a
(a -> b) -> GenericList n t a -> GenericList n t b
(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
<$ :: a -> GenericList n t b -> GenericList n t a
$c<$ :: forall n (t :: * -> *) a b.
Functor t =>
a -> GenericList n t b -> GenericList n t a
fmap :: (a -> b) -> GenericList n t a -> GenericList n t b
$cfmap :: forall n (t :: * -> *) a b.
Functor t =>
(a -> b) -> GenericList n t a -> GenericList n t b
Functor, GenericList n t a -> Bool
(a -> m) -> GenericList n t a -> m
(a -> b -> b) -> b -> GenericList n t a -> b
(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
product :: GenericList n t a -> a
$cproduct :: forall n (t :: * -> *) a.
(Foldable t, Num a) =>
GenericList n t a -> a
sum :: GenericList n t a -> a
$csum :: forall n (t :: * -> *) a.
(Foldable t, Num a) =>
GenericList n t a -> a
minimum :: GenericList n t a -> a
$cminimum :: forall n (t :: * -> *) a.
(Foldable t, Ord a) =>
GenericList n t a -> a
maximum :: GenericList n t a -> a
$cmaximum :: forall n (t :: * -> *) a.
(Foldable t, Ord a) =>
GenericList n t a -> a
elem :: a -> GenericList n t a -> Bool
$celem :: forall n (t :: * -> *) a.
(Foldable t, Eq a) =>
a -> GenericList n t a -> Bool
length :: GenericList n t a -> Int
$clength :: forall n (t :: * -> *) a. Foldable t => GenericList n t a -> Int
null :: GenericList n t a -> Bool
$cnull :: forall n (t :: * -> *) a. Foldable t => GenericList n t a -> Bool
toList :: GenericList n t a -> [a]
$ctoList :: forall n (t :: * -> *) a. Foldable t => GenericList n t a -> [a]
foldl1 :: (a -> a -> a) -> GenericList n t a -> a
$cfoldl1 :: forall n (t :: * -> *) a.
Foldable t =>
(a -> a -> a) -> GenericList n t a -> a
foldr1 :: (a -> a -> a) -> GenericList n t a -> a
$cfoldr1 :: forall n (t :: * -> *) a.
Foldable t =>
(a -> a -> a) -> GenericList n t a -> a
foldl' :: (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 :: (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
foldr' :: (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 :: (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
foldMap' :: (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 :: (a -> m) -> GenericList n t a -> m
$cfoldMap :: forall n (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> GenericList n t a -> m
fold :: GenericList n t m -> m
$cfold :: forall n (t :: * -> *) m.
(Foldable t, Monoid m) =>
GenericList n t m -> m
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)
(a -> f b) -> GenericList n t a -> f (GenericList n t b)
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)
sequence :: GenericList n t (m a) -> m (GenericList n t a)
$csequence :: forall n (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
GenericList n t (m a) -> m (GenericList n t a)
mapM :: (a -> m b) -> GenericList n t a -> m (GenericList n t b)
$cmapM :: forall n (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> GenericList n t a -> m (GenericList n t b)
sequenceA :: GenericList n t (f a) -> f (GenericList n t a)
$csequenceA :: forall n (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
GenericList n t (f a) -> f (GenericList n t a)
traverse :: (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)
$cp2Traversable :: forall n (t :: * -> *). Traversable t => Foldable (GenericList n t)
$cp1Traversable :: forall n (t :: * -> *). Traversable t => Functor (GenericList n t)
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
showList :: [GenericList n t e] -> ShowS
$cshowList :: forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
[GenericList n t e] -> ShowS
show :: GenericList n t e -> String
$cshow :: forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
GenericList n t e -> String
showsPrec :: Int -> GenericList n t e -> ShowS
$cshowsPrec :: forall n (t :: * -> *) e.
(Show n, Show (t e)) =>
Int -> 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
$cto :: forall n (t :: * -> *) e x.
Rep (GenericList n t e) x -> GenericList n t e
$cfrom :: forall n (t :: * -> *) e x.
GenericList n t e -> Rep (GenericList n t e) x
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 (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 (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
i
instance Splittable V.Vector where
splitAt :: 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 :: 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 :: Vector a -> Vector a
reverse = Vector a -> Vector a
forall a. Vector a -> Vector a
V.reverse
instance Reversible Seq.Seq where
reverse :: 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
-> GenericList n t e
-> EventM n (GenericList n t e)
handleListEvent :: Event -> GenericList n t e -> EventM n (GenericList n t e)
handleListEvent Event
e GenericList n t e
theList =
case Event
e of
EvKey Key
KUp [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey Key
KDown [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey Key
KHome [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey Key
KEnd [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey Key
KPageDown [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
GenericList n t e -> EventM n (GenericList n t e)
listMovePageDown GenericList n t e
theList
EvKey Key
KPageUp [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
GenericList n t e -> EventM n (GenericList n t e)
listMovePageUp GenericList n t e
theList
Event
_ -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return GenericList n t e
theList
handleListEventVi :: (Foldable t, Splittable t, Ord n)
=> (Event -> GenericList n t e -> EventM n (GenericList n t e))
-> Event
-> GenericList n t e
-> EventM n (GenericList n t e)
handleListEventVi :: (Event -> GenericList n t e -> EventM n (GenericList n t e))
-> Event -> GenericList n t e -> EventM n (GenericList n t e)
handleListEventVi Event -> GenericList n t e -> EventM n (GenericList n t e)
fallback Event
e GenericList n t e
theList =
case Event
e of
EvKey (KChar Char
'k') [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey (KChar Char
'j') [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey (KChar Char
'g') [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey (KChar Char
'G') [] -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (GenericList n t e))
-> GenericList n t e -> EventM n (GenericList n t e)
forall a b. (a -> b) -> a -> b
$ 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 GenericList n t e
theList
EvKey (KChar Char
'f') [Modifier
MCtrl] -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
GenericList n t e -> EventM n (GenericList n t e)
listMovePageDown GenericList n t e
theList
EvKey (KChar Char
'b') [Modifier
MCtrl] -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
GenericList n t e -> EventM n (GenericList n t e)
listMovePageUp GenericList n t e
theList
EvKey (KChar Char
'd') [Modifier
MCtrl] -> Double -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> GenericList n t e -> EventM n (GenericList n t e)
listMoveByPages (Double
0.5::Double) GenericList n t e
theList
EvKey (KChar Char
'u') [Modifier
MCtrl] -> Double -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> GenericList n t e -> EventM n (GenericList n t e)
listMoveByPages (-Double
0.5::Double) GenericList n t e
theList
Event
_ -> Event -> GenericList n t e -> EventM n (GenericList n t e)
fallback Event
e GenericList n t e
theList
listMoveToBeginning :: (Foldable t, Splittable t)
=> GenericList n t e
-> GenericList n t e
listMoveToBeginning :: 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 :: 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 (t e -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (t e -> Int) -> t e -> Int
forall a b. (a -> b) -> a -> b
$ GenericList n t e -> t e
forall n (t :: * -> *) e. GenericList n t e -> t e
listElements GenericList n t e
l) GenericList n t e
l
listAttr :: AttrName
listAttr :: AttrName
listAttr = AttrName
"list"
listSelectedAttr :: AttrName
listSelectedAttr :: AttrName
listSelectedAttr = AttrName
listAttr AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> AttrName
"selected"
listSelectedFocusedAttr :: AttrName
listSelectedFocusedAttr :: AttrName
listSelectedFocusedAttr = AttrName
listSelectedAttr AttrName -> AttrName -> AttrName
forall a. Semigroup a => a -> a -> a
<> AttrName
"focused"
list :: (Foldable t)
=> n
-> t e
-> Int
-> GenericList n t e
list :: 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 (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 :: (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 :: (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 :: (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)
traverse (\a
a -> StateT Int Identity Int
forall (m :: * -> *) s. Monad m => StateT s m s
get StateT Int Identity Int
-> (Int -> 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 (m :: * -> *) s. Monad m => s -> StateT 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 :: 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
c <- RenderM n Context
forall n. RenderM n Context
getContext
let es :: t e
es = Int -> Int -> t e -> t e
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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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. Lens' (GenericList n t e) (Maybe Int)
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
cContext -> Getting Int Context Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int Context Int
Lens' Context Int
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. Lens' (GenericList n t e) Int
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. Lens' (GenericList n t e) Int
listItemHeightL) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Context
cContext -> Getting Int Context Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int Context Int
Lens' Context Int
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. Lens' (GenericList n t e) Int
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. Lens' (GenericList n t e) (Maybe Int)
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.
Lens (GenericList n t e) (GenericList n t e) n n
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 (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 :: 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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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. Lens' (GenericList n t e) (Maybe Int)
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 (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. Lens' (GenericList n t e) (Maybe Int)
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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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 (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 :: Int -> GenericList n t e -> GenericList n t e
listRemove Int
pos GenericList n t e
l | GenericList n t e -> 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. Lens' (GenericList n t e) (Maybe Int)
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 (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 (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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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. Lens' (GenericList n t e) (Maybe Int)
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 (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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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 :: 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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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 (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. Lens' (GenericList n t e) (Maybe Int)
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 :: 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)
=> GenericList n t e
-> EventM n (GenericList n t e)
listMovePageUp :: GenericList n t e -> EventM n (GenericList n t e)
listMovePageUp = Double -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> GenericList n t e -> EventM n (GenericList n t e)
listMoveByPages (-Double
1::Double)
listMoveDown :: (Foldable t, Splittable t)
=> GenericList n t e
-> GenericList n t e
listMoveDown :: 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)
=> GenericList n t e
-> EventM n (GenericList n t e)
listMovePageDown :: GenericList n t e -> EventM n (GenericList n t e)
listMovePageDown = Double -> GenericList n t e -> EventM n (GenericList n t e)
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> GenericList n t e -> EventM n (GenericList n t e)
listMoveByPages (Double
1::Double)
listMoveByPages :: (Foldable t, Splittable t, Ord n, RealFrac m)
=> m
-> GenericList n t e
-> EventM n (GenericList n t e)
listMoveByPages :: m -> GenericList n t e -> EventM n (GenericList n t e)
listMoveByPages m
pages GenericList n t e
theList = do
Maybe Viewport
v <- n -> EventM n (Maybe Viewport)
forall n. Ord n => n -> EventM n (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.
Lens (GenericList n t e) (GenericList n t e) n n
listNameL)
case Maybe Viewport
v of
Maybe Viewport
Nothing -> GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return GenericList n t e
theList
Just Viewport
vp -> do
let nElems :: Int
nElems = m -> Int
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
_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. Lens' (GenericList n t e) Int
listItemHeightL)
GenericList n t e -> EventM n (GenericList n t e)
forall (m :: * -> *) a. Monad m => a -> m a
return (GenericList n t e -> EventM n (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 GenericList n t e
theList
listMoveBy :: (Foldable t, Splittable t)
=> Int
-> GenericList n t e
-> GenericList n t e
listMoveBy :: 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. Lens' (GenericList n t e) (Maybe Int)
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 (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 :: 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 (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. Lens' (GenericList n t e) (Maybe Int)
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 (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 :: 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 (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.
Lens (GenericList n t e) (GenericList n t e) (t e) (t e)
listElementsL)
in
Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
0 (if t e -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t e
t then GenericList n t e -> 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 :: 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. Lens' (GenericList n t e) (Maybe Int)
listSelectedL Maybe Int
forall a. Maybe a
Nothing
listFindBy :: (Foldable t, Splittable t)
=> (e -> Bool)
-> GenericList n t e
-> GenericList n t e
listFindBy :: (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. Lens' (GenericList n t e) (Maybe Int)
listSelectedL)
(t e
h, t e
t) = Int -> t e -> (t e, t e)
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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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 (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 (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 (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. Lens' (GenericList n t e) (Maybe Int)
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
listSelectedElement :: (Splittable t, Foldable t)
=> GenericList n t e
-> Maybe (Int, e)
listSelectedElement :: GenericList n t e -> Maybe (Int, e)
listSelectedElement GenericList n t e
l = do
Int
sel <- 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. Lens' (GenericList n t e) (Maybe Int)
listSelectedL
let (t e
_, t e
xs) = Int -> t e -> (t e, t e)
forall (t :: * -> *) a. Splittable t => Int -> t a -> (t a, t a)
splitAt Int
sel (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.
Lens (GenericList n t e) (GenericList n t e) (t e) (t e)
listElementsL)
(Int
sel,) (e -> (Int, e)) -> Maybe e -> Maybe (Int, e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t e -> [e]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList t e
xs [e] -> Getting (First e) [e] e -> Maybe e
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting (First e) [e] e
forall s a. Cons s s a a => Traversal' s a
_head
listClear :: (Monoid (t e)) => GenericList n t e -> GenericList n t e
listClear :: 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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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. Lens' (GenericList n t e) (Maybe Int)
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 :: 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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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 (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. Lens' (GenericList n t e) (Maybe Int)
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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GenericList n t e -> 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)
=> (e -> e)
-> GenericList n t e
-> GenericList n t e
listModify :: (e -> e) -> GenericList n t e -> GenericList n t e
listModify e -> 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. Lens' (GenericList n t e) (Maybe Int)
listSelectedL of
Maybe Int
Nothing -> GenericList n t e
l
Just Int
j -> 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.
Lens (GenericList n t e) (GenericList n t e) (t e) (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
%~ (Int -> e -> e) -> t e -> t e
forall (t :: * -> *) a b.
Traversable t =>
(Int -> a -> b) -> t a -> t b
imap (\Int
i e
e -> if Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
j then e -> e
f e
e else e
e)