From 0ca05dc12c03b8873d2f22caa6ce4c28988b3886 Mon Sep 17 00:00:00 2001 From: ruanwenfeng Date: Thu, 5 Nov 2020 21:32:19 +0800 Subject: [PATCH 01/11] Update list.go (#1508) This min value is equal to -1 when minimized. and line 192 panic: runtime error: index out of range [-1] --- widget/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget/list.go b/widget/list.go index 3ef376bf35..3a3c7484fe 100644 --- a/widget/list.go +++ b/widget/list.go @@ -182,7 +182,7 @@ func (l *listRenderer) Layout(size fyne.Size) { // Relayout What Is Visible - no scroll change - initial layout or possibly from a resize. l.visibleItemCount = int(math.Ceil(float64(l.scroller.size.Height) / float64(l.list.itemMin.Height+listDividerHeight))) - if l.visibleItemCount == 0 { + if l.visibleItemCount <= 0 { return } min := int(math.Min(float64(length), float64(l.visibleItemCount))) From 57a948988b31253a47ac5033aefd9b697d82c1e8 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 20 Nov 2020 20:14:02 +0000 Subject: [PATCH 02/11] Add date for release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90369e9638..684ffbafd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ This file lists the main changes with each version of the Fyne toolkit. More detailed release notes can be found on the [releases page](https://github.com/fyne-io/fyne/releases). -## 1.4.1 - Ongoing +## 1.4.1 - 20 November 2020 ### Changed From 5af2ba47c14563868979e2158a2140e13a67aca5 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Fri, 18 Dec 2020 17:22:29 +0000 Subject: [PATCH 03/11] Add windows execuables to .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index ba7d439ad7..ddb80f5904 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,10 @@ cmd/fyne/fyne cmd/fyne_demo/fyne_demo cmd/fyne_settings/fyne_settings cmd/hello/hello +cmd/fyne/fyne.exe +cmd/fyne_demo/fyne_demo.exe +cmd/fyne_settings/fyne_settings.exe +cmd/hello/hello.exe ### Tests **/testdata/failed From 39f2a71f6f1cb6cf2a3e1c7527ffb88a0e0446a8 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Fri, 18 Dec 2020 17:23:12 +0000 Subject: [PATCH 04/11] Fix the panic when removing tabs --- widget/tabcontainer.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index c79af51596..d87d868689 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -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() } @@ -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() @@ -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] @@ -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) } From 3c8dde3b9916c107b16ee4383f94cd5de0c201b2 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Fri, 18 Dec 2020 20:14:12 +0000 Subject: [PATCH 05/11] Move selected tab when number of tabs reduce When a tab is deleted, the higher index tabs move down one. If the selected is above the one deleted move it also down one to match the tabs --- widget/tabcontainer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index d87d868689..df4f23b84f 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -122,10 +122,13 @@ 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) } + if c.current > index { + c.setTabIndex(c.current - 1) + } + c.SetItems(append(c.Items[:index], c.Items[index+1:]...)) } // SetItems sets the container’s items and refreshes. From 1b8a3e8c285ab6bc1c59ca5afc562f46ac36d064 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Sat, 19 Dec 2020 14:49:08 +0000 Subject: [PATCH 06/11] Consistant selection behaviour on first tab. NewTabContainer selects the first tab. but Append did not select the first tab. This change makes the behaviour the same for both. Append will now select the first added tab. --- widget/tabcontainer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index df4f23b84f..a124ac3c93 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -80,6 +80,10 @@ func NewTabItemWithIcon(text string, icon fyne.Resource, content fyne.CanvasObje // Append adds a new TabItem to the rightmost side of the tab panel func (c *TabContainer) Append(item *TabItem) { c.SetItems(append(c.Items, item)) + if len(c.Items) == 1 { + // Current is first tab item + c.current = 0 + } } // CreateRenderer is a private method to Fyne which links this widget to its renderer From c620ce4220b5882669731c5e08f674223d23bcb0 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Sun, 20 Dec 2020 12:03:14 +0000 Subject: [PATCH 07/11] Revert "Consistant selection behaviour on first tab." This reverts commit 1b8a3e8c285ab6bc1c59ca5afc562f46ac36d064. --- widget/tabcontainer.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index a124ac3c93..df4f23b84f 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -80,10 +80,6 @@ func NewTabItemWithIcon(text string, icon fyne.Resource, content fyne.CanvasObje // Append adds a new TabItem to the rightmost side of the tab panel func (c *TabContainer) Append(item *TabItem) { c.SetItems(append(c.Items, item)) - if len(c.Items) == 1 { - // Current is first tab item - c.current = 0 - } } // CreateRenderer is a private method to Fyne which links this widget to its renderer From f1f4f012fbb8cc8229ad79155332f4318000c152 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Mon, 21 Dec 2020 10:58:39 +0000 Subject: [PATCH 08/11] Checking to show the changes comented --- widget/tabcontainer.go | 27 ++++++++++++++++----------- widget/tabcontainer_test.go | 11 +++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index df4f23b84f..954531ecb7 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -122,12 +122,12 @@ func (c *TabContainer) Remove(item *TabItem) { // RemoveIndex removes tab by index func (c *TabContainer) RemoveIndex(index int) { - if c.current == index { - c.setTabIndex(-1) - } - if c.current > index { - c.setTabIndex(c.current - 1) - } + // if c.current == index { + // c.setTabIndex(-1) + // } + // if c.current > index { + // c.setTabIndex(c.current - 1) + // } c.SetItems(append(c.Items[:index], c.Items[index+1:]...)) } @@ -135,7 +135,7 @@ func (c *TabContainer) RemoveIndex(index int) { func (c *TabContainer) SetItems(items []*TabItem) { c.Items = items if c.current >= len(c.Items) { - c.setTabIndex(-1) + c.current = -1 } c.Refresh() } @@ -155,10 +155,6 @@ 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() @@ -167,6 +163,15 @@ func (c *TabContainer) setTabIndex(index int) { } } +// func (c *TabContainer) setTabIndex(index int) { +// c.current = index +// c.Refresh() + +// if c.OnChanged != nil { +// c.OnChanged(c.Items[c.current]) +// } +// } + // SetTabLocation sets the location of the tab bar func (c *TabContainer) SetTabLocation(l TabLocation) { c.tabLocation = l diff --git a/widget/tabcontainer_test.go b/widget/tabcontainer_test.go index bb4d3adad9..68606b3e2b 100644 --- a/widget/tabcontainer_test.go +++ b/widget/tabcontainer_test.go @@ -98,3 +98,14 @@ func TestTabContainer_SelectTabIndex(t *testing.T) { assert.Equal(t, 1, tabs.CurrentTabIndex()) assert.Equal(t, tabs.Items[1], selectedTab) } + +func TestTabContainer_RemoveIndex(t *testing.T) { + t.Log("==================================================================================================================") + tabs := widget.NewTabContainer(&widget.TabItem{Text: "Test1", Content: widget.NewLabel("Test1")}) + + tabs.SelectTabIndex(0) + tabs.RemoveIndex(0) + assert.Equal(t, -1, tabs.CurrentTabIndex()) // check deselection and no panic + + t.Log("==================================================================================================================") +} From 02e2a8aa893cd5a4aa76b7d537086f4b370d45ff Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Mon, 21 Dec 2020 11:01:12 +0000 Subject: [PATCH 09/11] Cleaned up comments ready for merge --- widget/tabcontainer.go | 15 --------------- widget/tabcontainer_test.go | 3 --- 2 files changed, 18 deletions(-) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index 954531ecb7..84b1d2b334 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -122,12 +122,6 @@ func (c *TabContainer) Remove(item *TabItem) { // RemoveIndex removes tab by index func (c *TabContainer) RemoveIndex(index int) { - // if c.current == index { - // c.setTabIndex(-1) - // } - // if c.current > index { - // c.setTabIndex(c.current - 1) - // } c.SetItems(append(c.Items[:index], c.Items[index+1:]...)) } @@ -163,15 +157,6 @@ func (c *TabContainer) SelectTabIndex(index int) { } } -// func (c *TabContainer) setTabIndex(index int) { -// c.current = index -// c.Refresh() - -// if c.OnChanged != nil { -// c.OnChanged(c.Items[c.current]) -// } -// } - // SetTabLocation sets the location of the tab bar func (c *TabContainer) SetTabLocation(l TabLocation) { c.tabLocation = l diff --git a/widget/tabcontainer_test.go b/widget/tabcontainer_test.go index 68606b3e2b..1114292836 100644 --- a/widget/tabcontainer_test.go +++ b/widget/tabcontainer_test.go @@ -100,12 +100,9 @@ func TestTabContainer_SelectTabIndex(t *testing.T) { } func TestTabContainer_RemoveIndex(t *testing.T) { - t.Log("==================================================================================================================") tabs := widget.NewTabContainer(&widget.TabItem{Text: "Test1", Content: widget.NewLabel("Test1")}) tabs.SelectTabIndex(0) tabs.RemoveIndex(0) assert.Equal(t, -1, tabs.CurrentTabIndex()) // check deselection and no panic - - t.Log("==================================================================================================================") } From 06b84abf8432ac4008a577c39b788508a370d649 Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Mon, 21 Dec 2020 17:42:56 +0000 Subject: [PATCH 10/11] Update widget/tabcontainer.go Co-authored-by: Stuart Scott --- widget/tabcontainer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widget/tabcontainer.go b/widget/tabcontainer.go index 84b1d2b334..8baff17042 100644 --- a/widget/tabcontainer.go +++ b/widget/tabcontainer.go @@ -128,8 +128,8 @@ func (c *TabContainer) RemoveIndex(index int) { // SetItems sets the container’s items and refreshes. func (c *TabContainer) SetItems(items []*TabItem) { c.Items = items - if c.current >= len(c.Items) { - c.current = -1 + if l := len(c.Items); c.current >= l { + c.current = l - 1 } c.Refresh() } From f6040384579202c434424174a4f69b123b2d532f Mon Sep 17 00:00:00 2001 From: adrianre12 Date: Mon, 21 Dec 2020 19:14:30 +0000 Subject: [PATCH 11/11] Added test for selecting new last tab after removal of last tab --- widget/tabcontainer_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/widget/tabcontainer_test.go b/widget/tabcontainer_test.go index 1114292836..56304f366b 100644 --- a/widget/tabcontainer_test.go +++ b/widget/tabcontainer_test.go @@ -100,7 +100,12 @@ func TestTabContainer_SelectTabIndex(t *testing.T) { } func TestTabContainer_RemoveIndex(t *testing.T) { - tabs := widget.NewTabContainer(&widget.TabItem{Text: "Test1", Content: widget.NewLabel("Test1")}) + tabs := widget.NewTabContainer(&widget.TabItem{Text: "Test1", Content: widget.NewLabel("Test1")}, + &widget.TabItem{Text: "Test2", Content: widget.NewLabel("Test2")}) + + tabs.SelectTabIndex(1) + tabs.RemoveIndex(1) + assert.Equal(t, 0, tabs.CurrentTabIndex()) // check max item selection and no panic tabs.SelectTabIndex(0) tabs.RemoveIndex(0)