ScrollEdgeBar
A bar of controls floating over the edge of scrolling content, on glass, a soft edge or a blur.
Loading the live example…
import (
"fmt"
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/icons/lucide"
)
type photoFeed struct {
style int
}
var feedStyles = []struct {
name string
style components.ScrollEdgeStyle
}{
{"Glass", components.ScrollEdgeGlass},
{"Soft", components.ScrollEdgeSoft},
{"Hard", components.ScrollEdgeHard},
{"Blur", components.ScrollEdgeBlur},
}
var feedColors = []ui.Color{
ui.RGB(236, 120, 82), ui.RGB(79, 124, 255), ui.RGB(72, 168, 128),
ui.RGB(226, 178, 60), ui.RGB(206, 96, 176), ui.RGB(66, 176, 176),
}
func (f *photoFeed) View(c *ui.Context) {
options := components.ScrollEdgeBarOptions{Style: feedStyles[f.style].style}
// Over glass, buttons stay plain; the other styles leave the bar
// transparent, so the buttons bring their own face.
face := components.IconButtonToolbar
if options.Style == components.ScrollEdgeGlass {
face = components.IconButtonPlain
}
inset := components.ScrollEdgeBarExtent(c, options)
ui.Box(c).Fill().Clip().Children(func() {
components.ScrollView(c, components.ScrollViewOptions{}).Fill().
Padding(inset+8, 16, 16).ScrollbarInsets(inset, 0, 0).Gap(10).Children(func() {
for i := range 16 {
hue := feedColors[i%len(feedColors)]
ui.Row(c).Key(i).Gap(12).AlignItems(ui.Center).Children(func() {
ui.Box(c).Size(64, 44).Radius(8).Shrink(0).
LinearGradient(ui.LinearGradient{From: hue, To: hue.Alpha(.4), Angle: 135})
components.Text(c, fmt.Sprintf("Photo %d", i+1))
})
}
})
components.ScrollEdgeBar(c, options, func() {
components.IconButton(c, lucide.ChevronLeft(), "Back", face)
ui.Row(c).Grow(1).Justify(ui.Center).Children(func() {
names := make([]string, len(feedStyles))
for i, s := range feedStyles {
names[i] = s.name
}
components.Tabs(c, &f.style, components.TabsSegmented, names...)
})
components.IconButton(c, lucide.Share(), "Share", face)
}).Label("Toolbar")
})
}Build the bar after the content, inside a bounded container that clips: the bar samples what is painted beneath it. Pad the content by ScrollEdgeBarExtent so its first rows and the scroll bar start clear of the bar. Switch the styles above while scrolling to compare them.
ScrollEdgeGlass sets the whole bar on Liquid Glass. The other styles leave the bar transparent, so its controls bring their own faces, such as IconButtonToolbar. components.ScrollEdge is the effect alone, for hosts that place their own controls.
API
ScrollEdgeBar
func ScrollEdgeBar(c *ui.Context, options ScrollEdgeBarOptions, content func()) ui.ElementScrollEdgeBar floats a bar of controls over the top or bottom edge of scrolling content, such as a title bar, toolbar or bottom bar, and separates it from the content in the chosen style. Build it after the content, as a child of a bounded, clipping container that the content fills: materials sample what was painted beneath them, and the bar and its effect position themselves absolutely within that container.
ui.Box(c).Fill().Clip().Children(func() {
inset := components.ScrollEdgeBarExtent(c, options)
components.ScrollView(c, components.ScrollViewOptions{}).Fill().
Padding(inset+12, 16, 16).ScrollbarInsets(inset, 0, 0).Children(content)
components.ScrollEdgeBar(c, options, toolbar).Label("Toolbar")
})The returned element is the bar, a centered row that content builds the children of; the application owns them, their actions and the bar's accessible label. In styles other than ScrollEdgeGlass, the bar is transparent, so the controls should carry their own surfaces, such as interactive glass. The effect layer never takes input, so content under it beside the bar stays reachable.
pkg.go.devScrollEdgeBarOptions
ScrollEdgeStyle
type ScrollEdgeStyle intScrollEdgeStyle selects what separates a ScrollEdgeBar from the content scrolling under it.
const (
// ScrollEdgeGlass sets the whole bar on one capsule of Liquid Glass and
// leaves the content beside it untouched. This is the default.
ScrollEdgeGlass ScrollEdgeStyle = iota
// ScrollEdgeSoft fades the content into the background toward the edge,
// without a blur, as macOS's soft scroll edge effect.
ScrollEdgeSoft
// ScrollEdgeHard frosts the content evenly under the bar and draws a
// hairline where it ends, as macOS's hard scroll edge effect.
ScrollEdgeHard
// ScrollEdgeBlur blurs the content progressively, the more the nearer
// the edge.
ScrollEdgeBlur
)ScrollEdgeBarExtent
func ScrollEdgeBarExtent(c *ui.Context, options ScrollEdgeBarOptions) float32ScrollEdgeBarExtent returns how far from its edge a ScrollEdgeBar with options reaches, in DIPs: the scroll content's padding on that edge, plus any spacing, and its ScrollbarInsets keep content and scroll bar clear of the bar.
pkg.go.devScrollEdge
func ScrollEdge(c *ui.Context, options ScrollEdgeOptions) ui.ElementScrollEdge is ScrollEdgeBar's effect alone, for hosts that float their own controls over an edge of scrolling content, such as a composer. Build it after the content in the same bounded, clipping container. It never takes input; ScrollEdgeGlass has no edge of its own, so it draws nothing.
pkg.go.dev