Skip to content

Commit

Permalink
Fix bugs with appTabs render (#3983)
Browse files Browse the repository at this point in the history
Fixes #3980
  • Loading branch information
spxvszero authored Jul 2, 2023
1 parent 07d3354 commit 778dfc2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
28 changes: 16 additions & 12 deletions container/apptabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,22 @@ type appTabsRenderer struct {

func (r *appTabsRenderer) Layout(size fyne.Size) {
// Try render as many tabs as will fit, others will appear in the overflow
for i := len(r.appTabs.Items); i > 0; i-- {
r.updateTabs(i)
barMin := r.bar.MinSize()
if r.appTabs.location == TabLocationLeading || r.appTabs.location == TabLocationTrailing {
if barMin.Height <= size.Height {
// Tab bar is short enough to fit
break
}
} else {
if barMin.Width <= size.Width {
// Tab bar is thin enough to fit
break
if len(r.appTabs.Items) == 0 {
r.updateTabs(0)
} else {
for i := len(r.appTabs.Items); i > 0; i-- {
r.updateTabs(i)
barMin := r.bar.MinSize()
if r.appTabs.location == TabLocationLeading || r.appTabs.location == TabLocationTrailing {
if barMin.Height <= size.Height {
// Tab bar is short enough to fit
break
}
} else {
if barMin.Width <= size.Width {
// Tab bar is thin enough to fit
break
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions container/apptabs_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@ func Test_tabButtonRenderer_DeleteAdd(t *testing.T) {
tabs.SelectTab(item2)
assert.Equal(t, pos, indicator.Position())
}

func Test_tabButtonRenderer_EmptyDeleteAdd(t *testing.T) {
item1 := &TabItem{Text: "Test", Content: widget.NewLabel("Content")}
tabs := NewAppTabs()

// ensure enough space for buttons to be created.
tabs.Resize(fyne.NewSize(300, 200))

tabRenderer := cache.Renderer(tabs).(*appTabsRenderer)
assert.Equal(t, 0, len(tabRenderer.bar.Objects[0].(*fyne.Container).Objects))

tabs.Append(item1)
assert.Equal(t, 1, len(tabRenderer.bar.Objects[0].(*fyne.Container).Objects))

tabs.Remove(item1)
assert.Equal(t, 0, len(tabRenderer.bar.Objects[0].(*fyne.Container).Objects))
}

0 comments on commit 778dfc2

Please sign in to comment.