Files
gio/layout/context.go
T
Elias Naur 4fcd96ac4b layout,app: [API] rename FrameEvent.Queue and Context.Queue to Source
We're about to replace the interface Queue with a concrete input.Source.
This change renames the field accordingly.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2024-02-05 10:59:51 +00:00

65 lines
1.6 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
package layout
import (
"time"
"gioui.org/io/event"
"gioui.org/io/system"
"gioui.org/op"
"gioui.org/unit"
)
// Context carries the state needed by almost all layouts and widgets.
// A zero value Context never returns events, map units to pixels
// with a scale of 1.0, and returns the zero time from Now.
type Context struct {
// Constraints track the constraints for the active widget or
// layout.
Constraints Constraints
Metric unit.Metric
// By convention, a nil Source is a signal to widgets to draw themselves
// in a disabled state.
Source event.Queue
// Now is the animation time.
Now time.Time
// Locale provides information on the system's language preferences.
// BUG(whereswaldon): this field is not currently populated automatically.
// Interested users must look up and populate these values manually.
Locale system.Locale
*op.Ops
}
// Dp converts v to pixels.
func (c Context) Dp(v unit.Dp) int {
return c.Metric.Dp(v)
}
// Sp converts v to pixels.
func (c Context) Sp(v unit.Sp) int {
return c.Metric.Sp(v)
}
// Events returns the events available for the key. If no
// queue is configured, Events returns nil.
func (c Context) Events(k event.Tag) []event.Event {
if c.Source == nil {
return nil
}
return c.Source.Events(k)
}
// Disabled returns a copy of this context with a nil Queue,
// blocking events to widgets using it.
//
// By convention, a nil Queue is a signal to widgets to draw themselves
// in a disabled state.
func (c Context) Disabled() Context {
c.Source = nil
return c
}