[GH-ISSUE #48] Problem with Flex horizontal size #36

Closed
opened 2026-03-04 01:01:17 +03:00 by kerem · 3 comments
Owner

Originally created by @genzi on GitHub (Jan 29, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/48

display = tview.NewTable()

	cols, rows := 64, 32
	for r := 0; r < rows; r++ {
		for c := 0; c < cols; c++ {
			display.SetCell(r, c, tview.NewTableCell("|"))
		}
	}
	display.SetBorder(true).SetTitle("Display").SetRect(1, 1, 66, 34)

	flexF1 = tview.NewFlex().
		AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
			AddItem(display, 32+2, 1, false).
			AddItem(tview.NewTextView().SetBorder(true), 0, 1, false), 64+2, 1, false).
		AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
			AddItem(tview.NewBox().SetBorder(true), 0, 1, false).
			AddItem(tview.NewList().SetBorder(true), 0, 1, false), 0, 1, false)

	if err := app.SetRoot(flexF1, true).Run(); err != nil {
		panic(err)
	}

I want to use a table like kind of display. To visualize something I will call display.GetCell(px, py).SetBackgroundColor(tcell.ColorGreen) function when pixel should be on.
The code above should make "display" 64 x 32. Vertical size is OK (32; +2 for border), but horizontal size is less than 64.

Originally created by @genzi on GitHub (Jan 29, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/48 ``` display = tview.NewTable() cols, rows := 64, 32 for r := 0; r < rows; r++ { for c := 0; c < cols; c++ { display.SetCell(r, c, tview.NewTableCell("|")) } } display.SetBorder(true).SetTitle("Display").SetRect(1, 1, 66, 34) flexF1 = tview.NewFlex(). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(display, 32+2, 1, false). AddItem(tview.NewTextView().SetBorder(true), 0, 1, false), 64+2, 1, false). AddItem(tview.NewFlex().SetDirection(tview.FlexRow). AddItem(tview.NewBox().SetBorder(true), 0, 1, false). AddItem(tview.NewList().SetBorder(true), 0, 1, false), 0, 1, false) if err := app.SetRoot(flexF1, true).Run(); err != nil { panic(err) } ``` I want to use a table like kind of display. To visualize something I will call display.GetCell(px, py).SetBackgroundColor(tcell.ColorGreen) function when pixel should be on. The code above should make "display" 64 x 32. Vertical size is OK (32; +2 for border), but horizontal size is less than 64.
kerem closed this issue 2026-03-04 01:01:18 +03:00
Author
Owner

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

Hi,

You're correctly setting the required width to 64+2 in the Flex view. (The SetRect() call is not needed.) When I tried your example, the width of display got set to 64 or 66 with the border. See here:

image

I'm counting 32 vertical bars with one blank cell after each one = 64.

If you're getting a different output for this code, maybe you can include a screenshot.

<!-- gh-comment-id:361500739 --> @rivo commented on GitHub (Jan 30, 2018): Hi, You're correctly setting the required width to `64+2` in the `Flex` view. (The `SetRect()` call is not needed.) When I tried your example, the width of `display` got set to 64 or 66 with the border. See here: ![image](https://user-images.githubusercontent.com/480930/35553204-26f5bbec-0597-11e8-9ecd-366c2aca131d.png) I'm counting 32 vertical bars with one blank cell after each one = 64. If you're getting a different output for this code, maybe you can include a screenshot.
Author
Owner

@genzi commented on GitHub (Jan 30, 2018):

Hi,
Thank you for the answer. I didn't know that in a table there is additional blank cell after each one.
I that case I should set flex fixedSize to 128. I will try it in that way.
I know that this is "table" not "display" object, but is there a way to remove blank cells?
Because this breaks my "display" probably. Or can you suggest a different way to reach my goal?
Sorry for questions about not standard use your package.

<!-- gh-comment-id:361513650 --> @genzi commented on GitHub (Jan 30, 2018): Hi, Thank you for the answer. I didn't know that in a table there is additional blank cell after each one. I that case I should set flex fixedSize to 128. I will try it in that way. I know that this is "table" not "display" object, but is there a way to remove blank cells? Because this breaks my "display" probably. Or can you suggest a different way to reach my goal? Sorry for questions about not standard use your package.
Author
Owner

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

Currently, the character between columns cannot be removed. But you can change it to something else than a blank character with SetSeparator():

table.SetSeparator('|')

If you don't need the other Table functionality such as scrolling and selections, I would suggest using TextView instead. Just draw your bars into it:

textView := tview.NewTextView()
for row := 0; row < 32; row++ {
  fmt.Fprintln(textView, strings.Repeat("|", 64))
}

You can change colors like this:

textView := tview.NewTextView().SetDynamicColors(true)
// ...
textView.Clear()
fmt.Fprint(textView, "[red]")
for row := 0; row < 32; row++ {
  fmt.Fprintln(textView, strings.Repeat("|", 64))
}

or like this:

textView := tview.NewTextView().SetTextColor(tcell.ColorRed)
for row := 0; row < 32; row++ {
  fmt.Fprintln(textView, strings.Repeat("|", 64))
}
<!-- gh-comment-id:361523277 --> @rivo commented on GitHub (Jan 30, 2018): Currently, the character between columns cannot be removed. But you can change it to something else than a blank character with [`SetSeparator()`](https://godoc.org/github.com/rivo/tview#Table.SetSeparator): ```go table.SetSeparator('|') ``` If you don't need the other `Table` functionality such as scrolling and selections, I would suggest using `TextView` instead. Just draw your bars into it: ```go textView := tview.NewTextView() for row := 0; row < 32; row++ { fmt.Fprintln(textView, strings.Repeat("|", 64)) } ``` You can change colors like this: ```go textView := tview.NewTextView().SetDynamicColors(true) // ... textView.Clear() fmt.Fprint(textView, "[red]") for row := 0; row < 32; row++ { fmt.Fprintln(textView, strings.Repeat("|", 64)) } ``` or like this: ```go textView := tview.NewTextView().SetTextColor(tcell.ColorRed) for row := 0; row < 32; row++ { fmt.Fprintln(textView, strings.Repeat("|", 64)) } ```
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#36
No description provided.