Go Reference

A scroll progress indicator widget for gio.

example screenshot


~whereswaldon developed a view-only version of this for sprig, and ~jackmordaunt contributed support for clicking within the scroll tray area and for dragging the indicator to move it. We agreed that the feature was generally useful and have pulled it out of the sprig repository so that other gio users can benefit.


This repository does not have a stable API. Pin yourself to a particular version with go modules.



    Package scroll provides a scrollbar implementation for gio.



    View Source
    const (
    	Vertical   = 0
    	Horizontal = 1


    This section is empty.


    This section is empty.


    type Axis

    type Axis int

      Axis specifies the scroll bar orientation. Default to `Vertical`.

      func (Axis) Layout

      func (axis Axis) Layout(gtx C, widget layout.Widget) D

      func (Axis) ToGesture

      func (axis Axis) ToGesture() (g gesture.Axis)

      type Bar

      type Bar struct {
      	// Color of the scroll indicator.
      	Color color.NRGBA
      	// Progress tells the bar where to render the indicator as a fraction [0, 1].
      	Progress float32
      	// Scale tells the bar what fraction of the available axis space it should
      	// occupy as a fraction between [0, 1].
      	Scale float32
      	// Axis along which the bar is oriented.
      	Axis Axis
      	// Axis independent size.
      	Thickness unit.Value
      	// MinLength is the minimum length of the scroll indicator. Regardless of
      	// the scale of the bar, it will not be displayed shorter than this. If
      	// the scale parameter isn't provided, the indicator will always have
      	// this length.
      	MinLength unit.Value

        Bar represents a scrolling indicator for a layout.List

        func DefaultBar

        func DefaultBar(state *Scrollable, progress, scale float32) Bar

          DefaultBar returns a bar with a translucent gray background. The progress parameter tells the bar how far through its range of motion to draw itself. The scale parameter tells the bar what fraction of the scrollable space is visible. Scale may be left as zero to use a minimum-length scroll indicator that does not respond to changes in the length of the scrollable region.

          func (Bar) Layout

          func (sb Bar) Layout(gtx C) D

            Layout renders the bar into the provided context.

            type C

            type C = layout.Context

            type D

            type D = layout.Dimensions

            type Scrollable

            type Scrollable struct {
            	// contains filtered or unexported fields

              Scrollable holds state of a scrolling widget. The Scrolled() method is used to tell both whether a scroll operation occurred during the last frame as well as the progress through the scrollable region at the end of the scroll operation.

              func (Scrollable) Scrolled

              func (sb Scrollable) Scrolled() (didScroll bool, progress float32)

                Scrolled returns true if the scroll position changed within the last frame.

                func (*Scrollable) Update

                func (sb *Scrollable) Update(gtx C, axis Axis)

                  Update the internal state of the bar.

                  Source Files