mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
ui/app: update documentation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+11
-1
@@ -17,7 +17,9 @@ import (
|
|||||||
// method must be called.
|
// method must be called.
|
||||||
type UpdateEvent struct {
|
type UpdateEvent struct {
|
||||||
Config Config
|
Config Config
|
||||||
Size image.Point
|
// Size is the dimensions of the window.
|
||||||
|
Size image.Point
|
||||||
|
// Insets is the insets to apply.
|
||||||
Insets Insets
|
Insets Insets
|
||||||
// Whether this draw is system generated
|
// Whether this draw is system generated
|
||||||
// and needs a complete frame before
|
// and needs a complete frame before
|
||||||
@@ -40,6 +42,8 @@ type Insets struct {
|
|||||||
Top, Bottom, Left, Right ui.Value
|
Top, Bottom, Left, Right ui.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StageEvent is sent whenever the stage of a
|
||||||
|
// Window changes.
|
||||||
type StageEvent struct {
|
type StageEvent struct {
|
||||||
Stage Stage
|
Stage Stage
|
||||||
}
|
}
|
||||||
@@ -51,7 +55,10 @@ type CommandEvent struct {
|
|||||||
Cancel bool
|
Cancel bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stage of a Window.
|
||||||
type Stage uint8
|
type Stage uint8
|
||||||
|
|
||||||
|
// CommandType is the type of a CommandEvent.
|
||||||
type CommandType uint8
|
type CommandType uint8
|
||||||
|
|
||||||
type windowRendezvous struct {
|
type windowRendezvous struct {
|
||||||
@@ -66,7 +73,10 @@ type windowAndOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// StagePaused is the Stage for inactive Windows.
|
||||||
|
// Inactive Windows don't receive UpdateEvents.
|
||||||
StagePaused Stage = iota
|
StagePaused Stage = iota
|
||||||
|
// StateRunning is for active Windows.
|
||||||
StageRunning
|
StageRunning
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+16
-5
@@ -15,12 +15,15 @@ import (
|
|||||||
"gioui.org/ui/system"
|
"gioui.org/ui/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WindowOptions specifies a set of window properties
|
||||||
|
// for creating new Windows.
|
||||||
type WindowOptions struct {
|
type WindowOptions struct {
|
||||||
Width ui.Value
|
Width ui.Value
|
||||||
Height ui.Value
|
Height ui.Value
|
||||||
Title string
|
Title string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Window represents an operating system window.
|
||||||
type Window struct {
|
type Window struct {
|
||||||
driver *window
|
driver *window
|
||||||
lastFrame time.Time
|
lastFrame time.Time
|
||||||
@@ -43,8 +46,8 @@ type Window struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Queue is an input.Queue implementation that distributes
|
// Queue is an input.Queue implementation that distributes
|
||||||
// system input events to the input handlers declared through
|
// system input events to the input handlers declared in the
|
||||||
// Draw.
|
// most recent call to Update.
|
||||||
type Queue struct {
|
type Queue struct {
|
||||||
q iinput.Router
|
q iinput.Router
|
||||||
}
|
}
|
||||||
@@ -72,7 +75,8 @@ var ackEvent input.Event
|
|||||||
// options. The options are hints; the platform is free to
|
// options. The options are hints; the platform is free to
|
||||||
// ignore or adjust them.
|
// ignore or adjust them.
|
||||||
// If the current program is running on iOS and Android,
|
// If the current program is running on iOS and Android,
|
||||||
// NewWindow returns the window previously by the platform.
|
// NewWindow returns the window previously created by the
|
||||||
|
// platform.
|
||||||
func NewWindow(opts *WindowOptions) *Window {
|
func NewWindow(opts *WindowOptions) *Window {
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
opts = &WindowOptions{
|
opts = &WindowOptions{
|
||||||
@@ -96,14 +100,21 @@ func NewWindow(opts *WindowOptions) *Window {
|
|||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Events returns the channel where events are delivered.
|
||||||
func (w *Window) Events() <-chan input.Event {
|
func (w *Window) Events() <-chan input.Event {
|
||||||
return w.out
|
return w.out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Queue returns the Window's event queue. The queue contains
|
||||||
|
// the events received since the last UpdateEvent.
|
||||||
func (w *Window) Queue() *Queue {
|
func (w *Window) Queue() *Queue {
|
||||||
return &w.queue
|
return &w.queue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update updates the Window. Paint operations updates the
|
||||||
|
// window contents, input operations declare input handlers,
|
||||||
|
// and so on. The supplied operations list completely replaces
|
||||||
|
// the window state from previous calls.
|
||||||
func (w *Window) Update(frame *ui.Ops) {
|
func (w *Window) Update(frame *ui.Ops) {
|
||||||
w.frames <- frame
|
w.frames <- frame
|
||||||
}
|
}
|
||||||
@@ -139,8 +150,8 @@ func (w *Window) draw(size image.Point, frame *ui.Ops) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invalidate the current window such that a UpdateEvent will be generated
|
// Invalidate the current window such that a UpdateEvent will be generated
|
||||||
// immediately. If the window is not active, the redraw will trigger
|
// immediately. If the window is inactive, the event is sent when the
|
||||||
// when the window becomes active.
|
// window becomes active.
|
||||||
func (w *Window) Invalidate() {
|
func (w *Window) Invalidate() {
|
||||||
select {
|
select {
|
||||||
case w.invalidates <- struct{}{}:
|
case w.invalidates <- struct{}{}:
|
||||||
|
|||||||
Reference in New Issue
Block a user