Skip to content

Commit

Permalink
Fix the panic when removing tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianre12 committed Dec 18, 2020
1 parent 5af2ba4 commit 39f2a71
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions widget/tabcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ func (c *TabContainer) Remove(item *TabItem) {
// RemoveIndex removes tab by index
func (c *TabContainer) RemoveIndex(index int) {
c.SetItems(append(c.Items[:index], c.Items[index+1:]...))
if c.current == index {
c.setTabIndex(-1)
}
}

// SetItems sets the container’s items and refreshes.
func (c *TabContainer) SetItems(items []*TabItem) {
c.Items = items
if c.current >= len(c.Items) {
c.setTabIndex(-1)
}
c.Refresh()
}

Expand All @@ -146,7 +152,10 @@ func (c *TabContainer) SelectTabIndex(index int) {
if index < 0 || index >= len(c.Items) || c.current == index {
return
}
c.setTabIndex(index)
}

func (c *TabContainer) setTabIndex(index int) {
c.current = index
c.Refresh()

Expand Down Expand Up @@ -360,6 +369,7 @@ func (r *tabContainerRenderer) buildTabBar(buttons []fyne.CanvasObject) *fyne.Co

func (r *tabContainerRenderer) moveSelection() {
if r.container.current < 0 {
r.underline.Hide()
return
}
selected := r.tabBar.Objects[r.container.current]
Expand All @@ -380,6 +390,7 @@ func (r *tabContainerRenderer) moveSelection() {
underlinePos = fyne.NewPos(r.tabBar.Position().X-theme.Padding(), selected.Position().Y)
underlineSize = fyne.NewSize(theme.Padding(), selected.Size().Height)
}
r.underline.Show()
r.underline.Resize(underlineSize)
r.underline.Move(underlinePos)
}
Expand Down

0 comments on commit 39f2a71

Please sign in to comment.