TermUI.Widgets.Viewport (TermUI v0.2.0)
View SourceViewport widget for scrollable content.
Viewport displays a scrollable view of content larger than the viewport area. It tracks scroll position, clips content to bounds, and optionally shows scroll bars for visual feedback and interaction.
Usage
Viewport.new(
content: large_content_tree(),
width: 40,
height: 20,
scroll_bars: :both
)Features
- Scrollable view of larger content
- Automatic content clipping to viewport bounds
- Optional vertical and horizontal scroll bars
- Keyboard navigation (arrow keys, Page Up/Down, Home/End)
- Mouse wheel scrolling
- Scroll bar drag interaction
Keyboard Navigation
- Arrow keys: Scroll by one line/column
- Page Up/Down: Scroll by viewport height
- Home/End: Scroll to top/bottom
- Ctrl+Home/End: Scroll to start/end horizontally
Summary
Functions
Checks if content is scrollable horizontally.
Checks if content is scrollable vertically.
Gets the current scroll position.
Creates new Viewport widget props.
Scrolls to make a position visible.
Updates the content.
Updates the content dimensions.
Sets the scroll position.
Gets the visible fraction (0.0 - 1.0) for horizontal scrolling.
Gets the visible fraction (0.0 - 1.0) for vertical scrolling.
Functions
Checks if content is scrollable horizontally.
Checks if content is scrollable vertically.
Gets the current scroll position.
Creates new Viewport widget props.
Options
:content- Content to display (render node):content_width- Width of content (for horizontal scrolling):content_height- Height of content (for vertical scrolling):width- Viewport width (default: 40):height- Viewport height (default: 20):scroll_x- Initial horizontal scroll position (default: 0):scroll_y- Initial vertical scroll position (default: 0):scroll_bars- Scroll bar display: :none, :vertical, :horizontal, :both (default: :both):on_scroll- Callback when scroll position changes:scroll_step- Lines to scroll per step (default: 1):page_step- Lines to scroll per page (default: viewport height)
Scrolls to make a position visible.
Updates the content.
Updates the content dimensions.
Sets the scroll position.
Gets the visible fraction (0.0 - 1.0) for horizontal scrolling.
Gets the visible fraction (0.0 - 1.0) for vertical scrolling.