[GH-ISSUE #332] Integer divide by zero when setting proportion of last flex item to 0 #253

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

Originally created by @fajuchem on GitHub (Aug 9, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/332

Hello, I'm using flex as the main window in the app, so what I need to do is hide some of the items of the flex, I archived it setting the the item proportion to 0 so the item became hidden, which works great, except when you try to set the proportion to 0 of the last item added in the flex.

package main

import "github.com/rivo/tview"

func main() {
	app := tview.NewApplication()

	test1 := tview.NewBox().SetBorder(true).SetTitle("test1")
	test2 := tview.NewBox().SetBorder(true).SetTitle("test2")
	test3 := tview.NewBox().SetBorder(true).SetTitle("test3")

	flex := tview.NewFlex().
		AddItem(test1, 0, 0, false).
		AddItem(test2, 0, 1, false).
		// Becase the last item is added with 0 its gonna panic
		// with integer division by zero
		AddItem(test3, 0, 0, false)

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

Same thing happen if you try to resize the last item with:

    flex.ResizeItem(test3, 0, 0)

You gonna get:
panic: runtime error: integer divide by zero [recovered] panic: runtime error: integer divide by zero

Originally created by @fajuchem on GitHub (Aug 9, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/332 Hello, I'm using flex as the main window in the app, so what I need to do is hide some of the items of the flex, I archived it setting the the item proportion to 0 so the item became hidden, which works great, except when you try to set the proportion to 0 of the last item added in the flex. ```golang package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() test1 := tview.NewBox().SetBorder(true).SetTitle("test1") test2 := tview.NewBox().SetBorder(true).SetTitle("test2") test3 := tview.NewBox().SetBorder(true).SetTitle("test3") flex := tview.NewFlex(). AddItem(test1, 0, 0, false). AddItem(test2, 0, 1, false). // Becase the last item is added with 0 its gonna panic // with integer division by zero AddItem(test3, 0, 0, false) if err := app.SetRoot(flex, true).Run(); err != nil { panic(err) } } ``` Same thing happen if you try to resize the last item with: ```golang flex.ResizeItem(test3, 0, 0) ``` You gonna get: ` panic: runtime error: integer divide by zero [recovered] panic: runtime error: integer divide by zero `
kerem closed this issue 2026-03-04 01:03:23 +03:00
Author
Owner

@rivo commented on GitHub (Oct 17, 2019):

Thanks. I added a fix. But I should note that the documentation does not allow this:

The proportion must be at least 1 if fixedSize == 0 (ignored otherwise).

<!-- gh-comment-id:543092208 --> @rivo commented on GitHub (Oct 17, 2019): Thanks. I added a fix. But I should note that the documentation [does not allow this](https://godoc.org/github.com/rivo/tview#Flex.AddItem): > The proportion must be at least 1 if fixedSize == 0 (ignored otherwise).
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#253
No description provided.