TermUI.Widgets.ScrollBar (TermUI v0.2.0)

View Source

Standalone scroll bar widget.

ScrollBar provides a visual indicator and interactive control for scrolling. Can be used independently or integrated with other scrollable widgets.

Usage

ScrollBar.new(
  orientation: :vertical,
  total: 100,
  visible: 20,
  position: 0,
  length: 20,
  on_scroll: fn pos -> handle_scroll(pos) end
)

Features

  • Vertical and horizontal orientations
  • Proportional thumb size based on visible/total ratio
  • Track click for page scrolling
  • Drag scrolling for smooth navigation
  • Customizable appearance

Mouse Interaction

  • Click on thumb: Start dragging
  • Click on track: Page scroll toward click
  • Drag thumb: Smooth scrolling

Summary

Functions

Returns true if scrolling is possible (content exceeds visible).

Gets the scroll fraction (0.0 - 1.0).

Gets the current scroll position.

Creates a simple horizontal scroll bar.

Creates new ScrollBar widget props.

Updates the content dimensions.

Sets scroll by fraction (0.0 - 1.0).

Sets the scroll position.

Creates a simple vertical scroll bar.

Returns the visible fraction (thumb size ratio).

Functions

can_scroll?(state)

@spec can_scroll?(map()) :: boolean()

Returns true if scrolling is possible (content exceeds visible).

get_fraction(state)

@spec get_fraction(map()) :: float()

Gets the scroll fraction (0.0 - 1.0).

get_position(state)

@spec get_position(map()) :: integer()

Gets the current scroll position.

horizontal(opts)

@spec horizontal(keyword()) :: map()

Creates a simple horizontal scroll bar.

new(opts)

@spec new(keyword()) :: map()

Creates new ScrollBar widget props.

Options

  • :orientation - :vertical or :horizontal (default: :vertical)
  • :total - Total content size (default: 100)
  • :visible - Visible content size (default: 20)
  • :position - Current scroll position (default: 0)
  • :length - Bar length in characters (default: 20)
  • :on_scroll - Callback when position changes
  • :track_char - Character for track (default: "░")
  • :thumb_char - Character for thumb (default: "█")
  • :min_thumb_size - Minimum thumb size (default: 1)

set_dimensions(state, total, visible)

@spec set_dimensions(map(), integer(), integer()) :: map()

Updates the content dimensions.

set_fraction(state, fraction)

@spec set_fraction(map(), float()) :: map()

Sets scroll by fraction (0.0 - 1.0).

set_position(state, position)

@spec set_position(map(), integer()) :: map()

Sets the scroll position.

vertical(opts)

@spec vertical(keyword()) :: map()

Creates a simple vertical scroll bar.

visible_fraction(state)

@spec visible_fraction(map()) :: float()

Returns the visible fraction (thumb size ratio).