wijjit.layout.scroll.ScrollManager

class wijjit.layout.scroll.ScrollManager(content_size, viewport_size, initial_position=0)[source]

Manages scroll state and operations for a scrollable container.

This class provides methods for scrolling, handles bounds checking, and calculates visible content ranges. It maintains the scroll state and ensures all scroll operations are valid.

Parameters:
  • content_size (int) – Total content size (lines or columns)

  • viewport_size (int) – Viewport size (visible lines or columns)

  • initial_position (int, optional) – Initial scroll position (default: 0)

Variables:

state (ScrollState) – Current scroll state

__init__(content_size, viewport_size, initial_position=0)[source]
Parameters:
  • content_size (int)

  • viewport_size (int)

  • initial_position (int)

Return type:

None

Methods

__init__(content_size, viewport_size[, ...])

get_visible_range()

Get the range of visible content indices.

page_down()

Scroll down by one viewport.

page_up()

Scroll up by one viewport.

scroll_by(delta)

Scroll by a relative amount.

scroll_to(position)

Scroll to an absolute position.

scroll_to_bottom()

Scroll to the end (maximum scroll position).

scroll_to_top()

Scroll to the beginning (position 0).

update_content_size(size)

Update content size and adjust scroll position if needed.

update_viewport_size(size)

Update viewport size and adjust scroll position if needed.

scroll_by(delta)[source]

Scroll by a relative amount.

Parameters:

delta (int) – Amount to scroll (positive = down/right, negative = up/left)

Returns:

New scroll position after clamping

Return type:

int

scroll_to(position)[source]

Scroll to an absolute position.

Parameters:

position (int) – Target scroll position

Returns:

Actual scroll position after clamping

Return type:

int

scroll_to_top()[source]

Scroll to the beginning (position 0).

Returns:

New scroll position (always 0)

Return type:

int

scroll_to_bottom()[source]

Scroll to the end (maximum scroll position).

Returns:

New scroll position (max_scroll)

Return type:

int

page_up()[source]

Scroll up by one viewport.

Returns:

New scroll position

Return type:

int

page_down()[source]

Scroll down by one viewport.

Returns:

New scroll position

Return type:

int

update_content_size(size)[source]

Update content size and adjust scroll position if needed.

Parameters:

size (int) – New content size

Return type:

None

Notes

If the new content size results in a smaller max_scroll, the scroll position will be clamped to the new maximum.

update_viewport_size(size)[source]

Update viewport size and adjust scroll position if needed.

Parameters:

size (int) – New viewport size

Return type:

None

Notes

If the new viewport size results in a smaller max_scroll, the scroll position will be clamped to the new maximum.

get_visible_range()[source]

Get the range of visible content indices.

Returns:

(start_index, end_index) where end_index is exclusive. For example, (5, 10) means indices 5, 6, 7, 8, 9 are visible.

Return type:

tuple of int

Examples

>>> manager = ScrollManager(content_size=100, viewport_size=10)
>>> manager.scroll_to(20)
20
>>> manager.get_visible_range()
(20, 30)