EnableMouse to take bool and enable/disable directly

This commit is contained in:
Chris Miller 2020-03-03 16:24:50 +00:00
parent 15700e7129
commit 55cdc84e25
3 changed files with 12 additions and 5 deletions

View File

@ -155,10 +155,17 @@ func (a *Application) SetScreen(screen tcell.Screen) *Application {
} }
// EnableMouse enables mouse events. // EnableMouse enables mouse events.
func (a *Application) EnableMouse() *Application { func (a *Application) EnableMouse(enable bool) *Application {
a.Lock() a.Lock()
a.enableMouse = true defer a.Unlock()
a.Unlock() if enable != a.enableMouse && a.screen != nil {
if enable {
a.screen.EnableMouse()
} else {
a.screen.DisableMouse()
}
}
a.enableMouse = enable
return a return a
} }

View File

@ -15,7 +15,7 @@ func main() {
AddItem("Quit", "Press to exit", 'q', func() { AddItem("Quit", "Press to exit", 'q', func() {
app.Stop() app.Stop()
}) })
app.EnableMouse() app.EnableMouse(true)
if err := app.SetRoot(list, true).Run(); err != nil { if err := app.SetRoot(list, true).Run(); err != nil {
panic(err) panic(err)
} }

View File

@ -91,7 +91,7 @@ func main() {
return event return event
}) })
app.EnableMouse() app.EnableMouse(true)
// Start the application. // Start the application.
if err := app.SetRoot(layout, true).Run(); err != nil { if err := app.SetRoot(layout, true).Run(); err != nil {