From 3a31045dc9a82ec9e1b1ce24d5e389b3e2c56225 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Tue, 2 Jun 2020 16:22:33 -0400 Subject: [PATCH] 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 --- layout/context.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/layout/context.go b/layout/context.go index dc35e2ff..009bd1f5 100644 --- a/layout/context.go +++ b/layout/context.go @@ -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 +}