Skip to content

macoslite 实验性 ​

实验性

本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。

go
import "github.com/tangoui/tango/macoslite"

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

Package macoslite is a minimal macOS-native window host for small utility windows (settings, updaters, prompts). It talks to AppKit, CoreGraphics and CoreText directly through purego and does not load the Tango App, WebView, ui.Runner, layout, accessibility or GPU renderer, so an idle window costs far less memory than a full Tango surface.

Experimental: the API may change incompatibly between minor releases.

It is independent of uihost.Open and does not replace it. On platforms other than macOS, New returns ErrUnsupported. See docs/specs/macos-native-lite-design.md.

变量 ​

go
var (
	// ErrUnsupported is returned by New on platforms other than macOS.
	ErrUnsupported = errors.New("macoslite: unsupported platform")
	// ErrInvalidOptions wraps option validation failures.
	ErrInvalidOptions = errors.New("macoslite: invalid options")
	// ErrNilView is returned when New is given a nil View.
	ErrNilView = errors.New("macoslite: nil view")
)

类型 ​

App ​

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

App owns one native window. Create it with New and call Run on the main goroutine.

func New ​

go
func New(o Options, v View) (*App, error)

New validates the options and returns an App. It does not touch native APIs; the window is created by Run.

func (*App) Invalidate ​

go
func (a *App) Invalidate()

Invalidate schedules a redraw. Safe from any goroutine; calls made before the next frame coalesce into one.

func (*App) Run ​

go
func (a *App) Run() error

Run creates the window and runs the AppKit event loop until Stop is called or the window is closed. It must be called on the main goroutine.

func (*App) Stop ​

go
func (a *App) Stop()

Stop closes the window and makes Run return. Safe from any goroutine and safe to call more than once; View.Close runs once, on the main thread.

func (*App) TrimCaches ​

go
func (a *App) TrimCaches()

TrimCaches releases cached fonts; the current frame stays on screen. Safe from any goroutine: the fonts are released on the main thread.

Canvas ​

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

Canvas draws into the current frame's bitmap. Coordinates are in points with the origin at the top-left; the canvas scales them to pixels. A Canvas is valid only during the View.Draw call that received it.

func (*Canvas) Fill ​

go
func (c *Canvas) Fill(r Rect, col Color)

Fill paints r with col.

func (*Canvas) RoundRect ​

go
func (c *Canvas) RoundRect(r Rect, radius float64, col Color)

RoundRect paints r with corners of the given radius (points), antialiased.

func (*Canvas) Text ​

go
func (c *Canvas) Text(s string, origin Point, size float64, col Color)

Text draws s with its baseline-left at origin (points), in the system UI font at size points. CoreText picks fallback fonts (CJK, symbols) itself. Invalid UTF-8 is drawn with replacement characters.

Color ​

go
type Color struct{ R, G, B, A uint8 }

Color is a non-premultiplied 8-bit RGBA color.

Frame ​

go
type Frame struct {
	Width, Height, Scale float64
}

Frame describes the frame being drawn, in points; Scale is the backing scale factor (2 on Retina).

KeyEvent ​

go
type KeyEvent struct {
	Key  string
	Code uint16
	Down bool
}

KeyEvent is a key press or release. Key is "Escape", "Enter", "Tab", "Backspace" or the typed characters; Code is the hardware key code.

MouseEvent ​

go
type MouseEvent struct {
	Kind   MouseKind
	Pos    Point
	Button int
}

MouseEvent is a pointer event in view coordinates.

MouseKind ​

go
type MouseKind int

MouseKind classifies a MouseEvent.

go
const (
	MouseDown MouseKind = iota
	MouseUp
	MouseMove
)

Options ​

go
type Options struct {
	Name, Title   string
	Width, Height float64 // content size in points; both must be > 0
}

Options configures the single window of an App.

Point ​

go
type Point struct{ X, Y float64 }

Point is a position in points, origin top-left.

Rect ​

go
type Rect struct{ X, Y, W, H float64 }

Rect is an axis-aligned rectangle in points, origin top-left.

func (Rect) Contains ​

go
func (r Rect) Contains(p Point) bool

Contains reports whether p lies in r; the right and bottom edges are excluded.

View ​

go
type View interface {
	Draw(*Frame, *Canvas)
	Mouse(MouseEvent)
	Key(KeyEvent)
	Close()
}

View receives drawing and input callbacks on the main thread.

以 MIT 许可发布