Skip to content

flyout ​

go
import "github.com/tangoui/tango/sys/flyout"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package flyout shows a borderless panel under a tray icon — a popover in the macOS menu bar, a flyout above the Windows notification area — that hides itself when it loses focus.

t, _ := tray.New(a, tray.Options{Icon: png, Template: true, MenuOn: tray.MenuOnSecondary})
f, err := flyout.New(a, t, flyout.Options{Width: 320, Height: 420, URL: "/panel.html"})
// a left click on the icon now toggles the panel; f.Surface() is the page

The panel is an ordinary *tango.Surface (KindPanel, TitleBarNone, always on top, hidden until opened), so it can host a WebView page or, with Options.Surface, a surface the app created itself (a Go-drawn canvas surface, say). Open places it against the tray icon's bounds: below the icon when the icon is in the top half of its display (macOS menu bar, a top panel), above it when in the bottom half (Windows taskbar), beside it for vertical taskbars; always inside the display's work area. Where the platform does not report tray bounds (Linux AppIndicator) it goes to the top-right corner of the primary display's work area (bottom-right on Windows).

With a tray menu, set tray.Options.MenuOn = tray.MenuOnSecondary so left clicks reach the flyout and right clicks open the menu.

Methods are safe from any goroutine once the app runs.

变量 ​

go
var ErrClosed = errors.New("tango/flyout: the panel surface was closed")

ErrClosed is returned by Open after the panel's surface was closed.

函数 ​

func Place ​

go
func Place(anchor Rect, hasAnchor bool, work Rect, hasWork bool, w, h, gap int, bottomFallback bool) (x, y int)

Place computes the panel's top-left corner for a w x h panel against anchor (the tray icon) inside work (the work area of the anchor's display). Without an anchor the panel goes to the top-right corner of work, or the bottom-right when bottomFallback (Windows). Without a work area it is not clamped.

类型 ​

Flyout ​

go
type Flyout struct {
	// contains filtered or unexported fields
}

Flyout is a panel attached to a tray icon.

func New ​

go
func New(a *tango.App, t *tray.Tray, o Options) (*Flyout, error)

New creates the panel (hidden) and attaches it to t; t may be nil, in which case Open uses the fallback corner.

func (*Flyout) Close ​

go
func (f *Flyout) Close()

Close hides the panel.

func (*Flyout) IsOpen ​

go
func (f *Flyout) IsOpen() bool

IsOpen reports whether the panel is showing.

func (*Flyout) OnClose ​

go
func (f *Flyout) OnClose(fn func())

OnClose adds fn to run after the panel hid (Close, blur, Cmd+W).

func (*Flyout) OnOpen ​

go
func (f *Flyout) OnOpen(fn func())

OnOpen adds fn to run (on the main thread) after the panel opened.

func (*Flyout) Open ​

go
func (f *Flyout) Open() error

Open places the panel at the tray icon and shows and focuses it.

func (*Flyout) OpenAt ​

go
func (f *Flyout) OpenAt(anchor Rect, hasAnchor bool) error

OpenAt is Open against anchor instead of the tray icon's bounds (for example a point the app knows the user clicked: a 1x1 rect). With hasAnchor false it uses the fallback corner.

func (*Flyout) Surface ​

go
func (f *Flyout) Surface() *tango.Surface

Surface is the panel's surface.

func (*Flyout) Toggle ​

go
func (f *Flyout) Toggle()

Toggle opens the panel if it is hidden and closes it otherwise. A toggle right after the panel hid itself on blur — the click on the tray icon that caused the blur — leaves it closed.

Options ​

go
type Options struct {
	Width, Height int    // panel size; default 320x400
	URL           string // page of the panel (relative to the asset origin); ignored with Surface
	Debug         bool   // allow the inspector
	Transparent   bool   // transparent window and page (round the corners in CSS)
	Material      tango.Material
	// Gap is the distance between the icon and the panel; default 6 px.
	Gap int
	// KeepOnBlur keeps the panel open when it loses focus.
	KeepOnBlur bool
	// NoToggle stops a primary click on the icon from toggling the panel;
	// call Open/Close/Toggle yourself.
	NoToggle bool
	// Surface, if set, is used as the panel instead of creating one. It
	// should be frameless and hidden; Close hides it, it is never closed.
	Surface *tango.Surface
	// contains filtered or unexported fields
}

Options configures a flyout.

Rect ​

go
type Rect = tango.Rect

Rect is a screen rectangle in logical pixels.

以 MIT 许可发布