Skip to Content
Onevra

Breadcrumbs

Shows a path whose ancestors can be chosen, collapsing the middle when space runs out.

Loading the live example…

breadcrumbs.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type folderPath struct {
	path   []string
	chosen int
}

func (f *folderPath) View(c *ui.Context) {
	ui.Column(c).Width(420).MaxWidthPercent(100).Gap(16).Children(func() {
		if components.Breadcrumbs(c, f.path, &f.chosen).Changed() {
			// Ancestors navigate: trim the path to the chosen folder.
			f.path = f.path[:f.chosen+1]
		}
		if len(f.path) < 5 && components.Button(c, "Reset path", components.ButtonOutline).Clicked() {
			f.path = []string{"Home", "Projects", "Onevra", "Website", "Docs"}
		}
	})
}
Source

Activating an ancestor writes its index and reports Changed(); the application navigates. The path fills its parent's width, and when it does not fit, the middle ancestors collapse into a menu. Narrow the window to see it.

API

func Breadcrumbs(c *ui.Context, items []string, chosen *int) *BreadcrumbsControl

Breadcrumbs displays a path with interactive ancestors and a non-interactive final item. Activation writes the ancestor index to chosen; applications own navigation and the path itself. A nil chosen binding is invalid. Keep the control to query Changed after applying Element layout methods.

The path fills its parent's width. When it does not fit, the ancestors after the first collapse, nearest last, into an ellipsis button whose menu lists them in order; the first and final items stay and truncate if still too wide.

pkg.go.dev

BreadcrumbsControl retains activation separately from Element styling.

Prop

Type

Methods
func (b *BreadcrumbsControl) Changed() bool

Changed reports activation of an ancestor, even if chosen already held its index.

pkg.go.dev
Edit this page on GitHub

On this page