app

package
Version: v0.0.0-...-dee53b3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT, Unlicense Imports: 45 Imported by: 340

Documentation

Overview

Package app provides a platform-independent interface to operating system functionality for running graphical user interfaces.

See https://gioui.org for instructions to set up and run Gio programs.

Windows

Create a new Window by calling NewWindow. On mobile platforms or when Gio is embedded in another project, NewWindow merely connects with a previously created window.

A Window is run by receiving events from its Events channel. The most important event is FrameEvent that prompts an update of the window contents and state.

For example:

import "gioui.org/unit"

w := app.NewWindow()
for e := range w.Events() {
	if e, ok := e.(system.FrameEvent); ok {
		ops.Reset()
		// Add operations to ops.
		...
		// Completely replace the window contents and state.
		e.Frame(ops)
	}
}

A program must keep receiving events from the event channel until DestroyEvent is received.

Main

The Main function must be called from a program's main function, to hand over control of the main thread to operating systems that need it.

Because Main is also blocking on some platforms, the event loop of a Window must run in a goroutine.

For example, to display a blank but otherwise functional window:

package main

import "gioui.org/app"

func main() {
	go func() {
		w := app.NewWindow()
		for range w.Events() {
		}
	}()
	app.Main()
}

Event queue

A FrameEvent's Queue method returns an event.Queue implementation that distributes incoming events to the event handlers declared in the last frame. See the gioui.org/io/event package for more information about event handlers.

Permissions

The packages under gioui.org/app/permission should be imported by a Gio program or by one of its dependencies to indicate that specific operating-system permissions are required. Please see documentation for package gioui.org/app/permission for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataDir

func DataDir() (string, error)

DataDir returns a path to use for application-specific configuration data. On desktop systems, DataDir use os.UserConfigDir. On iOS NSDocumentDirectory is queried. For Android Context.getFilesDir is used.

BUG: DataDir blocks on Android until init functions have completed.

func Main

func Main()

Main must be called last from the program main function. On most platforms Main blocks forever, for Android and iOS it returns immediately to give control of the main thread back to the system.

Calling Main is necessary because some operating systems require control of the main thread of the program for running windows.

Types

type Config

type Config struct {
	// Size is the window dimensions (Width, Height).
	Size image.Point
	// MaxSize is the window maximum allowed dimensions.
	MaxSize image.Point
	// MinSize is the window minimum allowed dimensions.
	MinSize image.Point
	// Title is the window title displayed in its decoration bar.
	Title string
	// WindowMode is the window mode.
	Mode WindowMode
	// StatusColor is the color of the Android status bar.
	StatusColor color.NRGBA
	// NavigationColor is the color of the navigation bar
	// on Android, or the address bar in browsers.
	NavigationColor color.NRGBA
	// Orientation is the current window orientation.
	Orientation Orientation
	// CustomRenderer is true when the window content is rendered by the
	// client.
	CustomRenderer bool
	// Decorated reports whether window decorations are provided automatically.
	Decorated bool
	// contains filtered or unexported fields
}

Config describes a Window configuration.

type ConfigEvent

type ConfigEvent struct {
	Config Config
}

ConfigEvent is sent whenever the configuration of a Window changes.

func (ConfigEvent) ImplementsEvent

func (ConfigEvent) ImplementsEvent()

type Option

type Option func(unit.Metric, *Config)

Option configures a window.

func CustomRenderer

func CustomRenderer(custom bool) Option

CustomRenderer controls whether the window contents is rendered by the client. If true, no GPU context is created.

Caller must assume responsibility for rendering which includes initializing the render backend, swapping the framebuffer and handling frame pacing.

func Decorated

func Decorated(enabled bool) Option

Decorated controls whether Gio and/or the platform are responsible for drawing window decorations. Providing false indicates that the application will either be undecorated or will draw its own decorations.

func MaxSize

func MaxSize(w, h unit.Dp) Option

MaxSize sets the maximum size of the window.

func MinSize

func MinSize(w, h unit.Dp) Option

MinSize sets the minimum size of the window.

func NavigationColor(color color.NRGBA) Option

NavigationColor sets the color of the navigation bar on Android, or the address bar in browsers.

func Size

func Size(w, h unit.Dp) Option

Size sets the size of the window. The mode will be changed to Windowed.

func StatusColor

func StatusColor(color color.NRGBA) Option

StatusColor sets the color of the Android status bar.

func Title

func Title(t string) Option

Title sets the title of the window.

type Orientation

type Orientation uint8

Orientation is the orientation of the app (Orientation.Option sets it).

Supported platforms are Android and JS.

const (
	// AnyOrientation allows the window to be freely orientated.
	AnyOrientation Orientation = iota
	// LandscapeOrientation constrains the window to landscape orientations.
	LandscapeOrientation
	// PortraitOrientation constrains the window to portrait orientations.
	PortraitOrientation
)

