FloatingButtonGroup
A toolbar of soft buttons in a tray, with one highlight that springs between them.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
"github.com/oneo-me/onevra/source/icons/lucide"
)
type boardToolbar struct {
edits, undone int
presenting bool
}
func (b *boardToolbar) View(c *ui.Context) {
present := "Present"
if b.presenting {
present = "Stop"
}
items := []components.FloatingButtonGroupItem{
{ID: "undo", Label: "Undo", Icon: lucide.Undo2, IconOnly: true, Shortcut: "⌘Z", Disabled: b.edits == 0},
{ID: "redo", Label: "Redo", Icon: lucide.Redo2, IconOnly: true, Shortcut: "⇧⌘Z", Disabled: b.undone == 0},
{Separator: true},
{ID: "comment", Label: "Comment", Icon: lucide.MessageCircle},
{Separator: true},
{ID: "present", Label: present, Icon: lucide.Play, Toggle: true, On: b.presenting,
ReserveLabels: []string{"Present", "Stop"}},
}
group := components.FloatingButtonGroup(c, "Board actions",
components.FloatingButtonGroupRaised, ui.Horizontal, items)
switch group.Clicked() {
case "comment":
b.edits, b.undone = b.edits+1, 0
case "undo":
b.edits, b.undone = b.edits-1, b.undone+1
case "redo":
b.edits, b.undone = b.edits+1, b.undone-1
case "present":
b.presenting = !b.presenting
}
}Use a floating button group for actions over content, such as a canvas or a text selection. Items are buttons or separators; Clicked() returns the ID of the activated button. The tray is one Tab stop, and the arrow keys move between its buttons.
FloatingButtonGroupMuted sits quietly on a page; FloatingButtonGroupRaised floats with a shadow. Pass ui.Vertical for a column of tools along a canvas edge.
API
FloatingButtonGroup
func FloatingButtonGroup(c *ui.Context, label string, variant FloatingButtonGroupVariant, orientation ui.Orientation, items []FloatingButtonGroupItem) *FloatingButtonGroupControlFloatingButtonGroup creates a toolbar of separate soft buttons in a quiet tray, laid out along orientation, ui.Horizontal or ui.Vertical; label names it for assistive technology. Use it for actions; for a choice that stays selected use Tabs or a toggle.
One shared highlight marks the button under the pointer, or with keyboard focus, and springs between buttons in position and size. It stays put as the pointer crosses a gap or separator and fades as it leaves the tray. Appearing, it grows in place; a press darkens it and settles it slightly smaller, while the buttons themselves never move. A changed label or icon crossfades in place. Reduced Motion moves the highlight at once.
The tray is one Tab stop; the arrows of its orientation move among the enabled buttons, wrapping at the ends, Home and End go to the ends, and Enter or Space activates. Icon-only buttons and buttons with a Shortcut show a tooltip, above a row and beside a column. A column's buttons share the width of its widest one. Applications own the labels, the state of toggles and the actions; ask Clicked for the activated button.
pkg.go.devFloatingButtonGroupItem
FloatingButtonGroupVariant
type FloatingButtonGroupVariant intFloatingButtonGroupVariant selects the tray of a FloatingButtonGroup.
const (
// FloatingButtonGroupMuted sits quietly on a page or panel, on a
// translucent tint of the text color. This is the default.
FloatingButtonGroupMuted FloatingButtonGroupVariant = iota
// FloatingButtonGroupRaised lifts the tray on the raised surface with a
// hairline edge and a floating shadow, for toolbars over content such as
// a canvas or a text selection.
FloatingButtonGroupRaised
)FloatingButtonGroupControl
FloatingButtonGroupControl is the tray of a FloatingButtonGroup.
Prop
Type
Methods
func (g *FloatingButtonGroupControl) Clicked() stringClicked returns the ID of the button activated in this frame, or "".