Skip to content

Commit

Permalink
Merge pull request #4052 from andydotxyz/fix/3905
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Jul 22, 2023
2 parents 2f9133e + 53f4c07 commit 4a0f231
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 20 deletions.
5 changes: 5 additions & 0 deletions container/doctabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ func (r *docTabsRenderer) Layout(size fyne.Size) {
r.updateCreateTab()
r.updateTabs()
r.layout(r.docTabs, size)

// lay out buttons before updating indicator, which is relative to their position
buttons := r.scroller.Content.(*fyne.Container)
buttons.Layout.Layout(buttons.Objects, buttons.Size())
r.updateIndicator(r.docTabs.transitioning())

if r.docTabs.transitioning() {
r.docTabs.setTransitioning(false)
}
Expand Down
16 changes: 16 additions & 0 deletions container/doctabs_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ func TestDocTabs_tabButtonRenderer_SetText(t *testing.T) {
renderer = cache.Renderer(button).(*tabButtonRenderer)
assert.Equal(t, "Replace", renderer.label.Text)
}

func TestDocTabs_tabButtonRenderer_Remove(t *testing.T) {
items := []*TabItem{{Text: "1", Content: widget.NewLabel("Content1")},
{Text: "2", Content: widget.NewLabel("Content2")},
{Text: "3", Content: widget.NewLabel("Content3")}}
tabs := NewDocTabs(items...)
tabs.Resize(fyne.NewSize(160, 160))
tabRenderer := cache.Renderer(tabs).(*docTabsRenderer)

tabs.SelectIndex(1)
pos := tabRenderer.indicator.Position()
tabs.RemoveIndex(0)
assert.Equal(t, 0, tabs.SelectedIndex())

assert.Less(t, tabRenderer.indicator.Position().X, pos.X)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<container size="500x36">
<widget size="460x36" type="*widget.Scroll">
<container size="460x36">
<widget size="83x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="67x20">New longer text 1</text>
<widget size="164x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="148x20">New longer text 1</text>
</widget>
<widget pos="87,0" size="83x36" type="*container.tabButton">
<widget pos="168,0" size="83x36" type="*container.tabButton">
<text bold pos="8,8" size="67x20">New 2</text>
</widget>
</container>
Expand Down
4 changes: 2 additions & 2 deletions container/testdata/doctabs/desktop/dynamic_appended.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<widget size="76x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="60x20">Test1</text>
</widget>
<widget size="0x0" type="*container.tabButton">
<text bold size="0x0">Test2</text>
<widget pos="80,0" size="76x36" type="*container.tabButton">
<text bold pos="8,8" size="60x20">Test2</text>
</widget>
</container>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="0x0" type="*container.tabButton">
<text bold color="primary" size="0x0">Test2</text>
<widget size="76x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="60x20">Test2</text>
</widget>
</container>
</widget>
Expand Down
16 changes: 8 additions & 8 deletions container/testdata/doctabs/mobile/dynamic_appended.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="260x36" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="252x19">Test1</text>
<widget pos="236,8" size="20x20" type="*container.tabCloseButton">
<widget size="128x36" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="120x19">Test1</text>
<widget pos="104,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize" themed="primary"/>
</widget>
</widget>
<widget size="0x0" type="*container.tabButton">
<text bold size="0x0">Test2</text>
<widget size="0x0" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="0x0"/>
<widget pos="132,0" size="128x36" type="*container.tabButton">
<text bold pos="4,8" size="120x19">Test2</text>
<widget pos="104,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize"/>
</widget>
</widget>
</container>
Expand All @@ -27,7 +27,7 @@
</container>
</container>
<rectangle fillColor="shadow" pos="0,36" size="300x4"/>
<rectangle fillColor="primary" pos="0,36" size="260x4"/>
<rectangle fillColor="primary" pos="0,36" size="128x4"/>
<widget pos="0,40" size="300x110" type="*widget.Label">
<text pos="8,8" size="38x19">Text 1</text>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="0x0" type="*container.tabButton">
<text bold color="primary" size="0x0">Test2</text>
<widget size="0x0" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="0x0" themed="primary"/>
<widget size="260x36" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="252x19">Test2</text>
<widget pos="236,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize" themed="primary"/>
</widget>
</widget>
</container>
Expand All @@ -21,7 +21,7 @@
</container>
</container>
<rectangle fillColor="shadow" pos="0,36" size="300x4"/>
<rectangle fillColor="primary" pos="0,36" size="72x4"/>
<rectangle fillColor="primary" pos="0,36" size="260x4"/>
<widget pos="0,40" size="300x110" type="*widget.Label">
<text pos="8,8" size="38x19">Text 2</text>
</widget>
Expand Down

0 comments on commit 4a0f231

Please sign in to comment.