func (Orientation) Option

func (o Orientation) Option() Option

func (Orientation) String

func (o Orientation) String() string

type ViewEvent

type ViewEvent interface {
	ImplementsEvent()
	// contains filtered or unexported methods
}

ViewEvent provides handles to the underlying window objects for the current display protocol.

type WaylandViewEvent

type WaylandViewEvent struct {
	// Display is the *wl_display returned by wl_display_connect.
	Display unsafe.Pointer
	// Surface is the *wl_surface returned by wl_compositor_create_surface.
	Surface unsafe.Pointer
}

func (WaylandViewEvent) ImplementsEvent

func (WaylandViewEvent) ImplementsEvent()

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window represents an operating system window.

func NewWindow

func NewWindow(options ...Option) *Window

NewWindow creates a new window for a set of window options. The options are hints; the platform is free to ignore or adjust them.

If the current program is running on iOS or Android, NewWindow returns the window previously created by the platform.

Calling NewWindow more than once is not supported on iOS, Android, WebAssembly.

func (*Window) Events

func (w *Window) Events() <-chan event.Event

Events returns the channel where events are delivered.

func (*Window) Invalidate

func (w *Window) Invalidate()

Invalidate the window such that a FrameEvent will be generated immediately. If the window is inactive, the event is sent when the window becomes active.

Note that Invalidate is intended for externally triggered updates, such as a response from a network request. InvalidateOp is more efficient for animation and similar internal updates.

Invalidate is safe for concurrent use.

func (*Window) Option

func (w *Window) Option(opts ...Option)

Option applies the options to the window.

func (*Window) Perform

func (w *Window) Perform(actions system.Action)

Perform the actions on the window.

func (*Window) ReadClipboard

func (w *Window) ReadClipboard()

ReadClipboard initiates a read of the clipboard in the form of a clipboard.Event. Multiple reads may be coalesced to a single event.

func (*Window) Run

func (w *Window) Run(f func())

Run f in the same thread as the native window event loop, and wait for f to return or the window to close. Run is guaranteed not to deadlock if it is invoked during the handling of a ViewEvent, system.FrameEvent, system.StageEvent; call Run in a separate goroutine to avoid deadlock in all other cases.

Note that most programs should not call Run; configuring a Window with CustomRenderer is a notable exception.

func (*Window) WriteClipboard

func (w *Window) WriteClipboard(s string)

WriteClipboard writes a string to the clipboard.

type WindowMode

type WindowMode uint8

WindowMode is the window mode (WindowMode.Option sets it). Note that mode can be changed programatically as well as by the user clicking on the minimize/maximize buttons on the window's title bar.

const (
	// Windowed is the normal window mode with OS specific window decorations.
	Windowed WindowMode = iota
	// Fullscreen is the full screen window mode.
	Fullscreen
	// Minimized is for systems where the window can be minimized to an icon.
	Minimized
	// Maximized is for systems where the window can be made to fill the available monitor area.
	Maximized
)

func (WindowMode) Option

func (m WindowMode) Option() Option

Option changes the mode of a Window.

func (WindowMode) String

func (m WindowMode) String() string

String returns the mode name.

type X11ViewEvent

type X11ViewEvent struct {
	// Display is a pointer to the X11 Display created by XOpenDisplay.
	Display unsafe.Pointer
	// Window is the X11 window ID as returned by XCreateWindow.
	Window uintptr
}

func (X11ViewEvent) ImplementsEvent

func (X11ViewEvent) ImplementsEvent()

Directories

Path Synopsis
Package permission includes sub-packages that should be imported by a Gio program or by one of its dependencies to indicate that specific operating-system permissions are required.
Package permission includes sub-packages that should be imported by a Gio program or by one of its dependencies to indicate that specific operating-system permissions are required.
bluetooth
Package bluetooth implements permissions to access Bluetooth and Bluetooth Low Energy hardware, including the ability to discover and pair devices.
Package bluetooth implements permissions to access Bluetooth and Bluetooth Low Energy hardware, including the ability to discover and pair devices.
camera
Package camera implements permissions to access camera hardware.
Package camera implements permissions to access camera hardware.
networkstate
Package networkstate implements permissions to access network connectivity information.
Package networkstate implements permissions to access network connectivity information.
storage
Package storage implements read and write storage permissions on mobile devices.
Package storage implements read and write storage permissions on mobile devices.
wakelock
Package wakelock implements permission to acquire locks that keep the system from suspending.
Package wakelock implements permission to acquire locks that keep the system from suspending.
internal
log
Package points standard output, standard error and the standard library package log to the platform logger.
Package points standard output, standard error and the standard library package log to the platform logger.
xkb
Package xkb implements a Go interface for the X Keyboard Extension library.
Package xkb implements a Go interface for the X Keyboard Extension library.

Jump to

Keyboard shortcuts

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