commit f3af1138a54960c8c2519792b1e375fb0dbcee5d
parent eda707d087c65e68a589e7567ea4823c0d3e42a6
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date: Sat, 7 Nov 2020 18:47:09 +0800
feat(ux): cancel model with escape key
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/cmd/kanban/main.go b/cmd/kanban/main.go
@@ -23,6 +23,7 @@ import (
"git.sr.ht/~whereswaldon/materials"
"gioui.org/app"
+ "gioui.org/io/key"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
@@ -126,8 +127,6 @@ func (ui *UI) Loop() error {
return event.Err
case system.ClipboardEvent:
fmt.Printf("clipboard: %v\n", event.Text)
- case *system.CommandEvent:
- // TODO: integrate with command events.
case system.FrameEvent:
gtx := layout.NewContext(&ops, event)
ui.Update(gtx)
@@ -141,6 +140,14 @@ func (ui *UI) Loop() error {
// and others are for the devs.
// Currently errors are just printed; not great for windowed applications.
func (ui *UI) Update(gtx C) {
+ for _, event := range gtx.Events(ui) {
+ if k, ok := event.(key.Event); ok {
+ if k.Name == key.NameEscape {
+ ui.Modal = nil
+ ui.TicketForm = TicketForm{}
+ }
+ }
+ }
for ii := range ui.Panels {
panel := &ui.Panels[ii]
if panel.CreateTicket.Clicked() {
@@ -249,6 +256,7 @@ func (ui *UI) Update(gtx C) {
}
func (ui *UI) Layout(gtx C) D {
+ key.InputOp{Tag: ui}.Add(gtx.Ops)
return layout.Stack{}.Layout(
gtx,
layout.Stacked(func(gtx C) D {