Skip to content

Commit

Permalink
use global event filter to close ModalView
Browse files Browse the repository at this point in the history
  • Loading branch information
oligo committed Dec 12, 2024
1 parent 3d9f4c0 commit 1173490
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions view/modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/oligo/gioview/theme"

"gioui.org/io/event"
"gioui.org/io/key"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
Expand Down Expand Up @@ -81,6 +82,23 @@ func (m *ModalView) update(gtx layout.Context) bool {
m.closed = true
}

for {
// Use a global event filter to catch quit events.
// Applications have to be very careful as they may also use global escape
// elsewhere, which causes conflicts.
event, ok := gtx.Event(key.Filter{Name: key.NameEscape})
if !ok {
break
}
ev, ok := event.(key.Event)
if !ok {
continue
}
if ev.Name == key.NameEscape {
m.closed = true
}
}

return m.closed
}

Expand Down

0 comments on commit 1173490

Please sign in to comment.