Widget catalog

Data

Widgets that show and edit many rows. Each builds only the rows in view.

collection.List

A vertical list of any length that builds only the rows near the view. Rows may differ in height.

Package github.com/bankai-tensei/gowaku/widgets/collection

collection.Listcollection.List
basic.SizedBox{Width: 320, Height: 180, Child: collection.List{
	ItemCount: 10000, ItemExtent: 36,
	ItemBuilder: func(i int) core.Widget {
		return basic.Padding{Insets: geom.Symmetric(theme.Space12, theme.Space8), Child: basic.Text{
			Content: "Row " + strconv.Itoa(i+1) + " of 10,000",
		}}
	},
}}

collection.GridView

A grid of tiles of any number that builds only the rows near the view. The width decides the columns, and a TableController holds the selection and the focus, which stay on the same items when they move given an ItemKey. The arrows move between tiles and Enter opens one.

Package github.com/bankai-tensei/gowaku/widgets/collection

collection.GridViewcollection.GridView
var photos collection.TableController
photos.SetSelection(collection.RowRange{Start: 1, End: 3})
return basic.SizedBox{Width: 460, Height: 280, Child: collection.GridView{
	ItemCount: 10000, MinColumnWidth: 96, AspectRatio: 4.0 / 3, ExtraHeight: 20,
	Spacing: theme.Space8, RunSpacing: theme.Space8, Padding: geom.All(theme.Space8),
	Label: "Photos", Controller: &photos,
	LabelOf: func(i int) string { return "Photo " + strconv.Itoa(i+1) },
	ItemBuilder: func(i int) core.Widget {
		tone := theme.TonalPalette{Hue: float64(i*47%360) + 0.5, Chroma: 36}.Tone(66)
		return basic.Column{Cross: layout.CrossStretch, Spacing: theme.Space4, Children: []core.Widget{
			basic.Expanded{Child: basic.Container{Color: tone, Radius: th.Radius.Control}},
			basic.Text{Content: "Photo " + strconv.Itoa(i+1), Style: small},
		}}
	},
}}

collection.ReorderableList

A List whose items move by drag or with Ctrl+Shift and an arrow. It does not own the items: OnReorder asks for the move. A screen reader hears the new place.

Package github.com/bankai-tensei/gowaku/widgets/collection

collection.ReorderableListcollection.ReorderableList
basic.SizedBox{Width: 300, Height: 220, Child: collection.ReorderableList{
	ItemCount: len(todos), ItemExtent: 44, Label: "To do",
	LabelOf: func(i int) string { return todos[i] },
	// Move the item in your data, then build again.
	OnReorder: func(_, _ int) {},
	ItemBuilder: func(i int) core.Widget {
		return basic.Padding{Insets: geom.Symmetric(theme.Space12, 0), Child: basic.Row{Cross: layout.CrossCenter, Children: []core.Widget{
			basic.Expanded{Child: basic.Text{Content: todos[i]}},
			basic.Text{Content: "≡"},
		}}}
	},
}}

collection.Table

A table with sorting, filters, range selection, cell editing and frozen columns. Cells show text, badges, dots, bars or check boxes. With RowKey the selection stays on the same rows when they are sorted or deleted. The header of the sorted column tells a screen reader its order. Rows that live elsewhere, as the lines of a file, come through RowCount and Row without a slice of them.

Package github.com/bankai-tensei/gowaku/widgets/collection · Also collection.TableColumn, collection.TableController, collection.TableSort, collection.TableFilter, collection.TableEdit, collection.TableEditor, collection.CellKind, collection.CellTone, collection.RowRange, collection.SortOrder, collection.TableSelectMode

collection.Tablecollection.Table
rows := []task{
	{"Design review", "Aiko", "Done", 1},
	{"Release notes", "Ben", "In progress", 0.6},
	{"Fix the build", "Chiara", "Blocked", 0.2},
	{"Translate docs", "Daichi", "In progress", 0.4},
	{"Plan the sprint", "Aiko", "Done", 1},
}
tone := func(t task) collection.CellTone {
	switch t.status {
	case "Done":
		return collection.CellToneSuccess
	case "Blocked":
		return collection.CellToneDanger
	}
	return collection.CellToneAccent
}
return basic.SizedBox{Width: 520, Height: 220, Child: collection.Table[task]{
	Label: "Tasks", Rows: rows,
	Sort: collection.TableSort{Column: 0, Order: collection.SortAscending}, OnSort: func(collection.TableSort) {},
	Columns: []collection.TableColumn[task]{
		{Title: "Task", Width: 160, Text: func(t task) string { return t.name }, Sortable: true},
		{Title: "Owner", Width: 100, Text: func(t task) string { return t.owner }, Sortable: true},
		{Title: "Status", Width: 120, Text: func(t task) string { return t.status }, Kind: collection.CellBadge, Tone: tone},
		{Title: "Done", Width: 120, Kind: collection.CellProgress, Value: func(t task) float32 { return t.done }},
	},
}}

