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:
- Variables:
state (
ScrollState) – Current scroll state
Methods
__init__(content_size, viewport_size[, ...])Get the range of visible content indices.
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 the end (maximum scroll position).
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_to_top()[source]
Scroll to the beginning (position 0).
- Returns:
New scroll position (always 0)
- Return type:
- scroll_to_bottom()[source]
Scroll to the end (maximum scroll position).
- Returns:
New scroll position (max_scroll)
- Return type:
- 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:
Examples
>>> manager = ScrollManager(content_size=100, viewport_size=10) >>> manager.scroll_to(20) 20 >>> manager.get_visible_range() (20, 30)