Popover
A non-modal panel anchored to a control, for options and short forms.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type shareMenu struct {
open, comments, download bool
}
func (s *shareMenu) View(c *ui.Context) {
t := c.Theme()
ui.Column(c).Fill().Padding(t.Space(6)).AlignItems(ui.Center).Children(func() {
anchor := components.Button(c, "Share", components.ButtonOutline)
if anchor.Clicked() {
s.open = !s.open
}
components.Popover(c, anchor, &s.open, func(panel ui.Element) {
panel.Label("Sharing").Width(260)
components.Text(c, "Anyone with the link").Bold()
components.Text(c, "People you share with can view the board.").TextColor(t.TextMuted)
components.Checkbox(c, &s.comments, "Allow comments")
components.Checkbox(c, &s.download, "Allow downloads")
if components.Button(c, "Done", components.ButtonPrimary).Clicked() {
s.open = false
}
})
})
}Build the anchor first, then call components.Popover with it every frame. The panel opens below the anchor and flips above it when there is no room. Escape and a press outside close it; the press continues to whatever was under the pointer.
For a hint that is never interactive, use a tooltip.
API
Popover
func Popover(c *ui.Context, anchor ui.Element, open *bool, build func(panel ui.Element)) ui.ElementPopover builds a non-modal panel anchored below anchor, flipping above it when needed. Applications own open and trigger activation and call Popover every frame after building the anchor. The returned Element is absent while closed. MyGo owns positioning, focus order and Escape/outside-press dismissal; outside presses continue to the underlying control. Pressing the anchor does not dismiss the panel automatically.
build styles the panel and creates its children. It may override placement with AttachTo or supply scrolling for long content. Keep anchor and panel handles within the current build pass and use keyed parents for independent popovers. Label the panel in build when an accessible name is needed.
pkg.go.dev