forked from joejulian/gio
layout,io/input: move disabling events from layout.Context to input.Source
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
This commit is contained in:
+1
-16
@@ -5,7 +5,6 @@ package layout
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/input"
|
||||
"gioui.org/io/system"
|
||||
"gioui.org/op"
|
||||
@@ -29,7 +28,6 @@ type Context struct {
|
||||
// Interested users must look up and populate these values manually.
|
||||
Locale system.Locale
|
||||
|
||||
disabled bool
|
||||
input.Source
|
||||
*op.Ops
|
||||
}
|
||||
@@ -44,21 +42,8 @@ func (c Context) Sp(v unit.Sp) int {
|
||||
return c.Metric.Sp(v)
|
||||
}
|
||||
|
||||
func (c Context) Event(filters ...event.Filter) (event.Event, bool) {
|
||||
if c.disabled {
|
||||
return nil, false
|
||||
}
|
||||
return c.Source.Event(filters...)
|
||||
}
|
||||
|
||||
// Enabled reports whether this context is enabled. Disabled contexts
|
||||
// don't report events.
|
||||
func (c Context) Enabled() bool {
|
||||
return !c.disabled
|
||||
}
|
||||
|
||||
// Disabled returns a copy of this context that don't deliver any events.
|
||||
func (c Context) Disabled() Context {
|
||||
c.disabled = true
|
||||
c.Source = c.Source.Disabled()
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user