From 420633039887a05570ca5e1b1919ecb7c901aa16 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 4 Jun 2020 21:58:45 -0700 Subject: [PATCH] Add Supervisor.GetModal() function --- supervisor.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/supervisor.go b/supervisor.go index 151e122..86f1e6c 100644 --- a/supervisor.go +++ b/supervisor.go @@ -183,7 +183,7 @@ func (s *Supervisor) Loop(ev *event.State) error { if err == ErrStopPropagation || handled { // A widget in the active window has accepted an event. Do not pass // the event also to lower widgets. - return err + return ErrStopPropagation } } @@ -407,6 +407,12 @@ func (s *Supervisor) runWidgetEvents(XY render.Point, ev *event.State, } } + // If there was a modal, return stopPropagation (so callers that manage + // events externally of go/ui can see that a modal intercepted events) + if modal != nil { + return ranEvents, ErrStopPropagation + } + // If a stopPropagation was called, return it up the stack. if stopPropagation { return ranEvents, ErrStopPropagation @@ -510,3 +516,12 @@ func (s *Supervisor) PopModal(w Widget) bool { return false } + +// GetModal returns the modal on the top of the stack, or nil if there is +// no modal on top. +func (s *Supervisor) GetModal() Widget { + if len(s.modals) == 0 { + return nil + } + return s.modals[len(s.modals)-1] +}