Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a scrollable list type and functions for manipulating and rendering it.
- data List n e
- list :: n -> Vector e -> Int -> List n e
- renderList :: (Ord n, Show n) => (Bool -> e -> Widget n) -> Bool -> List n e -> Widget n
- handleListEvent :: Ord n => Event -> List n e -> EventM n (List n e)
- handleListEventVi :: Ord n => (Event -> List n e -> EventM n (List n e)) -> Event -> List n e -> EventM n (List n e)
- listElementsL :: forall n e e. Lens (List n e) (List n e) (Vector e) (Vector e)
- listSelectedL :: forall n e. Lens' (List n e) (Maybe Int)
- listNameL :: forall n e n. Lens (List n e) (List n e) n n
- listItemHeightL :: forall n e. Lens' (List n e) Int
- listElements :: List n e -> Vector e
- listName :: List n e -> n
- listSelectedElement :: List n e -> Maybe (Int, e)
- listSelected :: List n e -> Maybe Int
- listItemHeight :: List n e -> Int
- listMoveBy :: Int -> List n e -> List n e
- listMoveTo :: Int -> List n e -> List n e
- listMoveUp :: List n e -> List n e
- listMoveDown :: List n e -> List n e
- listMoveByPages :: (Ord n, RealFrac m) => m -> List n e -> EventM n (List n e)
- listMovePageUp :: Ord n => List n e -> EventM n (List n e)
- listMovePageDown :: Ord n => List n e -> EventM n (List n e)
- listInsert :: Int -> e -> List n e -> List n e
- listRemove :: Int -> List n e -> List n e
- listReplace :: Vector e -> Maybe Int -> List n e -> List n e
- listClear :: List n e -> List n e
- listReverse :: List n e -> List n e
- listModify :: (e -> e) -> List n e -> List n e
- listAttr :: AttrName
- listSelectedAttr :: AttrName
- listSelectedFocusedAttr :: AttrName
Documentation
List state. Lists have an element type e
that is the data stored
by the list. Lists handle the following events by default:
- Up/down arrow keys: move cursor of selected item
- Page up / page down keys: move cursor of selected item by one page at a time (based on the number of items shown)
- Home/end keys: move cursor of selected item to beginning or end of list
Constructing a list
:: n | The list name (must be unique) |
-> Vector e | The initial list contents |
-> Int | The list item height in rows (all list item widgets must be this high) |
-> List n e |
Construct a list in terms of an element type e
.
Rendering a list
:: (Ord n, Show n) | |
=> (Bool -> e -> Widget n) | Rendering function, True for the selected element |
-> Bool | Whether the list has focus |
-> List n e | The List to be rendered |
-> Widget n | rendered widget |
Turn a list state value into a widget given an item drawing function.
Handling events
:: Ord n | |
=> (Event -> List n e -> EventM n (List n e)) | Fallback event handler to use if none of the vi keys match. |
-> Event | |
-> List n e | |
-> EventM n (List n e) |
Enable list movement with the vi keys with a fallback if none match. Use (handleListEventVi handleListEvent) in place of handleListEvent to add the vi keys bindings to the standard ones. Movements handled include:
- Up (k)
- Down (j)
- Page Up (Ctrl-b)
- Page Down (Ctrl-f)
- Half Page Up (Ctrl-u)
- Half Page Down (Ctrl-d)
- Top (g)
- Bottom (G)
Lenses
Accessors
listElements :: List n e -> Vector e Source #
The list's vector of elements.
listItemHeight :: List n e -> Int Source #
The height of the list items.
Manipulating a list
listMoveBy :: Int -> List n e -> List n e Source #
Move the list selected index by the specified amount, subject to validation.
listMoveTo :: Int -> List n e -> List n e Source #
Set the selected index for a list to the specified index, subject to validation.
listMoveUp :: List n e -> List n e Source #
Move the list selected index up by one. (Moves the cursor up, subtracts one from the index.)
listMoveDown :: List n e -> List n e Source #
Move the list selected index down by one. (Moves the cursor down, adds one to the index.)
listMoveByPages :: (Ord n, RealFrac m) => m -> List n e -> EventM n (List n e) Source #
Move the list selected index by some (fractional) number of pages.
listMovePageUp :: Ord n => List n e -> EventM n (List n e) Source #
Move the list selected index up by one page.
listMovePageDown :: Ord n => List n e -> EventM n (List n e) Source #
Move the list selected index down by one page.
:: Int | The position at which to insert (0 <= i <= size) |
-> e | The element to insert |
-> List n e | |
-> List n e |
Insert an item into a list at the specified position.
Remove an element from a list at the specified position.
listReplace :: Vector e -> Maybe Int -> List n e -> List n e Source #
Replace the contents of a list with a new set of elements and
update the new selected index. If the list is empty, empty selection is used
instead. Otherwise, if the specified selected index (via Just
) is not in
the list bounds, zero is used instead.
listClear :: List n e -> List n e Source #
Remove all elements from the list and clear the selection.
listReverse :: List n e -> List n e Source #
Reverse the list. The element selected before the reversal will again be the selected one.
listModify :: (e -> e) -> List n e -> List n e Source #
Apply a function to the selected element. If no element is selected the list is not modified.
Attributes
listSelectedAttr :: AttrName Source #
The attribute used only for the currently-selected list item when
the list does not have focus. Extends listAttr
.
listSelectedFocusedAttr :: AttrName Source #
The attribute used only for the currently-selected list item when
the list has focus. Extends listSelectedAttr
.