Documentation
¶
Index ¶
- type Anchor
- type Axis
- type Scroll
- func (s *Scroll) Anchor(a Anchor) *Scroll
- func (s *Scroll) AtBottom() bool
- func (s *Scroll) Axis(a Axis) *Scroll
- func (s *Scroll) ContentHeight() int
- func (s *Scroll) ContentWidth() int
- func (s *Scroll) FitContent(on bool) *Scroll
- func (s *Scroll) Layout(gtx layout.Context) layout.Dimensions
- func (s *Scroll) MaxOffsetX() int
- func (s *Scroll) Offset() float32
- func (s *Scroll) OffsetDp() float32
- func (s *Scroll) OffsetX() float32
- func (s *Scroll) OnReachBottom(fn func()) *Scroll
- func (s *Scroll) OnScroll(fn func(offset, max float32)) *Scroll
- func (s *Scroll) Progress() float32
- func (s *Scroll) ScrollBy(dx, dy float32)
- func (s *Scroll) ScrollOffset() (x, y float32)
- func (s *Scroll) ScrollTo(v float32)
- func (s *Scroll) ScrollToBottom()
- func (s *Scroll) ScrollToDp(v float32)
- func (s *Scroll) ScrollToX(v float32)
- func (s *Scroll) Styles(st styles.Styles) *Scroll
- func (s *Scroll) ViewportHeight() int
- func (s *Scroll) ViewportWidth() int
- func (s *Scroll) Visible(top, height int) bool
- func (s *Scroll) VisibleDp(top, height float32) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Anchor ¶
type Anchor int
Anchor selects where a Scroll keeps its content when it grows.
const ( // AnchorTop keeps the offset when content is added (the default). AnchorTop Anchor = iota // AnchorBottom keeps a scroll that's at the bottom there as its // content grows - a chat following a reply as it streams in - and // stops following once the user scrolls up, until they scroll // back to the bottom. It starts at the bottom. AnchorBottom )
type Scroll ¶
type Scroll struct {
// Contextual gives it a context menu (Context).
elements.Contextual
// contains filtered or unexported fields
}
Scroll is a stateful vertical scroll container. It implements elements.Element, so it can be placed directly in the tree like any other element. Create it once with New and lay it out every frame; content is rebuilt every frame while visible and may be taller than the viewport.
The scroll offset reacts to the mouse wheel and touch drags, and the scrollbar thumb can be dragged with the mouse.
func New ¶
New returns a Scroll around content, rebuilt fresh every frame. The styles argument is optional: Background is the container fill and ScrollBar customizes the scrollbar's width, colors, corner radius and minimum thumb length.
func (*Scroll) Anchor ¶
Anchor sets where the content stays as it grows; see AnchorBottom. It returns s for chaining.
func (*Scroll) AtBottom ¶
AtBottom reports whether the scroll is at (or past) its maximum offset - also true when there's nothing to scroll at all (the content already fits the viewport), the same way a page with no scrollbar is trivially "at the bottom": there's nowhere else to go, so a load-more handler driven by AtBottom/OnReachBottom fires immediately, prompting an initial fetch when the first page of content doesn't even fill the viewport.
func (*Scroll) Axis ¶
Axis sets the directions the content scrolls in: Vertical (the default), Horizontal, or Vertical|Horizontal. Along a scrolling axis the content gets unlimited room; along the other it gets the viewport's size. It returns s for chaining.
func (*Scroll) ContentHeight ¶
ContentHeight returns the total height of the scrolled content, as measured on the last frame.
func (*Scroll) ContentWidth ¶
ContentWidth returns the total width of the scrolled content, as measured on the last frame. With Axis(Horizontal) (or both axes) the content may be wider than the viewport; otherwise it's laid out at the viewport's width.
func (*Scroll) FitContent ¶
FitContent makes the viewport only as tall (or, scrolling horizontally, as wide) as the content, up to the available space, instead of always filling it: a sheet with three rows stays three rows tall and scrolls once the content outgrows the screen. It returns s for chaining.
func (*Scroll) Layout ¶
func (s *Scroll) Layout(gtx layout.Context) layout.Dimensions
Layout lays out the scrollable content.
func (*Scroll) MaxOffsetX ¶
MaxOffsetX returns how far it can scroll sideways, in pixels: 0 when the content fits.
func (*Scroll) OffsetX ¶
OffsetX returns the horizontal offset in pixels, from the start edge: the left, or the right in a right-to-left locale, where a horizontal Scroll starts at its right end as in a browser.
func (*Scroll) OnReachBottom ¶
OnReachBottom sets the handler invoked once when the scroll reaches its maximum offset - edge-triggered: it fires again only after scrolling away from the bottom and back, not on every frame spent there. It returns s for chaining.
func (*Scroll) OnScroll ¶
OnScroll sets a handler called after the offset changes - by the user, ScrollTo or an anchor - with the vertical offset and its maximum in pixels (the horizontal ones for a Horizontal-only scroll). It returns s for chaining.
func (*Scroll) Progress ¶
Progress returns how far scrolled, from 0 (top) to 1 (bottom); 0 when there's nothing to scroll (the content fits the viewport).
func (*Scroll) ScrollBy ¶
ScrollBy moves the content by dx, dy pixels, as a wheel or drag would: positive dy scrolls down. The offsets are clamped to the content on the next layout. It's how automation (the MCP server's ui_scroll) scrolls.
func (*Scroll) ScrollOffset ¶
ScrollOffset returns the horizontal and vertical offsets in pixels.
func (*Scroll) ScrollToBottom ¶
func (s *Scroll) ScrollToBottom()
ScrollToBottom scrolls to the end of the content, and resumes following it with AnchorBottom.
func (*Scroll) ScrollToDp ¶
ScrollToDp sets the vertical offset in dp.
func (*Scroll) ScrollToX ¶
ScrollToX sets the horizontal offset in pixels, from the start edge (see OffsetX).
func (*Scroll) ViewportHeight ¶
ViewportHeight returns the height of the visible viewport, as measured on the last frame.
func (*Scroll) ViewportWidth ¶
ViewportWidth returns the width of the visible viewport, as measured on the last frame: for keeping a caret in view sideways, together with OffsetX and ScrollToX.
func (*Scroll) Visible ¶
Visible reports whether the vertical range [top, top+height) - in the same coordinate space as Content's own output, e.g. a running offset tracked while building a long list - is at least partially within the current viewport. Useful for lazy-loading or skipping expensive work for an item that isn't currently on screen.