[GH-ISSUE #866] Drawing Primitives at any coords on the screen #629

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

Originally created by @indeed999 on GitHub (Jul 31, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/866

Hi, is it possible to draw any Primitive at any given coords on the screen above the Grid which is set as root?

Fo example I want to draw inputField above the mainGrid

mainGrid.SetRows(1, -1).
		SetColumns(30, -1).
                AddItem(Primitive1, 0, 1, 1, 1, 0, 0, false).
		AddItem(Primitive1, 0, 1, 1, 1, 0, 0, false).
		AddItem(Primitive2, 1, 0, 2, 1, 0, 0, false).
		AddItem(Primitive3, 1, 1, 2, 1, 0, 0, true)

inputField = tview.NewInputField() 


if err := app.SetRoot(mainGrid, true).Run(); err != nil {
		panic(err)
	}	
Originally created by @indeed999 on GitHub (Jul 31, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/866 Hi, is it possible to draw any Primitive at any given coords on the screen above the Grid which is set as root? Fo example I want to draw ```inputField``` above the ```mainGrid``` ```go mainGrid.SetRows(1, -1). SetColumns(30, -1). AddItem(Primitive1, 0, 1, 1, 1, 0, 0, false). AddItem(Primitive1, 0, 1, 1, 1, 0, 0, false). AddItem(Primitive2, 1, 0, 2, 1, 0, 0, false). AddItem(Primitive3, 1, 1, 2, 1, 0, 0, true) inputField = tview.NewInputField() if err := app.SetRoot(mainGrid, true).Run(); err != nil { panic(err) } ```
kerem closed this issue 2026-03-04 01:06:36 +03:00
Author
Owner

@rivo commented on GitHub (Apr 4, 2024):

@indeed999 As @digitallyserviced mentioned, you'll want to use Pages to put primitives on top of each other. And you can always call SetRect() to set a specific screen position. (IMO, it's not necessary to create your own primitive. If you simply want to display an InputField, place it into a "page" and call its SetRect() function.)

From a UI point of view, however, I would suggest not trying to calculate screen positions yourself but rather use Grid or Flex to position the element. For example, the following Wiki page shows how to center a primitive on a page:

https://github.com/rivo/tview/wiki/Modal

This has the advantage that it will work with different screen sizes and you don't even have to know much about the screen yourself.

<!-- gh-comment-id:2037691186 --> @rivo commented on GitHub (Apr 4, 2024): @indeed999 As @digitallyserviced mentioned, you'll want to use `Pages` to put primitives on top of each other. And you can always call `SetRect()` to set a specific screen position. (IMO, it's not necessary to create your own primitive. If you simply want to display an `InputField`, place it into a "page" and call its `SetRect()` function.) From a UI point of view, however, I would suggest not trying to calculate screen positions yourself but rather use `Grid` or `Flex` to position the element. For example, the following Wiki page shows how to center a primitive on a page: https://github.com/rivo/tview/wiki/Modal This has the advantage that it will work with different screen sizes and you don't even have to know much about the screen yourself.
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#629
No description provided.