[GH-ISSUE #989] Manual scrolling in Grid #716

Closed
opened 2026-03-04 01:07:14 +03:00 by kerem · 1 comment
Owner

Originally created by @mkozjak on GitHub (May 21, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/989

Thanks for this amazing project.

I have a question regarding Grid and grid.SetOffset method. Should I be "redrawing" my screen after setting the offset value via grid.SetOffset?

I have a flex app that consists of two items split vertically - A list and a grid. I switch between these using Application.SetFocus in my Application.SetInputCapture callback.

Grid consists of multiple Lists, where the first one is automatically focused when set via Grid.AddItem. This item captures the 'j' key in order to select the next list item, as shown in this excerpt:

trackLst.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
	switch event.Rune() {
	case 'j':
		if trackLst.GetCurrentItem()+1 == trackLst.GetItemCount() {
			// skip to the next album if available
			if a.currentAlbumIndex+1 == a.currentAlbumCount {
				// do nothing, return default, because this is the last album
				return nil
			} else {
				c.SetOffset(a.currentAlbumIndex+1, 0)
				// FIXME: still need to somehow redraw the screen?
				a.currentAlbumIndex = a.currentAlbumIndex + 1

				return tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone)
			}
		}

		return tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone)
	}

	return event

I am 100% sure c.SetOffset works and the provided parameter to it is correct since after I switch back from a Grid root element to my List root element (via Tab) it scrolls itself to only show me the needed Grid element.

App preview:
image

Should grid.SetOffset be refreshing this app portion automatically or should I be doing something in addition?

Thanks!

Originally created by @mkozjak on GitHub (May 21, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/989 Thanks for this amazing project. I have a question regarding Grid and grid.SetOffset method. Should I be "redrawing" my screen after setting the offset value via `grid.SetOffset`? I have a flex app that consists of two items split vertically - A list and a grid. I switch between these using `Application.SetFocus` in my `Application.SetInputCapture` callback. Grid consists of multiple Lists, where the first one is automatically focused when set via `Grid.AddItem`. This item captures the 'j' key in order to select the next list item, as shown in this excerpt: ``` trackLst.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Rune() { case 'j': if trackLst.GetCurrentItem()+1 == trackLst.GetItemCount() { // skip to the next album if available if a.currentAlbumIndex+1 == a.currentAlbumCount { // do nothing, return default, because this is the last album return nil } else { c.SetOffset(a.currentAlbumIndex+1, 0) // FIXME: still need to somehow redraw the screen? a.currentAlbumIndex = a.currentAlbumIndex + 1 return tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone) } } return tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone) } return event ``` I am 100% sure `c.SetOffset` works and the provided parameter to it is correct since after I switch back from a Grid _root_ element to my List _root_ element (via Tab) it _scrolls_ itself to only show me the needed Grid element. App preview: <img width="882" alt="image" src="https://github.com/rivo/tview/assets/3506172/5fdff7c8-6667-47bf-99f5-b5f7d152c739"> Should `grid.SetOffset` be refreshing this app portion automatically or should I be doing something in addition? Thanks!
kerem closed this issue 2026-03-04 01:07:14 +03:00
Author
Owner

@mkozjak commented on GitHub (May 22, 2024):

I managed to mitigate this using Application.SetFocus giving it the primitive I want to focus, a next List instance.
Thanks!

<!-- gh-comment-id:2124233021 --> @mkozjak commented on GitHub (May 22, 2024): I managed to mitigate this using Application.SetFocus giving it the primitive I want to focus, a next List instance. Thanks!
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#716
No description provided.