From 55cdc84e256998332426db1fccdd05bc058bee67 Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Tue, 3 Mar 2020 16:24:50 +0000 Subject: [PATCH] EnableMouse to take bool and enable/disable directly --- application.go | 13 ++++++++++--- demos/list/main.go | 2 +- demos/presentation/main.go | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/application.go b/application.go index 3ef4e29..14823f3 100644 --- a/application.go +++ b/application.go @@ -155,10 +155,17 @@ func (a *Application) SetScreen(screen tcell.Screen) *Application { } // EnableMouse enables mouse events. -func (a *Application) EnableMouse() *Application { +func (a *Application) EnableMouse(enable bool) *Application { a.Lock() - a.enableMouse = true - a.Unlock() + defer a.Unlock() + if enable != a.enableMouse && a.screen != nil { + if enable { + a.screen.EnableMouse() + } else { + a.screen.DisableMouse() + } + } + a.enableMouse = enable return a } diff --git a/demos/list/main.go b/demos/list/main.go index 3ca90eb..07afa28 100644 --- a/demos/list/main.go +++ b/demos/list/main.go @@ -15,7 +15,7 @@ func main() { AddItem("Quit", "Press to exit", 'q', func() { app.Stop() }) - app.EnableMouse() + app.EnableMouse(true) if err := app.SetRoot(list, true).Run(); err != nil { panic(err) } diff --git a/demos/presentation/main.go b/demos/presentation/main.go index f72687b..1861780 100644 --- a/demos/presentation/main.go +++ b/demos/presentation/main.go @@ -91,7 +91,7 @@ func main() { return event }) - app.EnableMouse() + app.EnableMouse(true) // Start the application. if err := app.SetRoot(layout, true).Run(); err != nil {