Skip to Content
Onevra

Honeycomb

Items on a magnified honeycomb, as on a watch face, panned by dragging.

Loading the live example…

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

type launcherApp struct {
	id, name string
	icon     func() *ui.SVG
	color    ui.Color
}

var launcherApps = []launcherApp{
	{"documents", "Documents", lucide.FileText, ui.RGB(79, 124, 255)},
	{"photos", "Photos", lucide.Image, ui.RGB(236, 120, 82)},
	{"notes", "Notes", lucide.StickyNote, ui.RGB(226, 178, 60)},
	{"music", "Music", lucide.Music, ui.RGB(206, 96, 176)},
	{"files", "Files", lucide.Folder, ui.RGB(72, 168, 128)},
	{"mail", "Mail", lucide.Mail, ui.RGB(120, 176, 92)},
	{"camera", "Camera", lucide.Camera, ui.RGB(150, 118, 226)},
	{"cloud", "Cloud", lucide.Cloud, ui.RGB(122, 162, 214)},
	{"settings", "Settings", lucide.Settings, ui.RGB(110, 110, 122)},
	{"videos", "Videos", lucide.Video, ui.RGB(88, 128, 196)},
	{"archive", "Archive", lucide.Archive, ui.RGB(158, 138, 96)},
	{"inbox", "Inbox", lucide.MessageSquare, ui.RGB(66, 176, 176)},
}

type launcher struct {
	selected string
}

func (l *launcher) View(c *ui.Context) {
	items := make([]components.HoneycombItem, len(launcherApps))
	for i, a := range launcherApps {
		items[i] = components.HoneycombItem{
			ID: a.id, Label: a.name, Caption: a.name, Ring: a.color,
			Content: func(c *ui.Context, size float32) { launcherIcon(c, a, size) },
		}
	}
	// A folder shows the apps it holds as a group of images.
	var folder []components.HoneycombImage
	for _, a := range launcherApps[1:4] {
		folder = append(folder, components.HoneycombImage{Content: func(c *ui.Context, size float32) { launcherIcon(c, a, size) }})
	}
	items = append(items, components.HoneycombItem{ID: "media", Label: "Media", Caption: "Media", Images: folder})
	ui.Column(c).Fill().Children(func() {
		if id := components.Honeycomb(c, components.HoneycombOptions{
			Items:    items,
			Selected: l.selected,
		}); id != "" {
			l.selected = id
		}
	})
}

// launcherIcon fills a cell's circle, which the honeycomb does not clip.
func launcherIcon(c *ui.Context, a launcherApp, size float32) {
	ui.Box(c).Size(size, size).Radius(size/2).Background(a.color.Alpha(.16)).
		Border(1, a.color.Alpha(.45)).Center().Children(func() {
		components.Icon(c, a.icon).Size(size*.42, size*.42).TextColor(a.color)
	})
}
Source

Drag or scroll to pan; the honeycomb settles with the item nearest the middle centered and chosen. Items are magnified most in the middle and turn away toward the edges, as if on the surface of a ball. The keyboard reaches every item.

Items draw their own content at the given size, or Images overlapping as a group with a badge counting those beyond three. Caption names the middle item on a glass label, and Curvature, Gap and OffsetY tune the layout.

API

Honeycomb

func Honeycomb(c *ui.Context, options HoneycombOptions) string

Honeycomb draws the items as a honeycomb, as on a watch face, in a view that fills the width and grows into the height of its column. The honeycomb is magnified most in the middle of the view, shifted by OffsetY, so items and the space between them shrink smoothly the further out they are, and shrink further and fade out as they near the edge of the view. The honeycomb lies on the surface of a ball behind it, so each item turns away from the viewer the further out it is, and dragging it pans over that ball. The item nearest the middle wears a ring in its own color or the theme's accent, and its caption under it.

Dragging the items, or scrolling over them, pans the honeycomb, which then settles with the item nearest the middle centered and chosen; choosing an item, here or elsewhere, pans it over to center that item. The keyboard reaches every item and pans to the focused one. Honeycomb returns the ID of an item chosen by input in this frame, or "".

Applications own the items, their decoded images, labels, selected ID and any action a choice triggers. Items without a Content or Image builder draw nothing. Call Honeycomb within a bounded parent; the view takes its height from the space left to it, keeping at least two rows visible.

pkg.go.dev

HoneycombOptions

HoneycombOptions configures a Honeycomb.

Prop

Type

pkg.go.dev

HoneycombItem

HoneycombItem describes one round cell of a Honeycomb.

Prop

Type

pkg.go.dev

HoneycombImage

HoneycombImage is one round image of a HoneycombItem's Images.

Prop

Type

pkg.go.dev
Edit this page on GitHub

On this page