collection.Tree

A tree of nodes that open and close, with multiple selection, lazy loading, renaming and moves by drag.

Package github.com/bankai-tensei/gowaku/widgets/collection · Also collection.TreeController, collection.TreeMove, collection.TreeDrop

collection.Treecollection.Tree
isFolder := func(k string) bool { return len(folders[k]) > 0 || k == "Documents" }
return basic.SizedBox{Width: 280, Height: 260, Child: collection.Tree[string]{
	Label: "Files", Roots: folders[""], Controller: &ctrl,
	ChildrenOf:  func(k string) []string { return folders[k] },
	HasChildren: isFolder,
	IconOf: func(k string) core.Widget {
		if isFolder(k) {
			return basic.Icon{Path: icons.Folder(), Size: 16, Color: geom.Hex(0x2f5fd0)}
		}
		return basic.Icon{Path: icons.Document(), Size: 16, Color: geom.Hex(0x8a8a8e)}
	},
}}

collection.PropertyGrid

An inspector that edits properties in two columns of names and values, in categories that fold.

Package github.com/bankai-tensei/gowaku/widgets/collection · Also collection.Property, collection.PropertyCategory, collection.PropertyEditor, collection.PropertyText, collection.PropertyBool, collection.PropertyChoice, collection.PropertyInt, collection.PropertyNumber, collection.PropertyColor, collection.PropertyCustom

collection.PropertyGridcollection.PropertyGrid
type fit int
return basic.SizedBox{Width: 340, Child: collection.PropertyGrid{Label: "Inspector", Categories: []collection.PropertyCategory{
	{Name: "General", Properties: []collection.Property{
		{Name: "Name", Description: "The name of the layer.", Editor: collection.PropertyText{Value: "Header", OnChange: func(string) {}}},
		{Name: "Visible", Editor: collection.PropertyBool{Value: true, OnChange: func(bool) {}}},
		{Name: "Fit", Editor: collection.PropertyChoice[fit]{Value: 1, OnChange: func(fit) {}, Options: []field.DropdownOption[fit]{
			{Value: 0, Label: "Fill"}, {Value: 1, Label: "Contain"},
		}}},
	}},
	{Name: "Layout", Properties: []collection.Property{
		{Name: "Width", Editor: collection.PropertyInt{Value: 320, Max: 4096, OnChange: func(int) {}}},
		{Name: "Opacity", Editor: collection.PropertyNumber{Value: 0.85, Max: 1, OnChange: func(float64) {}}},
		{Name: "Tint", Editor: collection.PropertyColor{Value: geom.Hex(0x2f5fd0), OnPress: func() {}}},
	}},
	{Name: "Advanced", Collapsed: true, Properties: []collection.Property{
		{Name: "Cache", Editor: collection.PropertyBool{OnChange: func(bool) {}}},
	}},
}}}

collection.Group

A card of rows, the stuff of settings pages and forms. The lines between rows stop short of the left edge.

Package github.com/bankai-tensei/gowaku/widgets/collection · Also collection.GroupRow

collection.Groupcollection.Group
basic.SizedBox{Width: 420, Child: collection.Group{Title: "Playback", Children: []core.Widget{
	collection.GroupRow{Label: "Shuffle", Child: control.Switch{Value: true, OnChange: func(bool) {}}},
	collection.GroupRow{Label: "Repeat", Child: control.SegmentedControl{
		Options: []string{"Off", "All", "One"}, Selected: 1, OnChange: func(int) {},
	}},
	collection.GroupRow{Label: "Crossfade", Detail: "Seconds between songs", Child: control.NumberStepper{
		Value: 4, Max: 12, OnChange: func(int) {},
	}},
}}}