[GH-ISSUE #90] List Widget: add setFocus parameter to selected callback #69

Closed
opened 2026-03-04 01:01:38 +03:00 by kerem · 2 comments
Owner

Originally created by @soyking on GitHub (Mar 29, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/90

For a normal scene: select an item in List and jump to other widget.

Currently I have to rewrite InputHandler:

type CustomWidget struct {
        *tview.List
        otherWidget tview.Primitive
}

func (w *CustomWidget) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
	h := w.List.InputHandler()
	return func(event *tcell.EventKey, setFocus func(p tview.Primitive)){
		h(event, setFocus)
		switch key := event.Key(); key {
		case tcell.KeyEnter:
			setFocus(otherWidget)
		}
	}
}

Or any better way to make it? Thanks.

Originally created by @soyking on GitHub (Mar 29, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/90 For a normal scene: select an item in `List` and jump to other widget. Currently I have to rewrite `InputHandler`: ``` type CustomWidget struct { *tview.List otherWidget tview.Primitive } func (w *CustomWidget) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) { h := w.List.InputHandler() return func(event *tcell.EventKey, setFocus func(p tview.Primitive)){ h(event, setFocus) switch key := event.Key(); key { case tcell.KeyEnter: setFocus(otherWidget) } } } ``` Or any better way to make it? Thanks.
kerem closed this issue 2026-03-04 01:01:38 +03:00
Author
Owner

@rivo commented on GitHub (Mar 29, 2018):

The Application class has a public function SetFocus(). That's what you would usually use.

<!-- gh-comment-id:377293935 --> @rivo commented on GitHub (Mar 29, 2018): The `Application` class has a public function [`SetFocus()`](https://godoc.org/github.com/rivo/tview#Application.SetFocus). That's what you would usually use.
Author
Owner

@soyking commented on GitHub (Mar 30, 2018):

Thank you.

<!-- gh-comment-id:377426807 --> @soyking commented on GitHub (Mar 30, 2018): Thank you.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#69
No description provided.