app

package
v0.0.0-...-b767601 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT, Unlicense Imports: 27 Imported by: 0

Documentation

Overview

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

See https://github.com/kanryu/mado 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 calling its NextEvent method in a loop. The most important event is [FrameEvent] that prompts an update of the window contents.

For example:

w := app.NewWindow()
for {
	e := w.NextEvent()
	if e, ok := e.(app.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 "github.com/kanryu/mado/app"

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

Permissions

The packages under github.com/kanryu/mado/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 github.com/kanryu/mado/app/permission for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomRenderer

func CustomRenderer(custom bool) mado.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 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 Decorated

func Decorated(enabled bool) mado.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 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.

func MaxSize

func MaxSize(w, h unit.Dp) mado.Option

MaxSize sets the maximum size of the window.

func MinSize

func MinSize(w, h unit.Dp) mado.Option

MinSize sets the minimum size of the window.

func NavigationColor(color color.NRGBA) mado.Option

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

func NewContext

func NewContext(ops *op.Ops, e mado.FrameEvent) layout.Context

NewContext is shorthand for

layout.Context{
  Ops: ops,
  Now: e.Now,
  Source: e.Source,
  Metric: e.Metric,
  Constraints: layout.Exact(e.Size),
}

NewContext calls ops.Reset and adjusts ops for e.Insets.

func Size

func Size(w, h unit.Dp) mado.Option

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

func StatusColor

func StatusColor(color color.NRGBA) mado.Option

StatusColor sets the color of the Android status bar.

func Title

func Title(t string) mado.Option

Title sets the title of the window.

Types

type Callbacks

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

func (*Callbacks) ActionAt

func (c *Callbacks) ActionAt(p f32.Point) (system.Action, bool)

func (*Callbacks) AppendSemanticDiffs

func (c *Callbacks) AppendSemanticDiffs(diffs []input.SemanticID) []input.SemanticID

func (*Callbacks) ClickFocus

func (c *Callbacks) ClickFocus()

func (*Callbacks) EditorInsert

func (c *Callbacks) EditorInsert(text string, preedit bool)

func (*Callbacks) EditorReplace

func (c *Callbacks) EditorReplace(r key.Range, text string, preedit bool)

func (*Callbacks) EditorState

func (c *Callbacks) EditorState() mado.EditorState

func (*Callbacks) Event

func (c *Callbacks) Event(e event.Event) bool

func (*Callbacks) GetWindow

func (c *Callbacks) GetWindow() mado.Window

func (*Callbacks) LookupSemantic

func (c *Callbacks) LookupSemantic(semID input.SemanticID) (input.SemanticNode, bool)

LookupSemantic looks up a semantic node from an ID. The zero ID denotes the root.

func (*Callbacks) SemanticAt

func (c *Callbacks) SemanticAt(pos f32.Point) (input.SemanticID, bool)

func (*Callbacks) SemanticRoot

func (c *Callbacks) SemanticRoot() input.SemanticID

SemanticRoot returns the ID of the semantic root.

func (*Callbacks) SetComposingRegion

func (c *Callbacks) SetComposingRegion(r key.Range)

func (*Callbacks) SetDriver

func (c *Callbacks) SetDriver(d mado.Driver)

func (*Callbacks) SetEditorSelection

func (c *Callbacks) SetEditorSelection(r key.Range)

func (*Callbacks) SetEditorSnippet

func (c *Callbacks) SetEditorSnippet(r key.Range)

func (*Callbacks) SetWindow

func (c *Callbacks) SetWindow(w mado.Window)

type Window

type Window struct {

	// wakeupFuncs is sent wakeup functions when the driver changes.
	WakeupFuncs chan func()

	// options are the options waiting to be applied.
	Options chan []mado.Option
	// actions are the actions waiting to be performed.
	Actions chan system.Action

	Destroy chan struct{}

	// metric is the metric from the most recent frame.
	Metric unit.Metric

	Queue input.Router

	Decorations struct {
		op.Ops
		// enabled tracks the Decorated option as
		// given to the Option method. It may differ
		// from Config.Decorated depending on platform
		// capability.
		Enabled bool
		mado.Config
		Height        unit.Dp
		CurrentHeight int
		*material.Theme
		*widget.Decorations
	}

	// semantic data, lazily evaluated if requested by a backend to speed up
	// the cases where semantic data is not needed.
	Semantic struct {
		// uptodate tracks whether the fields below are up to date.
		Uptodate bool
		Root     input.SemanticID
		PrevTree []input.SemanticNode
		Tree     []input.SemanticNode
		Ids      map[input.SemanticID]input.SemanticNode
	}

	ImeState mado.EditorState

	// event stores the state required for processing and delivering events
	// from NextEvent. If we had support for range over func, this would
	// be the iterator state.
	EventState struct {
		Created     bool
		InitialOpts []mado.Option
		Wakeup      func()
		Timer       *time.Timer
	}
	// contains filtered or unexported fields
}

Window represents an operating system window.

func NewWindow

func NewWindow(callbacks mado.Callbacks, options ...mado.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) CollectSemanticDiffs

func (w *Window) CollectSemanticDiffs(diffs *[]input.SemanticID, n input.SemanticNode)

CollectSemanticDiffs traverses the previous semantic tree, noting changed nodes.

func (*Window) Decorate

func (w *Window) Decorate(d mado.Driver, e mado.FrameEvent, o *op.Ops) (size, offset image.Point)

decorate the window if enabled and returns the corresponding Insets.

func (*Window) DestroyGPU

func (w *Window) DestroyGPU()

func (*Window) DriverDefer

func (w *Window) DriverDefer(f func(d mado.Driver))

driverDefer is like Run but can be run from any context. It doesn't wait for f to return.

func (*Window) EffectiveConfig

func (w *Window) EffectiveConfig() mado.Config

func (*Window) FallbackDecorate

func (w *Window) FallbackDecorate() bool

func (*Window) Frame

func (w *Window) Frame(frame *op.Ops, viewport image.Point) error

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. The op.InvalidateCmd command is more efficient for animation.

Invalidate is safe for concurrent use.

func (*Window) NextEvent

func (w *Window) NextEvent() event.Event

NextEvent blocks until an event is received from the window, such as [FrameEvent]. It blocks forever if called after [DestroyEvent] has been returned.

func (*Window) Option

func (w *Window) Option(opts ...mado.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) ProcessEvent

func (w *Window) ProcessEvent(d mado.Driver, e event.Event) bool

func (*Window) ProcessFrame

func (w *Window) ProcessFrame(d mado.Driver)

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], [FrameEvent], [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) SetNextFrame

func (w *Window) SetNextFrame(at time.Time)

func (*Window) Update

func (w *Window) Update(frame *op.Ops)

update the window contents, input operations declare input handlers, and so on. The supplied operations list completely replaces the window state from previous calls.

func (*Window) UpdateAnimation

func (w *Window) UpdateAnimation(d mado.Driver)

func (*Window) UpdateCursor

func (w *Window) UpdateCursor(d mado.Driver)

func (*Window) UpdateSemantics

func (w *Window) UpdateSemantics()

updateSemantics refreshes the semantics tree, the id to node map and the ids of updated nodes.

func (*Window) UpdateState

func (w *Window) UpdateState(d mado.Driver)

func (*Window) ValidateAndProcess

func (w *Window) ValidateAndProcess(d mado.Driver, size image.Point, sync bool, frame *op.Ops, sigChan chan<- struct{}) error

func (*Window) WaitAck

func (w *Window) WaitAck(d mado.Driver)

func (*Window) Wakeup

func (w *Window) Wakeup()

Directories

Path Synopsis
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.
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.

Jump to

Keyboard shortcuts

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