diff --git a/container/apptabs.go b/container/apptabs.go
index 94dabd8b52..dbaee14b23 100644
--- a/container/apptabs.go
+++ b/container/apptabs.go
@@ -181,19 +181,7 @@ func (t *AppTabs) SetItems(items []*TabItem) {
// SetTabLocation sets the location of the tab bar
func (t *AppTabs) SetTabLocation(l TabLocation) {
- // Mobile has limited screen space, so don't put app tab bar on long edges
- if d := fyne.CurrentDevice(); d.IsMobile() {
- if o := d.Orientation(); fyne.IsVertical(o) {
- if l == TabLocationLeading || l == TabLocationTrailing {
- l = TabLocationBottom
- }
- } else {
- if l == TabLocationTop || l == TabLocationBottom {
- l = TabLocationLeading
- }
- }
- }
- t.location = l
+ t.location = tabsAdjustedLocation(l)
t.Refresh()
}
@@ -320,7 +308,11 @@ func (r *appTabsRenderer) buildTabButtons(count int) *fyne.Container {
if cells == 0 {
cells = 1
}
- buttons.Layout = layout.NewGridLayout(cells)
+ if r.appTabs.location == TabLocationTop || r.appTabs.location == TabLocationBottom {
+ buttons.Layout = layout.NewGridLayoutWithColumns(cells)
+ } else {
+ buttons.Layout = layout.NewGridLayoutWithRows(cells)
+ }
iconPos = buttonIconTop
} else if r.appTabs.location == TabLocationLeading || r.appTabs.location == TabLocationTrailing {
buttons.Layout = layout.NewVBoxLayout()
diff --git a/container/apptabs_mobile_test.go b/container/apptabs_mobile_test.go
index e96611f28e..67aed3cb71 100644
--- a/container/apptabs_mobile_test.go
+++ b/container/apptabs_mobile_test.go
@@ -232,25 +232,25 @@ func TestAppTabs_Layout(t *testing.T) {
name: "bottom: tab with icon only",
item: container.NewTabItemWithIcon("", theme.InfoIcon(), canvas.NewCircle(theme.BackgroundColor())),
location: container.TabLocationBottom,
- want: "apptabs/mobile/layout_bottom_ico.xml",
+ want: "apptabs/mobile/layout_bottom_icon.xml",
},
{
name: "leading: tab with icon and text",
item: container.NewTabItemWithIcon("Text1", theme.CancelIcon(), canvas.NewCircle(theme.BackgroundColor())),
location: container.TabLocationLeading,
- want: "apptabs/mobile/layout_bottom_icon_and_text.xml",
+ want: "apptabs/mobile/layout_top_icon_and_text.xml",
},
{
name: "leading: tab with text only",
item: container.NewTabItem("Text2", canvas.NewCircle(theme.BackgroundColor())),
location: container.TabLocationLeading,
- want: "apptabs/mobile/layout_bottom_text.xml",
+ want: "apptabs/mobile/layout_top_text.xml",
},
{
name: "leading: tab with icon only",
item: container.NewTabItemWithIcon("", theme.InfoIcon(), canvas.NewCircle(theme.BackgroundColor())),
location: container.TabLocationLeading,
- want: "apptabs/mobile/layout_bottom_icon.xml",
+ want: "apptabs/mobile/layout_top_icon.xml",
},
{
name: "trailing: tab with icon and text",
@@ -301,7 +301,7 @@ func TestAppTabs_SetTabLocation(t *testing.T) {
tabs.SetTabLocation(container.TabLocationLeading)
w.Resize(tabs.MinSize())
- test.AssertRendersToMarkup(t, "apptabs/mobile/tab_location_bottom.xml", c, "leading is the same as bottom on mobile")
+ test.AssertRendersToMarkup(t, "apptabs/mobile/tab_location_top.xml", c, "leading is the same as top on mobile")
tabs.SetTabLocation(container.TabLocationBottom)
w.Resize(tabs.MinSize())
diff --git a/container/doctabs.go b/container/doctabs.go
index 2d4e9026a2..9a7b79d235 100644
--- a/container/doctabs.go
+++ b/container/doctabs.go
@@ -145,7 +145,7 @@ func (t *DocTabs) SetItems(items []*TabItem) {
// SetTabLocation sets the location of the tab bar
func (t *DocTabs) SetTabLocation(l TabLocation) {
- t.location = l
+ t.location = tabsAdjustedLocation(l)
t.Refresh()
}
@@ -286,7 +286,11 @@ func (r *docTabsRenderer) buildTabButtons(count int) *fyne.Container {
if cells == 0 {
cells = 1
}
- buttons.Layout = layout.NewGridLayout(cells)
+ if r.docTabs.location == TabLocationTop || r.docTabs.location == TabLocationBottom {
+ buttons.Layout = layout.NewGridLayoutWithColumns(cells)
+ } else {
+ buttons.Layout = layout.NewGridLayoutWithRows(cells)
+ }
iconPos = buttonIconTop
} else if r.docTabs.location == TabLocationLeading || r.docTabs.location == TabLocationTrailing {
buttons.Layout = layout.NewVBoxLayout()
diff --git a/container/doctabs_mobile_test.go b/container/doctabs_mobile_test.go
index aaef6f4f26..e2eac4fc15 100644
--- a/container/doctabs_mobile_test.go
+++ b/container/doctabs_mobile_test.go
@@ -179,8 +179,17 @@ func TestDocTabs_HoverButtons(t *testing.T) {
test.MoveMouse(c, fyne.NewPos(75, 10))
test.AssertRendersToMarkup(t, "doctabs/mobile/hover_none.xml", c, "no hovering on mobile")
+ test.MoveMouse(c, fyne.NewPos(90, 10))
+ test.AssertRendersToMarkup(t, "doctabs/mobile/hover_none.xml", c, "no hovering on mobile")
+
test.MoveMouse(c, fyne.NewPos(10, 10))
test.AssertRendersToMarkup(t, "doctabs/mobile/hover_none.xml", c, "no hovering on mobile")
+
+ test.MoveMouse(c, fyne.NewPos(136, 10))
+ test.AssertRendersToMarkup(t, "doctabs/mobile/hover_none.xml", c, "no hovering on mobile")
+
+ test.MoveMouse(c, fyne.NewPos(104, 10))
+ test.AssertRendersToMarkup(t, "doctabs/mobile/hover_none.xml", c, "no hovering on mobile")
}
func TestDocTabs_Layout(t *testing.T) {
@@ -300,19 +309,17 @@ func TestDocTabs_SetTabLocation(t *testing.T) {
w.Resize(tabs.MinSize())
test.AssertRendersToMarkup(t, "doctabs/mobile/tab_location_top.xml", c)
- // TODO: doc tabs support leading/trailing but rendering is currently broken (see #1962)
- // tabs.SetTabLocation(container.TabLocationLeading)
- // w.Resize(tabs.MinSize())
- // test.AssertRendersToMarkup(t, "doctabs/mobile/tab_location_bottom.xml", c, "leading is the same as bottom on mobile")
+ tabs.SetTabLocation(container.TabLocationLeading)
+ w.Resize(tabs.MinSize())
+ test.AssertRendersToMarkup(t, "doctabs/mobile/tab_location_top.xml", c)
tabs.SetTabLocation(container.TabLocationBottom)
w.Resize(tabs.MinSize())
test.AssertRendersToMarkup(t, "doctabs/mobile/tab_location_bottom.xml", c)
- // TODO: doc tabs support leading/trailing but rendering is currently broken (see #1962)
- // tabs.SetTabLocation(container.TabLocationTrailing)
- // w.Resize(tabs.MinSize())
- // test.AssertRendersToMarkup(t, "doctabs/mobile/tab_location_bottom.xml", c, "trailing is the same as bottom on mobile")
+ tabs.SetTabLocation(container.TabLocationTrailing)
+ w.Resize(tabs.MinSize())
+ test.AssertRendersToMarkup(t, "doctabs/mobile/tab_location_bottom.xml", c)
tabs.SetTabLocation(container.TabLocationTop)
w.Resize(tabs.MinSize())
@@ -327,6 +334,9 @@ func TestDocTabs_Tapped(t *testing.T) {
item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text 2")}
item3 := &container.TabItem{Text: "Test3", Content: widget.NewLabel("Text 3")}
tabs := container.NewDocTabs(item1, item2, item3)
+ tabs.CreateTab = func() *container.TabItem {
+ return &container.TabItem{Text: "Another", Content: widget.NewLabel("Another Tab")}
+ }
w := test.NewWindow(tabs)
defer w.Close()
w.SetPadded(false)
@@ -347,4 +357,11 @@ func TestDocTabs_Tapped(t *testing.T) {
test.TapCanvas(c, fyne.NewPos(10, 10))
require.Equal(t, 0, tabs.SelectedIndex())
test.AssertRendersToMarkup(t, "doctabs/mobile/tapped_first_selected.xml", c)
+
+ test.TapCanvas(c, fyne.NewPos(254, 10))
+ require.Equal(t, 3, tabs.SelectedIndex())
+ test.AssertRendersToMarkup(t, "doctabs/mobile/tapped_create_tab.xml", c)
+
+ test.TapCanvas(c, fyne.NewPos(286, 10))
+ test.AssertRendersToMarkup(t, "doctabs/mobile/tapped_all_tabs.xml", c)
}
diff --git a/container/tabs.go b/container/tabs.go
index 55fc0a0a02..fe65f684c4 100644
--- a/container/tabs.go
+++ b/container/tabs.go
@@ -61,6 +61,27 @@ type baseTabs interface {
tabLocation() TabLocation
}
+func tabsAdjustedLocation(l TabLocation) TabLocation {
+ // Mobile has limited screen space, so don't put app tab bar on long edges
+ if d := fyne.CurrentDevice(); d.IsMobile() {
+ if o := d.Orientation(); fyne.IsVertical(o) {
+ if l == TabLocationLeading {
+ return TabLocationTop
+ } else if l == TabLocationTrailing {
+ return TabLocationBottom
+ }
+ } else {
+ if l == TabLocationTop {
+ return TabLocationLeading
+ } else if l == TabLocationBottom {
+ return TabLocationTrailing
+ }
+ }
+ }
+
+ return l
+}
+
func buildPopUpMenu(t baseTabs, button *widget.Button, items []*fyne.MenuItem) *widget.PopUpMenu {
d := fyne.CurrentApp().Driver()
c := d.CanvasForObject(button)
diff --git a/container/testdata/apptabs/mobile/layout_bottom_ico.xml b/container/testdata/apptabs/mobile/layout_bottom_ico.xml
deleted file mode 100644
index b63b53bf26..0000000000
--- a/container/testdata/apptabs/mobile/layout_bottom_ico.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
diff --git a/container/testdata/doctabs/mobile/tapped_all_tabs.xml b/container/testdata/doctabs/mobile/tapped_all_tabs.xml
new file mode 100644
index 0000000000..f5589b3214
--- /dev/null
+++ b/container/testdata/doctabs/mobile/tapped_all_tabs.xml
@@ -0,0 +1,96 @@
+
diff --git a/container/testdata/doctabs/mobile/tapped_create_tab.xml b/container/testdata/doctabs/mobile/tapped_create_tab.xml
new file mode 100644
index 0000000000..0985c5c5c8
--- /dev/null
+++ b/container/testdata/doctabs/mobile/tapped_create_tab.xml
@@ -0,0 +1,53 @@
+
diff --git a/container/testdata/doctabs/mobile/tapped_first_selected.xml b/container/testdata/doctabs/mobile/tapped_first_selected.xml
index b641270a1c..86c8dd1208 100644
--- a/container/testdata/doctabs/mobile/tapped_first_selected.xml
+++ b/container/testdata/doctabs/mobile/tapped_first_selected.xml
@@ -2,30 +2,35 @@
-
-
-
- Test1
-
+
+
+
+ Test1
+
-
- Test2
-
+
+ Test2
+
-
- Test3
-
+
+ Test3
+
-
+
+
+
+
+
+
@@ -33,7 +38,7 @@
-
+
Text 1
diff --git a/container/testdata/doctabs/mobile/tapped_second_selected.xml b/container/testdata/doctabs/mobile/tapped_second_selected.xml
index 399b3a7149..3dadde56ac 100644
--- a/container/testdata/doctabs/mobile/tapped_second_selected.xml
+++ b/container/testdata/doctabs/mobile/tapped_second_selected.xml
@@ -2,30 +2,35 @@
-
-
-
- Test1
-
+
+
+
+ Test1
+
-
- Test2
-
+
+ Test2
+
-
- Test3
-
+
+ Test3
+
-
+
+
+
+
+
+
@@ -33,7 +38,7 @@
-
+
Text 2
diff --git a/container/testdata/doctabs/mobile/tapped_third_selected.xml b/container/testdata/doctabs/mobile/tapped_third_selected.xml
index bd8c45503c..7bdc28a5c8 100644
--- a/container/testdata/doctabs/mobile/tapped_third_selected.xml
+++ b/container/testdata/doctabs/mobile/tapped_third_selected.xml
@@ -2,30 +2,35 @@
-
-
-
- Test1
-
+
+
+
+ Test1
+
-
- Test2
-
+
+ Test2
+
-
- Test3
-
+
+ Test3
+
-
+
+
+
+
+
+
@@ -33,7 +38,7 @@
-
+
Text 3