Files
gio/layout/context.go
T
Elias Naur 6027517949 io/input: [API] introduce Source, the interface between a Router and widgets
This change gets rid of the event.Queue interface by replacing it with
input.Source values. Source provides the interface to Router necessary
to implement interface widgets.

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

51 lines
1.2 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
package layout
import (
"time"
"gioui.org/io/input"
"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
// 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
input.Source
*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)
}
// Disabled returns a copy of this context with a disabled Source,
// blocking widgets from changing its state and receiving events.
func (c Context) Disabled() Context {
c.Source = input.Source{}
return c
}