[GH-ISSUE #714] NewList() doesn't render elements when cast as primitive in grid AddItem() #522

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

Originally created by @ivdok on GitHub (Mar 17, 2022).
Original GitHub issue: https://github.com/rivo/tview/issues/714

Related to #713 . Consider the following:

func main() {
	newPrimitive := func(text string) tview.Primitive {
		return tview.NewTextView().
			SetTextAlign(tview.AlignCenter).
			SetText(text)
	}
	main := tview.NewList(). //column 2
					ShowSecondaryText(true).
					SetTitle("Parameters")
	menu := tview.NewList(). //column 1
					ShowSecondaryText(true).
					AddItem("1", "Example", 1, nil).
					AddItem("2", "Example", 2, nil).
					AddItem("3", "Example", 3, nil).
					AddItem("4", "Example", 4, nil).
					AddItem("5", "Example", 'q', func() {
			app.Stop()
		}).
		SetSelectedFunc(func(i int, s1, s2 string, r rune) {
			// values.Clear()
		}).
		SetBorder(true).
		SetTitle("Category")

	grid := tview.NewGrid().
		SetRows(3, 0, 3).
		SetColumns(30, 0).
		SetBorders(true).
		AddItem(newPrimitive("Header"), 0, 0, 1, 3, 0, 0, false).
		AddItem(newPrimitive("Footer"), 2, 0, 1, 3, 0, 0, false)

	// Layout for screens narrower than 100 cells (menu and side bar are hidden).
	grid.AddItem(menu, 0, 0, 0, 0, 0, 0, true).
		AddItem(main, 1, 0, 1, 3, 0, 0, false)

	// Layout for screens wider than 100 cells.
	grid.AddItem(menu, 1, 0, 1, 1, 0, 100, true).
		AddItem(main, 1, 1, 1, 2, 0, 100, false)

	if err := tview.NewApplication().SetRoot(grid, true).SetFocus(grid).Run(); err != nil {
		panic(err)
	}
}

There are several issues here:

  1. Both lists are not rendered.
  2. While newPrimitive() draws the text, I can't get title drawn for "menu" or "main" primitive without ugly extra setBorder().
  3. Focus is ignored for AddItem(), therefore I can't exit by invoking 'q' key as defined in "menu" primitive.
  4. It is unclear from the comments in example why do we need multiple AddItem() invocations, what do they do internally, what happens when they overlap and how to debug them. Overall the examples are WAY too terse on comments and meanings behind function calls.
Originally created by @ivdok on GitHub (Mar 17, 2022). Original GitHub issue: https://github.com/rivo/tview/issues/714 Related to #713 . Consider the following: ``` func main() { newPrimitive := func(text string) tview.Primitive { return tview.NewTextView(). SetTextAlign(tview.AlignCenter). SetText(text) } main := tview.NewList(). //column 2 ShowSecondaryText(true). SetTitle("Parameters") menu := tview.NewList(). //column 1 ShowSecondaryText(true). AddItem("1", "Example", 1, nil). AddItem("2", "Example", 2, nil). AddItem("3", "Example", 3, nil). AddItem("4", "Example", 4, nil). AddItem("5", "Example", 'q', func() { app.Stop() }). SetSelectedFunc(func(i int, s1, s2 string, r rune) { // values.Clear() }). SetBorder(true). SetTitle("Category") grid := tview.NewGrid(). SetRows(3, 0, 3). SetColumns(30, 0). SetBorders(true). AddItem(newPrimitive("Header"), 0, 0, 1, 3, 0, 0, false). AddItem(newPrimitive("Footer"), 2, 0, 1, 3, 0, 0, false) // Layout for screens narrower than 100 cells (menu and side bar are hidden). grid.AddItem(menu, 0, 0, 0, 0, 0, 0, true). AddItem(main, 1, 0, 1, 3, 0, 0, false) // Layout for screens wider than 100 cells. grid.AddItem(menu, 1, 0, 1, 1, 0, 100, true). AddItem(main, 1, 1, 1, 2, 0, 100, false) if err := tview.NewApplication().SetRoot(grid, true).SetFocus(grid).Run(); err != nil { panic(err) } } ``` There are several issues here: 1. Both lists are not rendered. 2. While newPrimitive() draws the text, I can't get title drawn for "menu" or "main" primitive without ugly extra setBorder(). 3. Focus is ignored for AddItem(), therefore I can't exit by invoking 'q' key as defined in "menu" primitive. 4. It is unclear from the comments in example why do we need multiple AddItem() invocations, what do they do internally, what happens when they overlap and how to debug them. Overall the examples are WAY too terse on comments and meanings behind function calls.
kerem closed this issue 2026-03-04 01:05:42 +03:00
Author
Owner

@rivo commented on GitHub (Apr 15, 2022):

Please check if my reply to #713 helps you with this one, too.

<!-- gh-comment-id:1100275799 --> @rivo commented on GitHub (Apr 15, 2022): Please check if my reply to #713 helps you with this one, too.
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#522
No description provided.