ConsoleForge 0.3.0
Elm-architecture TUI framework for .NET 8
Loading...
Searching...
No Matches
ConsoleForge.Widgets.List Class Referencesealed

A scrollable list widget that displays items and highlights the selected one. More...

Inheritance diagram for ConsoleForge.Widgets.List:

Public Member Functions

 List ()
 Object-initializer constructor; all properties default.
 List (IReadOnlyList< string > items, int selectedIndex=0, Style? style=null, Style? selectedItemStyle=null, int paddingLeft=1, int paddingRight=0, int scrollOffset=0)
 Positional constructor for inline usage.
void OnKeyEvent (KeyMsg key, Action< IMsg > dispatch)
 Called by the runtime when a key is pressed and this widget has focus.Call dispatch to inject a custom IMsg into the event loop.
void Render (IRenderContext ctx)
 Render this widget into the provided context.The context carries the allocated region, theme, and color profile. Implementations MUST NOT write outside ctx.Region.

Static Public Member Functions

static int ComputeScrollOffset (int selectedIndex, int viewportHeight, int currentScrollOffset)
 Computes a new ScrollOffset that keeps selectedIndex within the visible viewport.

Properties

bool HasFocus [get, set]
 True when this widget holds keyboard focus.
SizeConstraint Height = SizeConstraint.Flex(1) [get]
 Height constraint used by the layout engine.
IReadOnlyList< string > Items = [] [get]
 The display strings shown in the list.
int PaddingLeft = 1 [get]
 Number of blank columns inserted to the left of each item's text.
int PaddingRight = 0 [get]
 Number of blank columns reserved to the right of each item's text.
int ScrollOffset [get]
 Zero-based index of the first item rendered in the viewport.
int SelectedIndex [get]
 Zero-based index of the currently highlighted item.
Style SelectedItemStyle = Style.Default.Reverse(true) [get]
 Visual style applied to the highlighted row. Defaults to reverse-video.
Style Style = Style.Default [get]
 Visual style for unselected rows. Inherits theme base style when no properties set.
SizeConstraint Width = SizeConstraint.Flex(1) [get]
 Width constraint used by the layout engine.

Detailed Description

A scrollable list widget that displays items and highlights the selected one.

Dispatches ListItemSelectedMsg when the user presses Enter.

Constructor & Destructor Documentation

◆ List()

ConsoleForge.Widgets.List.List ( IReadOnlyList< string > items,
int selectedIndex = 0,
Style? style = null,
Style? selectedItemStyle = null,
int paddingLeft = 1,
int paddingRight = 0,
int scrollOffset = 0 )

Positional constructor for inline usage.

Parameters
itemsDisplay strings to show.
selectedIndexInitially highlighted row index (clamped).
styleOptional style for unselected rows.
selectedItemStyleOptional style for the highlighted row.
paddingLeftBlank columns inserted to the left of each item's text. Provides breathing room when the list is placed inside a BorderBox. Defaults to 1.
paddingRightBlank columns reserved to the right of each item's text. Defaults to 0.
scrollOffsetFirst visible item index. Defaults to 0.

Member Function Documentation

◆ ComputeScrollOffset()

int ConsoleForge.Widgets.List.ComputeScrollOffset ( int selectedIndex,
int viewportHeight,
int currentScrollOffset )
static

Computes a new ScrollOffset that keeps selectedIndex within the visible viewport.

Call this from your model's Update handler when processing ListSelectionChangedMsg.

Parameters
selectedIndexThe newly selected item index.
viewportHeightNumber of visible rows in the List's region.
currentScrollOffsetCurrent ScrollOffset.

Property Documentation

◆ PaddingLeft

int ConsoleForge.Widgets.List.PaddingLeft = 1
get

Number of blank columns inserted to the left of each item's text.

Provides breathing room when the list is placed inside a BorderBox. Defaults to 1.

◆ PaddingRight

int ConsoleForge.Widgets.List.PaddingRight = 0
get

Number of blank columns reserved to the right of each item's text.

Defaults to 0.

◆ ScrollOffset

int ConsoleForge.Widgets.List.ScrollOffset
get

Zero-based index of the first item rendered in the viewport.

Update via ComputeScrollOffset when handling ListSelectionChangedMsg to keep the selection visible.


The documentation for this class was generated from the following file:
  • src/ConsoleForge/Widgets/List.cs