Documentation
¶
Overview ¶
Package gowaku is a GPU-native desktop UI library for Go that needs no cgo.
An application describes its UI with value-type widgets and hands the root to Run. See docs/ARCHITECTURE.md for the design.
What this package holds ¶
This package is the entry point of an application: App and Run, the windows (OpenWindow, ShowModal, WindowOf, TearOffWindow), the services of the OS (Post, Quit, Tray, TitleBar, the clipboard and the file dialogs), the theme while running (SetTheme), and the inspector. It also names the few types of package core that every widget of an application writes, such as Widget, BuildContext and StatefulBase, so that a UI file needs no import of core.
The widgets are in the packages under widgets, which an application imports directly, each for its layer (docs/ADR/0081-widget-layers.md):
import (
"github.com/bankai-tensei/gowaku"
"github.com/bankai-tensei/gowaku/layout"
"github.com/bankai-tensei/gowaku/theme"
"github.com/bankai-tensei/gowaku/widgets/basic"
"github.com/bankai-tensei/gowaku/widgets/control"
)
func header(ctx gowaku.BuildContext, title string, onAdd func()) gowaku.Widget {
th := basic.ThemeOf(ctx)
return basic.Row{Cross: layout.CrossCenter, Spacing: theme.Space8, Children: []gowaku.Widget{
basic.Expanded{Child: basic.Text{Content: title, Style: th.Text.Title}},
control.Button{Label: "Add", OnPress: onAdd},
}}
}
The geometry is in geom, the layout constants in layout, the keys in input, the theme in theme and the curves in motion.
The root package may import every other package. It holds the only mutable package-level variable of the library, the running application in currentApp, because Post has to find it from any goroutine.
Index ¶
- Constants
- Variables
- func Notify(ctx BuildContext, title, body string) error
- func OpenInspector()
- func OpenURL(u string) error
- func Post(fn func())
- func Quit()
- func Run(a App) error
- func SetTheme(ctx BuildContext, set theme.Set, mode ThemeMode)
- func ShowFileDialog(ctx BuildContext, d FileDialog, done func(paths []string, err error))
- func WriteClipboard(ctx BuildContext, c ClipboardContent)
- type App
- type BuildContext
- type ClipboardContent
- type ClipboardKinds
- type FileDialog
- type FileFilter
- type Key
- type State
- type StateBase
- type StateOf
- type StatefulBase
- type StatelessBase
- type ThemeMode
- type TitleBar
- type Tray
- type TrayOptions
- type Widget
- type WindowHandle
- func (h *WindowHandle) Activate()
- func (h *WindowHandle) Close()
- func (h *WindowHandle) Fullscreen() bool
- func (h *WindowHandle) MoveTo(e nav.TabTearOff)
- func (h *WindowHandle) RequestClose()
- func (h *WindowHandle) SetAlwaysOnTop(on bool)
- func (h *WindowHandle) SetFullscreen(on bool)
- func (h *WindowHandle) SetIcon(images []image.Image)
- func (h *WindowHandle) SetOnCloseRequest(fn func() bool)
- func (h *WindowHandle) SetSizeLimits(minSize, maxSize geom.Size)
- func (h *WindowHandle) SetTitle(title string)
- func (h *WindowHandle) ShowFileDialog(d FileDialog, done func(paths []string, err error))
- func (h *WindowHandle) Transparent() bool
- type WindowOptions
Examples ¶
Constants ¶
const ( ClipboardText = core.ClipboardText ClipboardHTML = core.ClipboardHTML ClipboardImage = core.ClipboardImage // ClipboardFiles is a list of files, as a file manager copies them. ClipboardFiles = core.ClipboardFiles )
The kinds of clipboard data.
const ( // ThemeSystem follows the OS, also while running. ThemeSystem = theme.ModeSystem // ThemeLight stays light. ThemeLight = theme.ModeLight // ThemeDark stays dark. ThemeDark = theme.ModeDark )
The theme modes.
Variables ¶
var ( ErrNoTray = platform.ErrNoTray ErrNoNotifications = platform.ErrNoNotifications )
ErrNoTray reports that the desktop shows no icons of applications, such as GNOME without the AppIndicator extension. ErrNoNotifications reports that it shows no notifications.
var ErrInvalidURL = errors.New("gowaku: not an absolute url")
ErrInvalidURL means that OpenURL was given something other than an absolute URL: an empty string, a relative reference such as "example.com" or "/docs", a path such as `C:\docs`, or a string with spaces or control characters.
var ErrNoFileDialog = platform.ErrNoFileDialog
ErrNoFileDialog means that the system has no file dialog to show. Linux needs xdg-desktop-portal for one; without it, ask for a path some other way.
var ErrUnsupported = errors.New("gowaku: this platform is not supported yet")
ErrUnsupported reports that gowaku cannot run on this operating system yet.
Functions ¶
func Notify ¶
func Notify(ctx BuildContext, title, body string) error
Notify shows a notification of the application: a toast on Windows, through the tray icon, and the notification service on Linux. A click on it runs the OnNotificationClick of the first tray. err is ErrNoNotifications where the desktop shows none. It must be called on the UI goroutine, outside a Build. Like ShowTray it goes through the host of the tree of ctx, so that a gowakutest.Tester records it, and gives ErrNoNotifications outside Run.
func OpenInspector ¶
func OpenInspector()
OpenInspector opens the Inspector, a window that shows the trees, the frames and the pictures of the other windows. F12 in any window does the same, and closes it again. Before Run, it opens the Inspector with the first window. It is safe to call from any goroutine.
It does something only in builds with -tags gowakudebug; in other builds it does nothing, and no code of the Inspector is linked in.
func OpenURL ¶
OpenURL opens u with the application that the system has for its scheme: a web page in the default browser, mailto: in the mail program, a file: URL in the application for the file. It returns once the system has the request, not when the application has opened, and may be called on any goroutine, with or without Run.
u must be an absolute URL with a scheme of two or more letters; anything else is ErrInvalidURL. OpenURL does not restrict the scheme, and a scheme can do more than show a page: a file: URL of a program runs it on Windows, and other schemes start whatever registered them. An application that opens links it did not write, such as those of a document, should allow only the schemes it means to, as in:
if p, err := url.Parse(link); err == nil && (p.Scheme == "https" || p.Scheme == "http" || p.Scheme == "mailto") {
err = gowaku.OpenURL(link)
}
It goes to ShellExecute on Windows, to NSWorkspace on macOS, and on Linux to the OpenURI portal of xdg-desktop-portal, then to xdg-open if the portal is missing or fails. No shell sees u. See docs/ADR/0116-keys-and-open-url.md.
func Post ¶
func Post(fn func())
Post schedules fn to run on the UI goroutine, which is the only place where SetState may be called. It is safe to call from any goroutine. Outside Run, fn is dropped, so that a worker can outlive the application. Work for one State goes through core.StateBase.Poster instead, which drops it once the State has left the tree and works under gowakutest as well. To run code on the UI goroutine after a delay, as to hide a message, a State uses core.StateBase.After instead, which follows the clock of the window and of gowakutest.
func Quit ¶
func Quit()
Quit closes every window, which ends Run. It asks no window: OnCloseRequest does not run, but OnClose does. An application that asks about unsaved work before it quits does so first, then calls Quit. It is safe to call from any goroutine.
func Run ¶
Run opens the window of a and blocks until the last window is closed. The calling goroutine becomes the UI goroutine. The returned error reports a failed initialization; failures during a frame panic.
Example ¶
Run opens the window and blocks until it is closed.
package main
import (
"fmt"
"github.com/bankai-tensei/gowaku"
"github.com/bankai-tensei/gowaku/widgets/basic"
)
type hello struct{ gowaku.StatelessBase }
// Build implements core.StatelessWidget.
func (hello) Build(gowaku.BuildContext) gowaku.Widget {
return basic.Center{Child: basic.Text{Content: "こんにちは、gowaku"}}
}
func main() {
run := func() {
err := gowaku.Run(gowaku.App{Title: "hello", Width: 400, Height: 300, Home: hello{}})
if err != nil {
fmt.Println(err)
}
}
_ = run
}
Output:
func SetTheme ¶
func SetTheme(ctx BuildContext, set theme.Set, mode ThemeMode)
SetTheme changes the look of every window of the application while it runs, as App.Theme and App.ThemeMode set it at the start: a settings page calls it to change the accent color or to choose light, dark or the mode of the OS.
gowaku.SetTheme(ctx, theme.FromAccent(accent), gowaku.ThemeDark)
Every widget that reads the theme rebuilds, and what the OS draws for the windows, their title bars and backgrounds, follows. With ThemeSystem the windows follow the OS again from then on. Dialogs, toasts and menus that are showing take the new theme too, unless they were opened under a basic.Theme of their own. basic.MediaQueryData.Brightness stays what the OS asks for; basic.ThemeOf(ctx).Brightness is the one in use.
The theme belongs to the application, not to a window: windows opened later take it too. Give part of the tree, or a whole window, a look of its own with basic.Theme. See docs/ADR/0067-runtime-theme.md.
The theme goes through the core.Host of the tree of ctx, as ShowTray and the clipboard functions do: in a window of Run that is the application, and under a gowakutest.Tester the Tester, whose tree takes the theme as the windows do. A host that keeps no theme, as outside both, ignores it.
It must be called on the UI goroutine, outside a Build, as from a callback.
func ShowFileDialog ¶
func ShowFileDialog(ctx BuildContext, d FileDialog, done func(paths []string, err error))
ShowFileDialog shows the file dialog of the system in front of the window of ctx, and later calls done on the UI goroutine with the chosen paths, or nil if the user canceled. It must be called on the UI goroutine, outside a Build, as from a callback.
The dialog goes through the core.Host of the tree of ctx, as ShowTray and the clipboard functions do: in a window of Run that is the dialog of the OS, and under a gowakutest.Tester a fake one that the test answers. A host that shows no file dialogs, as outside both, calls done with ErrNoFileDialog before ShowFileDialog returns.
On Windows the dialog is modal, and the windows of the application wait until it closes. On Linux it comes from xdg-desktop-portal, and the application goes on meanwhile.
func WriteClipboard ¶
func WriteClipboard(ctx BuildContext, c ClipboardContent)
WriteClipboard replaces the clipboard with every kind that c holds, so that each program takes the form it understands: an image goes as PNG and as a bitmap, files as a list that Explorer, Nautilus and Dolphin paste. It must be called on the UI goroutine, outside a Build.
Types ¶
type App ¶
type App struct {
Title string
// Width and Height are the first window's client area in logical pixels.
// Zero selects a default.
Width, Height float32
// Theme is the look of the application. The zero value is the default, and
// theme.FromAccent makes one from a color.
Theme theme.Set
// ThemeMode picks the light or dark half of Theme.
ThemeMode ThemeMode
// Background fills the window behind Home. The zero value is the canvas of
// the theme.
Background geom.Color
// OnClose runs when the first window closes. See WindowOptions.OnClose.
OnClose func()
// OnCloseRequest decides whether the first window closes when the user
// asks. See WindowOptions.OnCloseRequest.
OnCloseRequest func() bool
// OnDrawError reports what the first window could not draw. See
// WindowOptions.OnDrawError.
OnDrawError func(error)
// CustomFrame takes the title bar of the OS off the first window. See
// WindowOptions.CustomFrame.
CustomFrame bool
// Icon, MinSize, MaxSize, AlwaysOnTop, Fullscreen and Transparent are
// those of the first window. See the fields of WindowOptions.
Icon []image.Image
MinSize, MaxSize geom.Size
AlwaysOnTop bool
Fullscreen bool
Transparent bool
// AppID names the application to the Linux desktop, which matches it with
// its desktop file by it: the app_id of Wayland and the class of WM_CLASS
// on X11, such as "com.example.Editor". It should be the name of the
// desktop file without ".desktop", where the desktop takes the icon of
// the application from on Wayland. Empty is "gowaku". Windows and macOS
// ignore it.
AppID string
// Locale is the language and region the standard widgets speak in every
// window, which basic.MediaQueryData.Locale carries. The zero value
// follows the locale of the OS, also while running where the OS announces
// a change.
Locale language.Tag
// Strings are the tables of words the application adds to the bundled
// English and Japanese ones, or puts in their place. See basic.Strings
// and basic.Localizations.
Strings []*basic.Strings
Home Widget
}
App describes an application.
type ClipboardContent ¶
type ClipboardContent = core.ClipboardContent
ClipboardContent is what the clipboard holds: text, an HTML fragment, an image and a list of files, each there or not.
func ReadClipboard ¶
func ReadClipboard(ctx BuildContext, kinds ClipboardKinds) ClipboardContent
ReadClipboard reads the kinds asked for, of those that the clipboard holds. Another program owns the data, so this waits for it, up to a fraction of a second on Linux. It must be called on the UI goroutine, outside a Build.
c := gowaku.ReadClipboard(ctx, gowaku.ClipboardImage|gowaku.ClipboardFiles)
if c.Image != nil { ... }
type ClipboardKinds ¶
type ClipboardKinds = core.ClipboardKinds
ClipboardKinds is a set of the kinds of clipboard data.
func ClipboardHas ¶
func ClipboardHas(ctx BuildContext) ClipboardKinds
ClipboardHas reports what kinds the clipboard holds, without reading them: whether a Paste can be enabled. It must be called on the UI goroutine, outside a Build.
The clipboard functions go through the core.Host of the tree of ctx, the one that RenderBase.Host and BuildContext.Host return, as the copy and paste of field.Input do. In a window of Run that is the clipboard of the OS; a host that implements platform.Clipboard, as that of a gowakutest.Tester, takes every kind, and any other host only the text.
type FileDialog ¶
type FileDialog = core.FileDialog
FileDialog configures the file dialog of the system. The zero value opens one existing file. See ShowFileDialog.
type FileFilter ¶
type FileFilter = core.FileFilter
FileFilter is a choice of file types in a FileDialog, such as {Name: "Images", Patterns: []string{"*.png", "*.jpg"}}.
type StateOf ¶
StateOf is core.StateOf: a StateBase whose Widget returns a W.
Example ¶
A State that embeds StateOf gets its widget with its own type.
package main
import (
"fmt"
"github.com/bankai-tensei/gowaku"
"github.com/bankai-tensei/gowaku/widgets/basic"
"github.com/bankai-tensei/gowaku/widgets/control"
)
// stepper counts in steps of Step, which its state reads through StateOf.
type stepper struct {
gowaku.StatefulBase
Label string
Step int
}
type stepperState struct {
gowaku.StateOf[stepper]
n int
}
// CreateState implements core.StatefulWidget.
func (stepper) CreateState() gowaku.State { return &stepperState{} }
// Build implements core.State.
func (s *stepperState) Build(gowaku.BuildContext) gowaku.Widget {
w := s.Widget()
return basic.Center{Child: basic.VStack(
basic.Text{Content: fmt.Sprintf("%s: %d", w.Label, s.n)},
control.Button{Label: "Step", OnPress: func() { s.SetState(func() { s.n += s.Widget().Step }) }},
)}
}
func main() {
run := func() {
err := gowaku.Run(gowaku.App{Title: "stepper", Width: 400, Height: 300, Home: stepper{Label: "total", Step: 5}})
if err != nil {
fmt.Println(err)
}
}
_ = run
}
Output:
type StatefulBase ¶
type StatefulBase = core.StatefulBase
StatefulBase is core.StatefulBase.
Example ¶
A StatefulWidget keeps its State across builds. SetState asks for a new one.
package main
import (
"fmt"
"github.com/bankai-tensei/gowaku"
"github.com/bankai-tensei/gowaku/widgets/control"
)
type counter struct{ gowaku.StatefulBase }
type counterState struct {
gowaku.StateBase
n int
}
// CreateState implements core.StatefulWidget.
func (counter) CreateState() gowaku.State { return &counterState{} }
// Build implements core.State.
func (s *counterState) Build(gowaku.BuildContext) gowaku.Widget {
return control.Button{
Label: fmt.Sprintf("%d 回押した", s.n),
OnPress: func() { s.SetState(func() { s.n++ }) },
}
}
func main() {
var _ gowaku.Widget = counter{}
}
Output:
type ThemeMode ¶
ThemeMode says how an application treats the light and dark modes of the OS.
func CurrentTheme ¶
func CurrentTheme(ctx BuildContext) (theme.Set, ThemeMode)
CurrentTheme returns the theme of the application and its mode: those of App, or of the last SetTheme. Under a gowakutest.Tester they are those of its Options, or of the last SetTheme. The zero theme.Set stands for theme.Default, as in App, and a host that keeps no theme gives it with ThemeSystem. It must be called on the UI goroutine.
type TitleBar ¶
type TitleBar struct {
core.StatelessBase
Child Widget
}
TitleBar is the title bar of a window with CustomFrame: put it at the top of the root, with what it should hold, such as a MenuBar, a title or a search field. It draws the buttons that minimize, maximize and close the window on its right. Dragging it where nothing takes the pointer moves the window, a double click maximizes it, and a secondary click opens the menu of the window; Windows 11 offers its snap layouts over the maximize button. It is 36 logical pixels high, and takes no room while the window is fullscreen. A nil Child shows the title of the window.
basic.Column{Children: []gowaku.Widget{gowaku.TitleBar{Child: menuBar}, basic.Expanded{Child: page}}}
See docs/ADR/0048-custom-title-bar.md.
func (TitleBar) Build ¶
func (t TitleBar) Build(ctx BuildContext) Widget
Build implements core.StatelessWidget.
type Tray ¶
type Tray struct {
// contains filtered or unexported fields
}
Tray is an icon of the application in the tray of the desktop.
func ShowTray ¶
func ShowTray(ctx BuildContext, opts TrayOptions) (*Tray, error)
ShowTray shows an icon in the tray, which stays until Close or the end of Run. err is ErrNoTray where the desktop has no tray. It must be called on the UI goroutine, outside a Build, as from InitState or a callback.
The tray, like Notify, goes through the core.Host of the tree of ctx, as the clipboard functions do: in a window of Run that is the tray of the OS, and under a gowakutest.Tester a fake tray that the test inspects and clicks. A host that implements no platform.Trays, as outside both, gives ErrNoTray.
func (*Tray) Close ¶
func (t *Tray) Close()
Close takes the icon away. It must be called on the UI goroutine.
func (*Tray) Update ¶
func (t *Tray) Update(opts TrayOptions)
Update replaces what the icon shows and does. It must be called on the UI goroutine.
type TrayOptions ¶
type TrayOptions struct {
// Icon is drawn at the size of the tray, 16 to 32 pixels. Nil shows the
// icon of applications of the OS.
Icon image.Image
Tooltip string
// Menu opens on a secondary click. The tray draws it, as no window of the
// application holds it; the actions of its items are those of a MenuBar.
Menu []overlay.MenuItem
// OnActivate runs on a click on the icon.
OnActivate func()
// OnNotificationClick runs on a click on a notification of Notify. The
// first tray hears those that no tray showed.
OnNotificationClick func()
}
TrayOptions is what a tray icon shows and does. See docs/ADR/0051-tray-and-notifications.md.
type WindowHandle ¶
type WindowHandle struct {
// contains filtered or unexported fields
}
WindowHandle refers to an open window.
func OpenWindow ¶
func OpenWindow(opts WindowOptions, root Widget) (*WindowHandle, error)
OpenWindow opens another window with its own tree. It must be called on the UI goroutine, during Run.
func ShowModal ¶
func ShowModal(ctx BuildContext, opts WindowOptions, root Widget) (*WindowHandle, error)
ShowModal opens a window that belongs to the window of ctx and keeps the user from that window until the new one closes, as a dialog of the OS does: the owner takes no input, a press on it brings the modal window to the front, and it opens centered over the owner where the OS allows. opts.OnClose runs when the window closes, which is where its result goes; closing the owner closes it first. The event loop stays one: ShowModal returns at once.
var h *gowaku.WindowHandle
h, err := gowaku.ShowModal(ctx, gowaku.WindowOptions{Title: "設定", OnClose: apply},
settings{onDone: func() { h.Close() }})
It must be called on the UI goroutine, during Run, outside a Build. See docs/ADR/0047-modal-windows.md.
func TearOffWindow ¶
func TearOffWindow(e nav.TabTearOff, opts WindowOptions, root Widget) (*WindowHandle, error)
TearOffWindow opens a window for a tab torn off a TabBar, as a browser does: placed so that the tab comes out under the pointer where it was let go, if root shows its TabBar where the bar the tab left has it, with the tab first. Where the window system does not let applications place windows, as on Wayland, the window opens where the system puts it. Call it from TabBar.OnTearOff, after taking the tab out of its bar:
OnTearOff: func(e nav.TabTearOff) {
if e.Alone {
win.MoveTo(e) // the window goes with its only tab
return
}
s.remove(e.Index)
gowaku.TearOffWindow(e, gowaku.WindowOptions{Title: "…"}, docWindow{tabs: []int{e.Key.(int)}})
}
It must be called on the UI goroutine, during Run.
func WindowOf ¶
func WindowOf(ctx BuildContext) *WindowHandle
WindowOf returns the window of ctx. It must be called on the UI goroutine, during Run.
func (*WindowHandle) Activate ¶
func (h *WindowHandle) Activate()
Activate brings the window to the front and gives it the keyboard, as far as the window system lets an application do that. It must be called on the UI goroutine.
func (*WindowHandle) Close ¶
func (h *WindowHandle) Close()
Close closes the window, also from a callback of its own widgets: it goes once the callback has returned. Run returns once the last window is gone. It must be called on the UI goroutine.
func (*WindowHandle) Fullscreen ¶
func (h *WindowHandle) Fullscreen() bool
Fullscreen reports whether the window is fullscreen, by the program or by the user through the window system, also during the first Build of the window. It must be called on the UI goroutine.
func (*WindowHandle) MoveTo ¶
func (h *WindowHandle) MoveTo(e nav.TabTearOff)
MoveTo moves the window to where e says a window for its tab goes, so that a tab torn off a bar where it was alone takes its window along. It does nothing where the window system does not let applications place windows. It must be called on the UI goroutine.
func (*WindowHandle) RequestClose ¶
func (h *WindowHandle) RequestClose()
RequestClose asks to close the window as the close button of the OS does: OnCloseRequest decides, once the callback that called RequestClose has returned. While a modal window is open over the window, that window comes to the front instead. It must be called on the UI goroutine.
func (*WindowHandle) SetAlwaysOnTop ¶
func (h *WindowHandle) SetAlwaysOnTop(on bool)
SetAlwaysOnTop keeps the window above the windows of other applications, or stops; see WindowOptions.AlwaysOnTop. It must be called on the UI goroutine.
func (*WindowHandle) SetFullscreen ¶
func (h *WindowHandle) SetFullscreen(on bool)
SetFullscreen puts the window over the whole of its monitor, or back where it was; see WindowOptions.Fullscreen. The change takes effect when the window system has made it, which may be after an animation on macOS. It must be called on the UI goroutine.
func (*WindowHandle) SetIcon ¶
func (h *WindowHandle) SetIcon(images []image.Image)
SetIcon replaces the icon of the window, which the title bar, the task bar and the window switcher show. images are the same picture in one or more sizes; see WindowOptions.Icon. Nil goes back to the default. On macOS it is the icon of the application in the Dock. It must be called on the UI goroutine.
func (*WindowHandle) SetOnCloseRequest ¶
func (h *WindowHandle) SetOnCloseRequest(fn func() bool)
SetOnCloseRequest puts fn in place of WindowOptions.OnCloseRequest, so that the widgets of the window, which know what it holds, can decide whether it closes: a State calls it with the handle of WindowOf. Nil closes the window without asking. It must be called on the UI goroutine.
func (*WindowHandle) SetSizeLimits ¶
func (h *WindowHandle) SetSizeLimits(minSize, maxSize geom.Size)
SetSizeLimits bounds the client area of the window, in logical pixels; see WindowOptions.MinSize. A window outside the new bounds is resized into them. It must be called on the UI goroutine.
func (*WindowHandle) SetTitle ¶
func (h *WindowHandle) SetTitle(title string)
SetTitle changes the title of the window. It must be called on the UI goroutine.
func (*WindowHandle) ShowFileDialog ¶
func (h *WindowHandle) ShowFileDialog(d FileDialog, done func(paths []string, err error))
ShowFileDialog is the package function in front of this window, for code that holds the window and no BuildContext of it.
func (*WindowHandle) Transparent ¶
func (h *WindowHandle) Transparent() bool
Transparent reports whether the window shows the desktop through the alpha of what it draws: it was opened with WindowOptions.Transparent, and the system can, also during the first Build of the window. It must be called on the UI goroutine.
type WindowOptions ¶
type WindowOptions struct {
Title string
// Width and Height are the client area in logical pixels. Zero selects a
// default.
Width, Height float32
// Background fills the window. The zero value is the canvas of the theme.
Background geom.Color
// OnClose runs on the UI goroutine when the window closes, whether the user
// closed it, the program called Close or Quit, or the last window went. The
// tree is still whole, so it is the place to save what the window holds.
OnClose func()
// OnCloseRequest runs on the UI goroutine when the user asks to close the
// window: with the close button of the OS or of a TitleBar, Alt+F4, the
// window menu, the taskbar, the window manager or a screen reader, or when
// the program calls WindowHandle.RequestClose. Returning false keeps the
// window open, so that the application can ask about unsaved work, with a
// Dialog or ShowModal, and call WindowHandle.Close once it has the answer.
// It must not block. It runs from the event loop, outside any Build and
// outside the callbacks of the widgets, and not while a modal window is
// open over the window: a request then brings the modal window to the
// front instead. Nil closes the window at once.
//
// Closing from the program asks nothing: WindowHandle.Close, Quit, closing
// the owner of a modal window, and the window system destroying the
// window. See docs/ADR/0076-close-request.md.
OnCloseRequest func() bool
// OnDrawError runs on the UI goroutine, after a frame, when the GPU could
// not draw part of what the window shows, such as a custom shader it
// refused; the rest is drawn, and the part stays out from then on. Each
// failure is reported once. Without it, the error goes to the default
// slog logger.
OnDrawError func(error)
// CustomFrame takes the title bar of the OS off the window, so that the
// application draws its own: put a TitleBar at the top of the root. The
// edges still resize the window. See docs/ADR/0048-custom-title-bar.md.
CustomFrame bool
// Icon is the picture of the window in its title bar, the task bar and the
// window switcher: one image, best 256 pixels square, which each size the
// system wants is scaled down from, or the same picture in several sizes,
// of which the smallest that covers each size is scaled. Nil leaves the
// default of the OS. macOS has no icon per window and shows the last one
// given in the Dock, for the whole application. Wayland shows it only
// where the compositor has xdg-toplevel-icon-v1; elsewhere it takes the
// icon of the desktop file that App.AppID names.
Icon []image.Image
// MinSize and MaxSize bound the client area in logical pixels, which the
// user cannot resize the window past; they follow the scale of the
// monitor. A zero axis has no bound, so the zero values bound nothing.
MinSize, MaxSize geom.Size
// AlwaysOnTop keeps the window above the windows of other applications.
// Wayland has no way to ask for it, and ignores it.
AlwaysOnTop bool
// Fullscreen opens the window over the whole of its monitor, without a
// frame. A TitleBar takes no room while the window is fullscreen, and the
// title bar that gowaku draws on some Wayland compositors goes too.
Fullscreen bool
// Transparent opens a window that shows the desktop through the alpha of
// what it draws, for shaped or glass-like windows: the zero Background is
// then clear instead of the canvas of the theme. It is fixed when the
// window opens. Where the system cannot, the window is opaque and the zero
// Background is the canvas again; WindowHandle.Transparent tells. On X11
// it needs a compositing manager. See docs/ADR/0111-window-decorations.md.
Transparent bool
}
WindowOptions configures a new window.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gowaku-bindgen
command
Command gowaku-bindgen writes Go bindings of Wayland protocols for gowaku, without cgo.
|
Command gowaku-bindgen writes Go bindings of Wayland protocols for gowaku, without cgo. |
|
gowaku-preview
command
Command gowaku-preview draws the previews of Go packages built with gowaku to PNG files, with a report of what each shows and what may be wrong with it: overflow, controls without a label, text of low contrast, and what changed since the last run.
|
Command gowaku-preview draws the previews of Go packages built with gowaku to PNG files, with a report of what each shows and what may be wrong with it: overflow, controls without a label, text of low contrast, and what changed since the last run. |
|
gowaku-shader
command
Command gowaku-shader compiles a custom shader for gowaku.
|
Command gowaku-shader compiles a custom shader for gowaku. |
|
Package core is the declarative heart of gowaku: the three trees of Widget, element and RenderObject, the reconciler that diffs them, and the scheduling of build, layout and paint.
|
Package core is the declarative heart of gowaku: the three trees of Widget, element and RenderObject, the reconciler that diffs them, and the scheduling of build, layout and paint. |
|
examples
|
|
|
animated
command
Command animated plays animated pictures side by side with AnimatedImage: two GIF files that it makes itself, and any GIF, APNG, WebP, PNG or JPEG files named on the command line.
|
Command animated plays animated pictures side by side with AnimatedImage: two GIF files that it makes itself, and any GIF, APNG, WebP, PNG or JPEG files named on the command line. |
|
bigfile
command
Command bigfile opens a file of any size at once: the editor reads only the lines it shows, from a LineSource that indexes the file on a goroutine of its own, and holds in memory only the lines that are edited.
|
Command bigfile opens a file of any size at once: the editor reads only the lines it shows, from a LineSource that indexes the file on a goroutine of its own, and holds in memory only the lines that are edited. |
|
counter
command
Command counter is the smallest sample with state: a State, a theme, and an implicit animation.
|
Command counter is the smallest sample with state: a State, a theme, and an implicit animation. |
|
decorations
command
Command decorations shows what a window can be asked for besides its contents: an icon, bounds on its size, always on top, fullscreen and a transparent background.
|
Command decorations shows what a window can be asked for besides its contents: an icon, bounds on its size, always on top, fullscreen and a transparent background. |
|
dragdrop
command
Command dragdrop takes files and text dropped from other programs, drags text and a file out to them, and shows a tray icon and notifications.
|
Command dragdrop takes files and text dropped from other programs, drags text and a file out to them, and shows a tray icon and notifications. |
|
form
command
Command form is a sample of text input: text fields with Japanese input, a checkbox and buttons.
|
Command form is a sample of text input: text fields with Japanese input, a checkbox and buttons. |
|
gallery
command
Command gallery shows the widgets of gowaku in the design of docs/DESIGN.md, as a settings window.
|
Command gallery shows the widgets of gowaku in the design of docs/DESIGN.md, as a settings window. |
|
glass
command
Command glass shows a glass dialog, Dialog{Glass: true}, over a colorful list that keeps scrolling behind it.
|
Command glass shows a glass dialog, Dialog{Glass: true}, over a colorful list that keeps scrolling behind it. |
|
hello
command
Command hello is the smallest gowaku application.
|
Command hello is the smallest gowaku application. |
|
jptext
command
Command jptext shows the Japanese typesetting of gowaku.
|
Command jptext shows the Japanese typesetting of gowaku. |
|
listview
command
Command listview scrolls 10,000 rows of an icon, text and a button.
|
Command listview scrolls 10,000 rows of an icon, text and a button. |
|
menus
command
Command menus is a small editor with a menu bar, shortcuts and a context menu.
|
Command menus is a small editor with a menu bar, shortcuts and a context menu. |
|
multiwindow
command
Command multiwindow opens windows that share one GPU device and one piece of state.
|
Command multiwindow opens windows that share one GPU device and one piece of state. |
|
navigator
command
Command navigator is a list of notes that opens each note on a page of its own: the icon of the note flies from its row to the page (Hero), and the page slides in over the list.
|
Command navigator is a list of notes that opens each note on a page of its own: the icon of the note flies from its row to the page (Hero), and the page slides in over the list. |
|
notes
command
Command notes is a notebook application: a folder of plain text notes with search, tabs and windows, vertical and horizontal writing, ruby in the notation of Aozora Bunko, autosave, menus, a command palette and file drops.
|
Command notes is a notebook application: a folder of plain text notes with search, tabs and windows, vertical and horizontal writing, ruby in the notation of Aozora Bunko, autosave, menus, a command palette and file drops. |
|
notes/store
Package store keeps what the notes sample saves: the text files, the settings, the state of each file, the recent files, the open windows and the autosaved text that a crash would otherwise lose.
|
Package store keeps what the notes sample saves: the text files, the settings, the state of each file, the recent files, the open windows and the autosaved text that a crash would otherwise lose. |
|
rects
command
Command rects is a sample of the SDF pipeline.
|
Command rects is a sample of the SDF pipeline. |
|
rotate
command
Command rotate turns widgets with Transform: a card that spins with an AnimationController, and a turned button that is hit only inside its turned shape.
|
Command rotate turns widgets with Transform: a card that spins with an AnimationController, and a turned button that is hit only inside its turned shape. |
|
scripts
command
Command scripts shows what gowaku sets beyond Japanese: color emoji, right-to-left text mixed with left-to-right, variable fonts and English hyphenation.
|
Command scripts shows what gowaku sets beyond Japanese: color emoji, right-to-left text mixed with left-to-right, variable fonts and English hyphenation. |
|
shader
command
Command shader shows custom shaders: an aurora that CustomPaint draws, and a shimmer and ripples that ShaderMask lays over text and a picture.
|
Command shader shows custom shaders: an aurora that CustomPaint draws, and a shimmer and ripples that ShaderMask lays over text and a picture. |
|
shader/shaders
Package shaders holds the custom shaders of examples/shader, written in HLSL and compiled by cmd/gowaku-shader, with the Go fallbacks that let the CPU renderer of gowakutest draw them, and the scene of the example, which the golden images of internal/golden draw too.
|
Package shaders holds the custom shaders of examples/shader, written in HLSL and compiled by cmd/gowaku-shader, with the Go fallbacks that let the CPU renderer of gowakutest draw them, and the scene of the example, which the golden images of internal/golden draw too. |
|
tabs
command
Command tabs is a browser in miniature: documents in tabs that close, move, and tear off into windows of their own.
|
Command tabs is a browser in miniature: documents in tabs that close, move, and tear off into windows of their own. |
|
tategaki
command
Command tategaki shows vertical Japanese text: the opening of Natsume Soseki's Botchan (1906, public domain, from Aozora Bunko) set in columns with ruby, tate-chu-yoko and Western text turned sideways, next to the same text set horizontally and justified.
|
Command tategaki shows vertical Japanese text: the opening of Natsume Soseki's Botchan (1906, public domain, from Aozora Bunko) set in columns with ruby, tate-chu-yoko and Western text turned sideways, next to the same text set horizontally and justified. |
|
todo
command
Command todo is a small to-do application that runs on every backend: the same code runs on Windows with Direct3D 11 and on Linux with Vulkan.
|
Command todo is a small to-do application that runs on every backend: the same code runs on Windows with Direct3D 11 and on Linux with Vulkan. |
|
zoom
command
Command zoom has a list that zooms with a pinch of the touchpad, or Ctrl and the wheel, and a pad that draws with a finger, a pen or the mouse, as thick as the pen presses.
|
Command zoom has a list that zooms with a pinch of the touchpad, or Ctrl and the wheel, and a pad that draws with a finger, a pen or the mouse, as thick as the pen presses. |
|
Package geom provides the 2D value types shared by every gowaku layer: Offset, Size, Rect, RRect, Affine and Color, plus float32 math helpers.
|
Package geom provides the 2D value types shared by every gowaku layer: Offset, Size, Rect, RRect, Affine and Color, plus float32 math helpers. |
|
Package gowakupreview draws the previews of a package to PNG files, with a report of what each one shows and what may be wrong with it.
|
Package gowakupreview draws the previews of a package to PNG files, with a report of what each one shows and what may be wrong with it. |
|
Package gowakutest runs a widget tree in a test, without a window or a GPU, the way gowaku.Run would run it in a window.
|
Package gowakutest runs a widget tree in a test, without a window or a GPU, the way gowaku.Run would run it in a window. |
|
Package gpu defines the rendering backend interface.
|
Package gpu defines the rendering backend interface. |
|
d3d11
Package d3d11 implements gpu.Backend on Direct3D 11 without cgo.
|
Package d3d11 implements gpu.Backend on Direct3D 11 without cgo. |
|
metal
Package metal implements gpu.Backend with Metal on macOS, without cgo.
|
Package metal implements gpu.Backend with Metal on macOS, without cgo. |
|
soft
Package soft implements gpu.Backend on the CPU, as the reference that the GPU backends are compared to.
|
Package soft implements gpu.Backend on the CPU, as the reference that the GPU backends are compared to. |
|
vulkan
Package vulkan implements gpu.Backend on Vulkan 1.0 without cgo.
|
Package vulkan implements gpu.Backend on Vulkan 1.0 without cgo. |
|
Package icons is a small set of common icons for basic.Icon and the widgets that take a *paint.Path, such as nav.BreadcrumbItem.Icon, Tree.IconOf, SidebarItem.Icon, control.Button.Icon and Toolbar items:
|
Package icons is a small set of common icons for basic.Icon and the widgets that take a *paint.Path, such as nav.BreadcrumbItem.Icon, Tree.IconOf, SidebarItem.Icon, control.Button.Icon and Toolbar items: |
|
Package input holds the value types of user input that both the platform and the widget tree need to know: keys, modifiers, pointer buttons, mouse cursors and IME compositions.
|
Package input holds the value types of user input that both the platform and the widget tree need to know: keys, modifiers, pointer buttons, mouse cursors and IME compositions. |
|
internal
|
|
|
catalog
Package catalog is the widget catalog of docs/catalog: one entry for each public widget of the packages under widgets, with a short description in Japanese and English, a scene drawn on the CPU in light and dark, and the code of that scene as the example.
|
Package catalog is the widget catalog of docs/catalog: one entry for each public widget of the packages under widgets, with a short description in Japanese and English, a scene drawn on the CPU in light and dark, and the code of that scene as the example. |
|
cmd/catalog
command
Command catalog writes the widget catalog of docs/catalog from internal/catalog: the pictures, drawn on the CPU, the Markdown pages in Japanese and English, and the static site.
|
Command catalog writes the widget catalog of docs/catalog from internal/catalog: the pictures, drawn on the CPU, the Markdown pages in Japanese and English, and the static site. |
|
cmd/shaderc
command
Command shaderc compiles the HLSL shaders of a directory for one backend.
|
Command shaderc compiles the HLSL shaders of a directory for one backend. |
|
golden
Package golden draws fixed scenes on any gpu.Backend and compares the result with stored PNGs.
|
Package golden draws fixed scenes on any gpu.Backend and compares the result with stored PNGs. |
|
linuxwin
Package linuxwin picks the window system of Linux: Wayland when the session has one, X11 otherwise (docs/ADR/0021-wayland-platform.md).
|
Package linuxwin picks the window system of Linux: Wayland when the session has one, X11 otherwise (docs/ADR/0021-wayland-platform.md). |
|
shadertool
Package shadertool holds what internal/cmd/shaderc, which compiles the shaders of gowaku, and cmd/gowaku-shader, which compiles custom shaders, share: finding fxc, dxc and spirv-cross, running them, and the prelude and epilogue that turn the function of a custom shader into a pixel shader.
|
Package shadertool holds what internal/cmd/shaderc, which compiles the shaders of gowaku, and cmd/gowaku-shader, which compiles custom shaders, share: finding fxc, dxc and spirv-cross, running them, and the prelude and epilogue that turn the function of a custom shader into a pixel shader. |
|
shot
Package shot runs a widget tree outside the event loop of gowaku.Run, on a real window and GPU, for samples that take screenshots or measure frames.
|
Package shot runs a widget tree outside the event loop of gowaku.Run, on a real window and GPU, for samples that take screenshots or measure frames. |
|
testutil
Package testutil renders widgets to text, for tests that need neither a GPU nor a window.
|
Package testutil renders widgets to text, for tests that need neither a GPU nor a window. |
|
Package layout provides the standard render objects: padding, alignment, sizing, flex, stacking and box decoration.
|
Package layout provides the standard render objects: padding, alignment, sizing, flex, stacking and box decoration. |
|
markdown
module
|
|
|
Package motion holds animation: curves, tweens, springs, the controller that runs them, and the bookkeeping of implicit animations.
|
Package motion holds animation: curves, tweens, springs, the controller that runs them, and the bookkeeping of implicit animations. |
|
Package paint records drawing commands.
|
Package paint records drawing commands. |
|
Package platform defines the window system abstraction that gowaku draws on: Platform, Window, Event and NativeHandle.
|
Package platform defines the window system abstraction that gowaku draws on: Platform, Window, Event and NativeHandle. |
|
cocoa
Package cocoa implements platform.Platform with AppKit on macOS, without cgo.
|
Package cocoa implements platform.Platform with AppKit on macOS, without cgo. |
|
dbus
Package dbus is what gowaku asks of Linux desktops over D-Bus: the color scheme and enable-animations of xdg-desktop-portal, its file chooser, and the AT-SPI2 bridge that screen readers such as Orca read the windows through (ADR 0043).
|
Package dbus is what gowaku asks of Linux desktops over D-Bus: the color scheme and enable-animations of xdg-desktop-portal, its file chooser, and the AT-SPI2 bridge that screen readers such as Orca read the windows through (ADR 0043). |
|
internal/clip
Package clip converts clipboard data between platform.ClipboardContent and the formats of the OS: the MIME types of X11 and Wayland, and the HTML Format and device-independent bitmaps of Windows.
|
Package clip converts clipboard data between platform.ClipboardContent and the formats of the OS: the MIME types of X11 and Wayland, and the HTML Format and device-independent bitmaps of Windows. |
|
internal/desktop
Package desktop reads settings of Linux desktops that do not depend on the window system: platform/x11 and platform/wayland share it.
|
Package desktop reads settings of Linux desktops that do not depend on the window system: platform/x11 and platform/wayland share it. |
|
internal/evqueue
Package evqueue is the event queue that the platforms share.
|
Package evqueue is the event queue that the platforms share. |
|
internal/frame
Package frame holds what the Linux platforms share about windows whose title bar the application draws: which edge of the window the pointer resizes.
|
Package frame holds what the Linux platforms share about windows whose title bar the application draws: which edge of the window the pointer resizes. |
|
internal/icon
Package icon picks and scales the pictures of a window icon to the sizes a window system wants.
|
Package icon picks and scales the pictures of a window icon to the sizes a window system wants. |
|
internal/keysym
Package keysym maps the keysyms of X11 and xkbcommon, which share their values, to input.KeyCode.
|
Package keysym maps the keysyms of X11 and xkbcommon, which share their values, to input.KeyCode. |
|
wayland
Package wayland implements platform.Platform on Wayland without cgo.
|
Package wayland implements platform.Platform on Wayland without cgo. |
|
win32
Package win32 implements platform.Platform on Win32 without cgo.
|
Package win32 implements platform.Platform on Win32 without cgo. |
|
win32/com
Package com implements COM objects in Go without cgo, for the interfaces that Windows calls back into: the UI Automation providers today, the drag-and-drop and file dialog event interfaces later (ADR 0042 §5).
|
Package com implements COM objects in Go without cgo, for the interfaces that Windows calls back into: the UI Automation providers today, the drag-and-drop and file dialog event interfaces later (ADR 0042 §5). |
|
x11
Package x11 implements platform.Platform on Xlib without cgo.
|
Package x11 implements platform.Platform on Xlib without cgo. |
|
Package render turns a paint.DisplayList into the gpu.Batch that a backend draws.
|
Package render turns a paint.DisplayList into the gpu.Batch that a backend draws. |
|
Package semantics describes a window to assistive technology: the nodes of the accessibility tree, their roles, states and actions, and the difference between two trees.
|
Package semantics describes a window to assistive technology: the nodes of the accessibility tree, their roles, states and actions, and the difference between two trees. |
|
Package text turns strings into positioned glyphs: font lookup with fallback, shaping, Japanese line breaking through text/jlreq, cursor and selection geometry, and the glyph atlas.
|
Package text turns strings into positioned glyphs: font lookup with fallback, shaping, Japanese line breaking through text/jlreq, cursor and selection geometry, and the glyph atlas. |
|
aozora
Package aozora reads the ruby notation of Aozora Bunko: |漢字《かんじ》, or 漢字《かんじ》 when the base is the run of kanji just before 《.
|
Package aozora reads the ruby notation of Aozora Bunko: |漢字《かんじ》, or 漢字《かんじ》 when the base is the run of kanji just before 《. |
|
hyphen
Package hyphen finds where words may break with a hyphen, by Liang's algorithm and TeX patterns.
|
Package hyphen finds where words may break with a hyphen, by Liang's algorithm and TeX patterns. |
|
jlreq
Package jlreq breaks Japanese text into lines by the rules of "Requirements for Japanese Text Layout" (W3C JLReq): line start and line end prohibitions, unbreakable sequences, squeezing of adjacent punctuation, hanging punctuation and the space between Japanese and Western text.
|
Package jlreq breaks Japanese text into lines by the rules of "Requirements for Japanese Text Layout" (W3C JLReq): line start and line end prohibitions, unbreakable sequences, squeezing of adjacent punctuation, hanging punctuation and the space between Japanese and Western text. |
|
Package theme holds the tokens of the design of docs/DESIGN.md: the colors that follow from one accent, the type scale, the corners and the shadows.
|
Package theme holds the tokens of the design of docs/DESIGN.md: the colors that follow from one accent, the type scale, the corners and the shadows. |
|
Package widgets holds no code.
|
Package widgets holds no code. |
|
basic
Package basic is the lowest layer of the widgets: the theme, media and strings of the tree, the boxes that lay out children (Container, Padding, Column, Row, Stack, Wrap, Grid), visual effects and transforms, implicit animations, text, images and scrolling.
|
Package basic is the lowest layer of the widgets: the theme, media and strings of the tree, the boxes that lay out children (Container, Padding, Column, Row, Stack, Wrap, Grid), visual effects and transforms, implicit animations, text, images and scrolling. |
|
collection
Package collection shows many items: list views, trees, data tables and property grids, with their controllers.
|
Package collection shows many items: list views, trees, data tables and property grids, with their controllers. |
|
control
Package control holds the controls that the library draws in its own style: buttons, checkboxes, switches, sliders, segmented controls, radios, chips, cards, steppers, tabs, split panes, badges and progress indicators.
|
Package control holds the controls that the library draws in its own style: buttons, checkboxes, switches, sliders, segmented controls, radios, chips, cards, steppers, tabs, split panes, badges and progress indicators. |
|
editor
Package editor is the editor of long documents: a buffer of lines, find and replace, built on the text fields of widgets/field.
|
Package editor is the editor of long documents: a buffer of lines, find and replace, built on the text fields of widgets/field. |
|
field
Package field holds the widgets that take a value from the user by typing or picking: text fields (with ruby), search fields, forms, autocomplete, dropdown menus, calendars and date and time pickers, and the command palette with its fuzzy matcher, Fuzzy, which applications can use for lists of their own.
|
Package field holds the widgets that take a value from the user by typing or picking: text fields (with ruby), search fields, forms, autocomplete, dropdown menus, calendars and date and time pickers, and the command palette with its fuzzy matcher, Fuzzy, which applications can use for lists of their own. |
|
interact
Package interact turns input into callbacks: gestures, mouse regions, focus, shortcuts and actions, drag and drop, and the semantics that a screen reader reads.
|
Package interact turns input into callbacks: gestures, mouse regions, focus, shortcuts and actions, drag and drop, and the semantics that a screen reader reads. |
|
internal/behavior
Package behavior holds Control, the hover, focus and press behavior that the controls of the library share, which gives them their feel.
|
Package behavior holds Control, the hover, focus and press behavior that the controls of the library share, which gives them their feel. |
|
internal/kit
Package kit holds what the widgets packages share and do not export to applications: timings of controls, the undo history, type-ahead search, small glyphs and helpers.
|
Package kit holds what the widgets packages share and do not export to applications: timings of controls, the undo history, type-ahead search, small glyphs and helpers. |
|
internal/wtest
Package wtest holds the test helpers that the widget packages share: trees with a shaper, frame stepping, display list inspection, semantics queries, synthetic input and a fake platform host.
|
Package wtest holds the test helpers that the widget packages share: trees with a shaper, frame stepping, display list inspection, semantics queries, synthetic input and a fake platform host. |
|
nav
Package nav moves the user between pages and places: the navigator and its routes, hero transitions, the back button, breadcrumbs, tab bars, toolbars, and the dock layout whose tabs move between groups of panels.
|
Package nav moves the user between pages and places: the navigator and its routes, hero transitions, the back button, breadcrumbs, tab bars, toolbars, and the dock layout whose tabs move between groups of panels. |
|
overlay
Package overlay draws above the page: the overlay itself, dialogs, sheets, toasts, tooltips, and the menus (popup menus, the menu bar, context menus and popup lists).
|
Package overlay draws above the page: the overlay itself, dialogs, sheets, toasts, tooltips, and the menus (popup menus, the menu bar, context menus and popup lists). |

