Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer divide by zero when setting proportion of last flex item to 0 #332

Closed
fajuchem opened this issue Aug 9, 2019 · 1 comment
Closed

Comments

@fajuchem
Copy link

fajuchem commented Aug 9, 2019

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

natemago added a commit to natemago/tview that referenced this issue Aug 19, 2019
In the rare case when all items have proportion 0, then the size of the
flex is also zero.

This fixes rivo#332.
@rivo rivo closed this as completed in de7ae86 Oct 17, 2019
@rivo
Copy link
Owner

rivo commented 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants