mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
fff2375470
The fix for #605 moved the disabling of event delivery from Source to Context to enable disabled Contexts to still react to commands (invalidate, focus etc.). However, that change in turn caused #641 where the exported Context.Source field would no longer know not to deliver events. This change partially reverts the fix for #605 by moving disabledness back to Source, fixing #641. Disabled Sources are left capable of executing commands, thus keeping #605 fixed. Thanks to Chris et al for keeping the use-cases straight enough for me to come up with this (hopefully final) fix. Signed-off-by: Elias Naur <mail@eliasnaur.com> Fixes: https://todo.sr.ht/~eliasnaur/gio/641 References: https://todo.sr.ht/~eliasnaur/gio/605
50 lines
1.1 KiB
Go
50 lines
1.1 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 that don't deliver any events.
|
|
func (c Context) Disabled() Context {
|
|
c.Source = c.Source.Disabled()
|
|
return c
|
|
}
|