Closed
Conversation
Add Application.Set(Get)UnknownEventHandler for handling events that tview does not yet support, such as a mouse event or an user defined event.
2607857 to
5f04651
Compare
Contributor
|
Hi, what would make me hesitate to use this is the fact that "unknown" events aren't well defined and could change in the future, thus breaking compatibility. Instead, it could be raw event for all events, or mouse event just for mouse events. I think I like the idea of a raw event handler, it preprocesses all events, and could allow you to intercept and change behavior; and in this case, to receive mouse events. |
Contributor
|
It's actually fairly easy to do this without making any changes, wrap the Screen and grab the events: type MouseScreen struct {
tcell.Screen
MouseEventHandler func(event *tcell.EventMouse)
}
func (screen *MouseScreen) PollEvent() tcell.Event {
event := screen.Screen.PollEvent()
if mouseEvent, ok := event.(*tcell.EventMouse); ok {
screen.MouseEventHandler(mouseEvent)
}
return event
}Use: app := tview.NewApplication()
tscreen, err := tcell.NewScreen()
if err != nil {
return err
}
screen := &MouseScreen{Screen: tscreen,
MouseEventHandler: func(event *tcell.EventMouse) {
// ... handle mouse event here ...
}}
err = screen.Init()
if err != nil {
return err
}
screen.EnableMouse()
app.SetScreen(screen) |
Merged
Author
|
Thanks @millerlogic, I learned a lot from here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Application.EnableMouse() to enable tcell mouse support.
A limited mouse support is available with #337.