Skip to main content

Scroll View

YauiScrollView scrolls a content element inside a viewport element by dragging, with the scroll wheel, and with scrollbars, like uGUI's ScrollRect.

The scroll view moves the content with its render transform (YauiElement.Translate). Scrolling never runs the layout again.

Setup​

The content keeps its own layout. A typical setup for vertical scrolling:

ScrollView YauiElement (ClipChildren), YauiScrollView
└─ Content YauiElement (Position Absolute, Inset Left 0 / Top 0, Width 100%)
├─ Item
├─ Item
└─ ...
  • The viewport clips its children (ClipChildren). The viewport is the scroll view's own element unless Viewport is set.
  • The content is an absolutely positioned child of the viewport, at the top-left. For vertical scrolling, its width is 100% of the viewport and its height is Auto, so that its children decide it. For horizontal scrolling, swap the width and the height.

Properties​

MemberDescription
Content, ViewportThe scrolled element, and the element that shows it
Horizontal, VerticalThe axes that scroll
MovementTypeElastic (pulls past the edges and springs back), Clamped (stops at the edges) or Unrestricted
ElasticityElastic: roughly the time in seconds to spring back
Inertia, DecelerationRateWhether the content keeps moving after a drag, and the fraction of the velocity left after a second
ScrollSensitivityCanvas units per step of the scroll wheel
HorizontalScrollbar, VerticalScrollbarScrollbars driven by the scroll view. The vertical one uses the direction TopToBottom.
OnValueChangedInvoked with the normalized position when it changes

Scrolling from scripts​

MemberDescription
ScrollPositionHow far the content is scrolled from its place, in canvas units (positive toward its end)
ScrollRangeHow far the content can scroll on each axis
NormalizedPositionThe scroll position as a fraction of the range (0 at the top-left)
VelocityThe current velocity
StopMovement()Stops the inertia
ScrollIntoView(element)Scrolls as little as needed to show a descendant of the content

Nested scroll views​

A scroll view passes drags on the axes it cannot scroll, and scroll wheel events when its content fits, to the scroll view above it. A vertical list inside a horizontal pager works without extra code.

The scroll view does not virtualize its items. See Performance.