layout: add Disabled method to Context

This adds a simple method that returns a copy of the Context
with no event queue. Widgets laid out with this Context will
never receive events, and can check whether the event queue
is nil as a hint for whether or not to draw themselves as
disabled.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2020-06-02 16:22:33 -04:00
committed by Elias Naur
parent d280d438c7
commit 3a31045dc9
+13 -1
View File
@@ -22,7 +22,9 @@ type Context struct {
Constraints Constraints
Config system.Config
Queue event.Queue
// By convention, a nil Queue is a signal to widgets to draw themselves
// in a disabled state.
Queue event.Queue
*op.Ops
}
@@ -71,3 +73,13 @@ func (c Context) Events(k event.Tag) []event.Event {
}
return c.Queue.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.Queue = nil
return c
}