Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot enable mouse support with views.Application #493

Closed
ghost opened this issue Oct 9, 2021 · 1 comment
Closed

Cannot enable mouse support with views.Application #493

ghost opened this issue Oct 9, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 9, 2021

Correct me if I'm wrong, but it seems that you can't enable mouse support when using views.Application? If I make a simple program with my own screen and event loop, I can receive mouse events perfectly fine... However this example using views.Application will not give the expected output:

package main

import (
    "os"

    "github.com/gdamore/tcell"
    "github.com/gdamore/tcell/views"
)

type Widget struct {
    views.Spacer
}

func (widget *Widget) HandleEvent(event tcell.Event) bool {
    switch event.(type) {
    case *tcell.EventKey:
        panic("Key Event")
    case *tcell.EventMouse:
        panic("Mouse Event")
    }

    return false
}

func Run() int {
    screen, err := tcell.NewScreen()

    if err != nil {
        return 1
    }

    screen.EnableMouse()

    var app views.Application
    app.SetScreen(screen)
    app.SetRootWidget(&Widget{})

    if !screen.HasMouse() {
        panic("No mouse")
    }

    if err := app.Run(); err != nil {
        println(err)
        return 1
    }

    return 0
}

func main() {
    os.Exit(Run())
}

The "Key Event" panic can hit as expected when typing, but the "Mouse Event" cannot be hit by clicking/scrolling. Also screen.HasMouse() is still returning true anyway

Does screen.EnableMouse() need to be called after screen initialization? That's how I was using it in my other tests where I didn't use views.Application.

If that is the case, then it seems that there's the issue that initializing the screen before passing it to Application.SetScreen() seems to break the application, since it also attempts to initialize the screen:

screen.Init()

@ghost
Copy link
Author

ghost commented Oct 11, 2021

Closed with #494

@ghost ghost closed this as completed Oct 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants