List widget
This module provides list widgets for displaying and interacting with collections of items, with support for selection, scrolling, and styling.
Types
List = ref object of Widget items*: seq[ListItem] state*: ListState selectionMode*: SelectionMode selectedIndices*: seq[int] highlightedIndex*: int scrollOffset*: int visibleCount*: int normalStyle*: Style selectedStyle*: Style highlightedStyle*: Style disabledStyle*: Style bulletPrefix*: string showScrollbar*: bool onSelect*: proc (index: int) onMultiSelect*: proc (indices: seq[int]) onHighlight*: proc (index: int)
- List widget for displaying items
ListItem = object text*: string style*: Option[Style] selectable*: bool
- Individual list item with optional custom style
ListState = enum Normal, Focused, Disabled
- List visual states
SelectionMode = enum None, Single, Multiple
- List selection behavior
Procs
proc bulletList(items: seq[string]; bullet: string = "• "): List {....raises: [], tags: [], forbids: [].}
- Create a bulleted list
proc clearItems(widget: List) {....raises: [], tags: [], forbids: [].}
- Clear all items from the list
proc clearSelection(widget: List) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Clear all selections
proc deselectItem(widget: List; index: int) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Deselect an item (for multiple selection mode)
proc getItemStyle(widget: List; index: int): Style {....raises: [], tags: [], forbids: [].}
- Get the style for a specific item
proc handleKeyEvent(widget: List; event: KeyEvent): bool {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Handle keyboard input for the list Returns true if the event was handled
proc handleMouseEvent(widget: List; event: MouseEvent; area: Rect): bool {. ...raises: [Exception], tags: [RootEffect], forbids: [].}
- Handle mouse input for the list Returns true if the event was handled
proc highlightFirst(widget: List) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to first selectable item
proc highlightLast(widget: List) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to last selectable item
proc highlightNext(widget: List) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to next selectable item
proc highlightPrevious(widget: List) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to previous selectable item
proc isSelected(widget: List; index: int): bool {....raises: [], tags: [], forbids: [].}
- Check if an item is selected
proc list(items: seq[string]; selectionMode: SelectionMode = Single): List {. ...raises: [], tags: [], forbids: [].}
- Convenience constructor for List widget from strings
proc newList(items: seq[ListItem] = @[]; selectionMode: SelectionMode = Single; normalStyle: Style = defaultStyle(); selectedStyle: Style = style(Black, White); highlightedStyle: Style = style(White, BrightBlack); disabledStyle: Style = style(BrightBlack, Reset); bulletPrefix: string = ""; showScrollbar: bool = true; onSelect: proc (index: int) = nil; onMultiSelect: proc (indices: seq[int]) = nil; onHighlight: proc (index: int) = nil): List {....raises: [], tags: [], forbids: [].}
- Create a new List widget
proc newListItem(text: string; style: Option[Style] = none(Style); selectable: bool = true): ListItem {....raises: [], tags: [], forbids: [].}
- Create a new list item
proc removeItem(widget: List; index: int) {....raises: [], tags: [], forbids: [].}
- Remove an item from the list
proc renderScrollbar(widget: List; area: Rect; buf: var Buffer) {....raises: [], tags: [], forbids: [].}
- Render a scrollbar on the right edge
proc scrollDown(widget: List; lines: int = 1) {....raises: [], tags: [], forbids: [].}
- Scroll the list down
proc selectItem(widget: List; index: int) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Select an item (respecting selection mode)
proc selectList(items: seq[string]; onSelect: proc (index: int) = nil): List {. ...raises: [], tags: [], forbids: [].}
- Create a single-selection list
proc setEnabled(widget: List; enabled: bool) {....raises: [], tags: [], forbids: [].}
- Enable or disable the list
proc simpleList(items: seq[string]): List {....raises: [], tags: [], forbids: [].}
- Create a simple list with no selection
proc toggleSelection(widget: List; index: int) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Toggle selection of an item
proc withBulletPrefix(widget: List; prefix: string): List {....raises: [], tags: [], forbids: [].}
- Create a copy with different bullet prefix
proc withScrollbar(widget: List; show: bool): List {....raises: [], tags: [], forbids: [].}
- Create a copy with scrollbar visibility setting
proc withSelectionMode(widget: List; mode: SelectionMode): List {....raises: [], tags: [], forbids: [].}
- Create a copy with different selection mode
Methods
method getMinSize(widget: List): Size {....raises: [], tags: [], forbids: [].}
- Get minimum size for list widget
method getPreferredSize(widget: List; available: Size): Size {....raises: [], tags: [], forbids: [].}
- Get preferred size for list widget