ScrollState

@Stable
class ScrollState

A hoistable state holder for the scroll position of a ScrollPane.

x and y are two-way: assigning them scrolls the pane, and the user scrolling it - by wheel, scrollbar or keyboard - writes the new position back. The metrics the position is bounded by (extentWidth, extentHeight, viewWidth, viewHeight) and the largest useful position (maxX, maxY) follow the content and the pane's size, so state.y = state.maxY scrolls to the bottom of whatever is currently there.

Every value is snapshot-observable: reading one inside a composable (or a snapshotFlow collector) subscribes to later scrolling and resizing, so the reader recomposes as the pane moves.

canScrollForwardX, canScrollBackwardX, canScrollForwardY and canScrollBackwardY answer whether an axis has anywhere left to scroll, for a caller that offers a way to scroll further and wants it disabled at the end. A reader of one of them stands still until the answer itself changes.

revealRect scrolls to a region of the content instead of to a coordinate, for a caller that knows where something is but not where the pane has to stand to show it.

A position outside the content is not refused, exactly as the widget does not refuse one: the pane takes it, and its next layout pass corrects it and reports the corrected value back here. The position outlives the content it was reached in - new content is scrolled to where the state stands, so a pane that leaves the composition and returns comes back where the user left it. A state renders at most one pane; declaring it on a second one moves it to that pane, and it moves back to the first as soon as the second stops declaring it while the first still does.

See also

Properties

Link copied to clipboard

Whether any content is left before the visible part across the pane: false while x stands at 0.

Link copied to clipboard

Whether any content is left before the visible part down the pane: false while y stands at 0.

Link copied to clipboard

Whether any content is left beyond the visible part across the pane: false once x stands at maxX, and while the content is no wider than the viewport or no pane renders this state.

Link copied to clipboard

Whether any content is left beyond the visible part down the pane: false once y stands at maxY, and while the content is no taller than the viewport or no pane renders this state.

Link copied to clipboard

The height of the visible part of the content, in view coordinates; 0 while no pane renders this state.

Link copied to clipboard

The width of the visible part of the content, in view coordinates; 0 while no pane renders this state.

Link copied to clipboard
val maxX: Int

The largest x that shows content; 0 when the content is no wider than the viewport.

Link copied to clipboard
val maxY: Int

The largest y that shows content; 0 when the content is no taller than the viewport.

Link copied to clipboard

The full height of the scrolled content, in view coordinates; 0 while no pane renders this state.

Link copied to clipboard

The full width of the scrolled content, in view coordinates; 0 while no pane renders this state.

Link copied to clipboard
var x: Int

The view coordinate shown at the viewport's left edge.

Link copied to clipboard
var y: Int

The view coordinate shown at the viewport's top edge.

Functions

Link copied to clipboard

Brings the region rect names of the pane's content into view - in the content's own coordinates, where its top left corner is the origin, whatever the pane is currently scrolled to - and returns whether it was reached.