[GH-ISSUE #1073] Undefined Grid AddItem #780

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

Originally created by @piotr-placzek on GitHub (Jan 30, 2025).
Original GitHub issue: https://github.com/rivo/tview/issues/1073

I'm just starting with Go and tview,
I looked at grid.go, NewGrid should return *Grid but sth goes wrong here. I can not add items to grid.
it looks like NewGrid returns *Box instead of *Grid. whats going on here?

package ui

import (
	"github.com/rivo/tview"
)

func newPrimitive(text string) tview.Primitive {
  return tview.NewTextView().
          SetTextAlign(tview.AlignCenter).
          SetText(text)
}

func CreateMainView() {
  leftSideView:= newPrimitive("test")

  mainGrid := tview.NewGrid().
              SetRows(0).
              SetColumns(30, 0).
              SetBorder(true)

  mainGrid.AddItem(leftSideView, 0, 0, 1, 1, 0, 0, true)
	
  if err := tview.NewApplication().SetRoot(mainGrid, true).SetFocus(mainGrid).Run(); err != nil {
		panic(err)
	}
}

$ go run main.go
# github.com/----/----/ui
ui/layout.go:21:12: mainGrid.AddItem undefined (type *tview.Box has no field or method AddItem)

Originally created by @piotr-placzek on GitHub (Jan 30, 2025). Original GitHub issue: https://github.com/rivo/tview/issues/1073 I'm just starting with Go and tview, I looked at grid.go, NewGrid should return *Grid but sth goes wrong here. I can not add items to grid. it looks like NewGrid returns *Box instead of *Grid. whats going on here? ```go package ui import ( "github.com/rivo/tview" ) func newPrimitive(text string) tview.Primitive { return tview.NewTextView(). SetTextAlign(tview.AlignCenter). SetText(text) } func CreateMainView() { leftSideView:= newPrimitive("test") mainGrid := tview.NewGrid(). SetRows(0). SetColumns(30, 0). SetBorder(true) mainGrid.AddItem(leftSideView, 0, 0, 1, 1, 0, 0, true) if err := tview.NewApplication().SetRoot(mainGrid, true).SetFocus(mainGrid).Run(); err != nil { panic(err) } } ``` ``` $ go run main.go # github.com/----/----/ui ui/layout.go:21:12: mainGrid.AddItem undefined (type *tview.Box has no field or method AddItem) ```
kerem closed this issue 2026-03-04 01:07:41 +03:00
Author
Owner

@piotr-placzek commented on GitHub (Jan 30, 2025):

nvm there is typo in SetBorders

<!-- gh-comment-id:2624933471 --> @piotr-placzek commented on GitHub (Jan 30, 2025): nvm there is typo in SetBorders
Author
Owner

@rivo commented on GitHub (Jan 30, 2025):

https://pkg.go.dev/github.com/rivo/tview#hdr-Type_Hierarchy

<!-- gh-comment-id:2625011408 --> @rivo commented on GitHub (Jan 30, 2025): https://pkg.go.dev/github.com/rivo/tview#hdr-Type_Hierarchy
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#780
No description provided.