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

Fix issues with DocTabs scrolling #2709

Merged
merged 4 commits into from Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions container/doctabs.go
@@ -1,6 +1,8 @@
package container

import (
"image/color"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/layout"
Expand Down Expand Up @@ -62,7 +64,7 @@ func (t *DocTabs) CreateRenderer() fyne.WidgetRenderer {
buttonCache: make(map[*TabItem]*tabButton),
},
docTabs: t,
scroller: NewScroll(nil),
scroller: NewScroll(&fyne.Container{}),
}
r.action = r.buildAllTabsButton()
r.create = r.buildCreateTabsButton()
Expand Down Expand Up @@ -289,8 +291,8 @@ func (r *docTabsRenderer) buildCreateTabsButton() *widget.Button {
return create
}

func (r *docTabsRenderer) buildTabButtons(count int) *fyne.Container {
buttons := &fyne.Container{}
func (r *docTabsRenderer) buildTabButtons(count int, buttons *fyne.Container) {
buttons.Objects = nil

var iconPos buttonIconPosition
if fyne.CurrentDevice().IsMobile() {
Expand Down Expand Up @@ -335,7 +337,6 @@ func (r *docTabsRenderer) buildTabButtons(count int) *fyne.Container {
button.Refresh()
buttons.Objects = append(buttons.Objects, button)
}
return buttons
}

func (r *docTabsRenderer) scrollToSelected() {
Expand Down Expand Up @@ -363,7 +364,7 @@ func (r *docTabsRenderer) scrollToSelected() {

func (r *docTabsRenderer) updateIndicator(animate bool) {
if r.docTabs.current < 0 {
r.indicator.Hide()
r.indicator.FillColor = color.Transparent
r.indicator.Refresh()
return
}
Expand Down Expand Up @@ -414,7 +415,7 @@ func (r *docTabsRenderer) updateIndicator(animate bool) {
indicatorPos.Y = 0
}
if indicatorSize.Width < 0 || indicatorSize.Height < 0 {
r.indicator.Hide()
r.indicator.FillColor = color.Transparent
r.indicator.Refresh()
return
}
Expand All @@ -441,8 +442,7 @@ func (r *docTabsRenderer) updateCreateTab() {

func (r *docTabsRenderer) updateTabs() {
tabCount := len(r.docTabs.Items)

r.scroller.Content = r.buildTabButtons(tabCount)
r.buildTabButtons(tabCount, r.scroller.Content.(*fyne.Container))

// Set layout of tab bar containing tab buttons and overflow action
if r.docTabs.location == TabLocationLeading || r.docTabs.location == TabLocationTrailing {
Expand Down
19 changes: 14 additions & 5 deletions container/tabs.go
Expand Up @@ -107,6 +107,12 @@ func buildPopUpMenu(t baseTabs, button *widget.Button, items []*fyne.MenuItem) *
popUpPos.X = buttonPos.X + buttonSize.Width - popUpMin.Width
popUpPos.Y = buttonPos.Y - popUpMin.Height
}
if popUpPos.X < 0 {
popUpPos.X = 0
}
if popUpPos.Y < 0 {
popUpPos.Y = 0
}
popUpMenu.ShowAtPosition(popUpPos)
return popUpMenu
}
Expand Down Expand Up @@ -202,9 +208,10 @@ func setItems(t baseTabs, items []*TabItem) {
type baseTabsRenderer struct {
positionAnimation, sizeAnimation *fyne.Animation

lastIndicatorMutex sync.RWMutex
lastIndicatorPos fyne.Position
lastIndicatorSize fyne.Size
lastIndicatorMutex sync.RWMutex
lastIndicatorPos fyne.Position
lastIndicatorSize fyne.Size
lastIndicatorHidden bool

action *widget.Button
bar *fyne.Container
Expand Down Expand Up @@ -301,7 +308,8 @@ func (r *baseTabsRenderer) minSize(t baseTabs) fyne.Size {

func (r *baseTabsRenderer) moveIndicator(pos fyne.Position, siz fyne.Size, animate bool) {
r.lastIndicatorMutex.RLock()
isSameState := r.lastIndicatorPos.Subtract(pos).IsZero() && r.lastIndicatorSize.Subtract(siz).IsZero()
isSameState := r.lastIndicatorPos.Subtract(pos).IsZero() && r.lastIndicatorSize.Subtract(siz).IsZero() &&
r.lastIndicatorHidden == r.indicator.Hidden
r.lastIndicatorMutex.RUnlock()
if isSameState {
return
Expand All @@ -316,7 +324,7 @@ func (r *baseTabsRenderer) moveIndicator(pos fyne.Position, siz fyne.Size, anima
r.sizeAnimation = nil
}

r.indicator.Show()
r.indicator.FillColor = theme.PrimaryColor()
if r.indicator.Position().IsZero() {
r.indicator.Move(pos)
r.indicator.Resize(siz)
Expand All @@ -327,6 +335,7 @@ func (r *baseTabsRenderer) moveIndicator(pos fyne.Position, siz fyne.Size, anima
r.lastIndicatorMutex.Lock()
r.lastIndicatorPos = pos
r.lastIndicatorSize = siz
r.lastIndicatorHidden = r.indicator.Hidden
r.lastIndicatorMutex.Unlock()

if animate {
Expand Down
4 changes: 2 additions & 2 deletions container/testdata/doctabs/desktop/dynamic_appended.xml
Expand Up @@ -7,8 +7,8 @@
<widget size="80x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="64x20">Test1</text>
</widget>
<widget pos="84,0" size="80x36" type="*container.tabButton">
<text bold pos="8,8" size="64x20">Test2</text>
<widget size="0x0" type="*container.tabButton">
<text bold size="0x0">Test2</text>
</widget>
</container>
</widget>
Expand Down
Expand Up @@ -4,8 +4,8 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="80x36" type="*container.tabButton">
<text bold color="primary" pos="8,8" size="64x20">Test2</text>
<widget size="0x0" type="*container.tabButton">
<text bold color="primary" size="0x0">Test2</text>
</widget>
</container>
</widget>
Expand All @@ -18,7 +18,7 @@
</container>
</container>
<rectangle fillColor="shadow" pos="0,36" size="300x4"/>
<rectangle fillColor="primary" pos="0,36" size="80x4"/>
<rectangle fillColor="primary" pos="0,36" size="0x4"/>
<widget pos="0,40" size="300x109" type="*widget.Label">
<text pos="8,8" size="284x20">Text 2</text>
</widget>
Expand Down
Expand Up @@ -32,6 +32,7 @@
</container>
</container>
<rectangle fillColor="shadow" pos="72,0" size="4x36"/>
<rectangle pos="72,0" size="4x36"/>
<widget pos="76,0" size="59x36" type="*widget.Label">
<text pos="8,8" size="43x20">Text 1</text>
</widget>
Expand Down
Expand Up @@ -32,6 +32,7 @@
</container>
</container>
<rectangle fillColor="shadow" pos="59,0" size="4x36"/>
<rectangle pos="0,36" size="19x4"/>
<widget size="59x36" type="*widget.Label">
<text pos="8,8" size="43x20">Text 1</text>
</widget>
Expand Down
16 changes: 8 additions & 8 deletions container/testdata/doctabs/mobile/dynamic_appended.xml
Expand Up @@ -4,16 +4,16 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="128x37" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="120x20">Test1</text>
<widget pos="104,8" size="20x20" type="*container.tabCloseButton">
<widget size="260x37" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="252x20">Test1</text>
<widget pos="236,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize" themed="primary"/>
</widget>
</widget>
<widget pos="132,0" size="128x37" type="*container.tabButton">
<text bold pos="4,8" size="120x20">Test2</text>
<widget pos="104,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize"/>
<widget size="0x0" type="*container.tabButton">
<text bold size="0x0">Test2</text>
<widget size="0x0" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="0x0"/>
</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="128x4"/>
<rectangle fillColor="primary" pos="0,36" size="260x4"/>
<widget pos="0,40" size="300x109" type="*widget.Label">
<text pos="8,8" size="284x20">Text 1</text>
</widget>
Expand Down
Expand Up @@ -4,10 +4,10 @@
<container size="300x36">
<widget size="260x36" type="*widget.Scroll">
<container size="260x36">
<widget size="260x37" type="*container.tabButton">
<text bold color="primary" pos="4,8" size="252x20">Test2</text>
<widget pos="236,8" size="20x20" type="*container.tabCloseButton">
<image rsc="cancelIcon" size="iconInlineSize" themed="primary"/>
<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>
</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="260x4"/>
<rectangle fillColor="primary" pos="0,36" size="0x4"/>
<widget pos="0,40" size="300x109" type="*widget.Label">
<text pos="8,8" size="284x20">Text 2</text>
</widget>
Expand Down