surface

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package surface connects the content of a window that MyGo draws itself (package ui) to the window (package mygo), without either importing the other's internals.

Index

Constants

This section is empty.

Variables

View Source
var Automate func(conn *Conn, content Automated)

Automate is set by plugins/automation, in an app that links it and whose MYGO_AUTOMATION asks for it, before any window opens. Package ui then calls it on the main thread with the connection and the content of each window of native UI as the content attaches. Apps that don't link the plugin leave it nil and link none of Automated's methods, which only the plugin calls.

Functions

This section is empty.

Types

type Automated

type Automated interface {
	// AutomationTree returns the elements of the last frame as assistive
	// technology reads them, in the window's DIPs, and the keys the app
	// gave elements (ui's Key), by element ID.
	AutomationTree() (tree *platform.AccessTree, keys map[uint64]any)
	// FramePending reports whether the content asked for a frame that has
	// not come yet, as it does after input and while something animates.
	FramePending() bool
}

Automated is what the content of a window tells plugins/automation, which drives apps from another process. Package ui implements it. Its methods run on the main thread.

type Conn

type Conn struct {
	Surface platform.Surface
	// Window is the *mygo.Window.
	Window any
	// Clipboard is the system clipboard.
	Clipboard platform.Clipboard
	// StartDrag moves the window with the pointer, for drag regions;
	// TitleBarDoubleClicked does what a double click on a title bar does.
	StartDrag             func()
	TitleBarDoubleClicked func()
	// Escape is called with an Escape that no element or shortcut of the
	// content handled, which closes a flyout.
	Escape func()
	// StartDataDrag connects a UI source to the core's process-local
	// registry. local never leaves the process.
	StartDataDrag  func(transfer.Data, any, transfer.DragOptions, float64, float64) error
	CancelDataDrag func()
	// IsDark reports the system's dark appearance, and Preferences the
	// settings of the desktop that controls follow, which ThemeChanged
	// tells changes of as well.
	IsDark      func() bool
	Preferences func() platform.Preferences
	// Locale returns the language the app shows (App.Locale), and Region
	// the user's regional formats, which LocaleChanged tells changes of.
	// They cost nothing: the content may read them every frame.
	Locale func() string
	Region func() i18n.Region
	// RightToLeft reports whether the content is laid out right to left,
	// as the app's language reads (i18n.Direction of App.Locale), unless
	// the window says otherwise; nil is left to right. The content reads
	// it as it builds each frame: call Changed after it changes.
	RightToLeft func() bool
	// UIFont returns the family of the desktop's interface font where the
	// system's text stack does not know it (Linux), else "".
	UIFont func() string
	// FontRendering returns how the desktop's settings say to rasterize
	// text where the system's text stack does not know them (Linux).
	FontRendering func() platform.FontRendering
	// TitleBar returns the room the window controls take in a window with
	// a hidden title bar, zero in other windows.
	TitleBar func() platform.TitleBar
	// Active reports whether the window is drawn as active, as the window
	// the user's input goes to (see ui.Context.WindowActive), which
	// ActiveChanged tells changes of; nil is active. It costs nothing.
	Active func() bool
	// OpenURL opens a link in the default browser, and gives done, unless
	// nil, what came of it on the main thread.
	OpenURL func(url string, done func(error))
	// DevTools tells that the window's developer tools are on
	// (PageOptions.DevTools): the content then opens its inspector.
	DevTools bool
	// Invalidate asks for a frame; it is safe from any goroutine.
	Invalidate func()
	// Changed asks for a frame built anew after the app changed the state
	// the content shows (Window.Update, Window.Invalidate); the content
	// sets it, else the window asks the surface for a frame.
	Changed func()
	// Post runs fn on the main thread soon, unless the window has closed;
	// it is safe from any goroutine.
	Post func(fn func())
	// Ready tells that the content presented its first frame: the window
	// is ready to show (Window.OnReadyToShow).
	Ready func()
	// PopupMenu shows m as a context menu at (x, y) in the surface, in
	// DIPs, once the event being handled returns. chosen receives the ID of
	// the item chosen, if one is.
	PopupMenu func(m *platform.Menu, x, y float64, chosen func(id int))
	// PlaceWebViews shows the window's web views where the content's last
	// frame shows them (Surface.PlaceWebViews).
	PlaceWebViews func(views []platform.WebViewPlacement)
	// ContentSize, set by a window that takes its content's size
	// (mygo.FlyoutOptions.FitContent), nil in others, hears the size
	// the content takes, in DIPs, as a frame laid out at the window's
	// size measures it and when it changed: its max-content width within
	// the bounds FitWidth returns (0 for none), and its height at that
	// width. It is called while the frame builds: the window resizes
	// after it, and the frame that follows lays the content out at the
	// size it took.
	ContentSize func(width, height float64)
	FitWidth    func() (min, max float64)
	// Fit, set by the content where ContentSize is, builds and lays out
	// at once the frame the content waits to draw, if one waits, as in a
	// hidden window, which tells ContentSize the size it takes if that
	// changed, and reports whether it did build one. The window calls
	// it before it shows, to show at that size.
	Fit func() bool

	// Event receives the surface's events, and Focus and Blur of the
	// window. It reports whether the content takes dragged files, as
	// WindowHandler.SurfaceEvent does.
	Event func(ev platform.SurfaceEvent) bool
	// ThemeChanged is called when the system appearance changes, and
	// TitleBarChanged when TitleBar does.
	ThemeChanged    func()
	TitleBarChanged func()
	// ActiveChanged is called when Active changed.
	ActiveChanged func()
	// LocaleChanged is called when Locale or Region changed, for the
	// content to build its frame anew.
	LocaleChanged func()
	// Capture renders the content as it is now into premultiplied RGBA.
	Capture func() (width, height int, rgba []byte)
	// ToggleDevTools opens or closes the content's inspector, for the
	// Toggle Developer Tools menu item, when DevTools is set.
	ToggleDevTools func()
	// Detach is called once the window is closed.
	Detach func()
}

Conn is a window's side of the connection. Package mygo fills it before calling Content.AttachContent; the content sets the hooks it handles. Everything runs on the main thread, except Invalidate and Post.

type Content

type Content interface {
	AttachContent(conn *Conn)
}

Content is implemented by package ui.

type WebView

type WebView interface {
	// SurfaceWebView returns the web view's native side when it is of the
	// window of conn and not destroyed, else nil. Main thread only.
	SurfaceWebView(conn *Conn) platform.WebView
}

WebView is a web view a window made for its content to show (*mygo.WebView, of Window.NewWebView), which package ui places.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL