From 2c1642f355f2c8323ced76847d1473c5fa65a0d4 Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Thu, 9 May 2024 16:41:22 -0400 Subject: [PATCH] move from testCanvas to software canvas, fix a bunch of tests, break a few more --- app/app_software.go | 9 +- canvas/rectangle_test.go | 5 +- container/apptabs_desktop_flakey_test.go | 4 +- container/apptabs_desktop_test.go | 15 +- container/apptabs_mobile_flakey_test.go | 4 +- container/apptabs_mobile_test.go | 14 +- container/doctabs_desktop_test.go | 19 +- container/doctabs_mobile_test.go | 18 +- container/innerwindow_test.go | 6 +- container/tabs_test.go | 6 +- dialog/color_button_test.go | 3 +- dialog/color_channel_test.go | 3 +- dialog/color_picker_test.go | 9 +- dialog/color_preview_test.go | 3 +- dialog/color_test.go | 11 +- dialog/color_wheel_test.go | 3 +- dialog/confirm_test.go | 31 +- dialog/custom_test.go | 15 +- dialog/entry_test.go | 8 +- dialog/file_test.go | 59 +- dialog/folder_test.go | 3 +- dialog/form_test.go | 15 +- dialog/information_test.go | 34 +- dialog/progressinfinite_test.go | 33 +- driver/software/render.go | 2 - driver/software/render_test.go | 1 - internal/app/theme.go | 2 + internal/driver/common/canvas_test.go | 875 +++++++++--------- internal/driver/glfw/menu_bar_test.go | 13 +- internal/driver/software/canvas.go | 127 ++- .../driver/software/canvas_test.go | 4 +- .../driver/software/clipboard.go | 10 +- internal/driver/software/driver.go | 86 +- .../driver/software/file.go | 8 +- internal/driver/software/window.go | 63 +- internal/overlay_stack_test.go | 4 +- internal/painter/image_test.go | 12 +- internal/painter/software/painter.go | 3 +- internal/painter/software/painter_test.go | 91 +- internal/widget/shadow_test.go | 11 +- internal/widget/simple_renderer_test.go | 3 +- test/markup_renderer.go | 3 +- test/markup_renderer_test.go | 7 +- test/test.go | 41 +- test/test_test.go | 16 +- test/testapp.go | 5 +- test/testcanvas.go | 305 ------ test/testdriver.go | 140 --- test/testwindow.go | 142 --- widget/accordion_test.go | 7 +- widget/activity_internal_test.go | 3 +- widget/activity_test.go | 8 +- widget/button_internal_test.go | 3 +- widget/button_test.go | 13 +- widget/card_test.go | 5 +- widget/check_group_test.go | 19 +- widget/check_internal_test.go | 11 +- widget/check_test.go | 3 +- widget/entry_internal_test.go | 9 +- widget/entry_test.go | 29 +- widget/entry_validation_test.go | 3 +- widget/fileicon_test.go | 9 +- widget/form_test.go | 29 +- widget/gridwrap_test.go | 8 +- widget/hyperlink_test.go | 5 +- widget/icon_test.go | 3 +- widget/label_test.go | 7 +- widget/list_test.go | 25 +- widget/menu_desktop_test.go | 5 +- widget/menu_mobile_test.go | 4 +- widget/popup_menu_test.go | 5 +- widget/popup_test.go | 121 +-- widget/radio_group_test.go | 19 +- widget/richtext_objects_test.go | 3 +- widget/richtext_test.go | 3 +- widget/select_entry_internal_test.go | 13 +- widget/select_internal_test.go | 6 +- widget/select_test.go | 29 +- widget/slider_test.go | 5 +- widget/table_desktop_test.go | 3 +- widget/table_test.go | 41 +- widget/tree_internal_test.go | 17 +- widget/tree_test.go | 9 +- widget/widget_test.go | 7 +- 84 files changed, 1166 insertions(+), 1627 deletions(-) rename test/testcanvas_test.go => internal/driver/software/canvas_test.go (95%) rename test/testclipboard.go => internal/driver/software/clipboard.go (55%) rename test/testfile.go => internal/driver/software/file.go (86%) delete mode 100644 test/testcanvas.go delete mode 100644 test/testdriver.go delete mode 100644 test/testwindow.go diff --git a/app/app_software.go b/app/app_software.go index 362458a706..2bd8cc7a48 100644 --- a/app/app_software.go +++ b/app/app_software.go @@ -6,19 +6,18 @@ import ( "image" "fyne.io/fyne/v2" - software2 "fyne.io/fyne/v2/internal/driver/software" - "fyne.io/fyne/v2/internal/painter/software" - "fyne.io/fyne/v2/test" + "fyne.io/fyne/v2/internal/driver/software" + painter "fyne.io/fyne/v2/internal/painter/software" ) // NewWithID returns a new app instance using the test (headless) driver. // The ID string should be globally unique to this app. func NewWithID(id string) fyne.App { - return newAppWithDriver(test.NewDriverWithPainter(software.NewPainter()), id) + return newAppWithDriver(software.NewDriverWithPainter(painter.NewPainter()), id) } // NewWithSoftwareDriver returns a new app instance using the Software (custom) driver. // The ID string should be globally unique to this app. func NewWithSoftwareDriver(id string, painter func(image.Image, []image.Rectangle), events chan any) fyne.App { - return newAppWithDriver(software2.NewDriver(painter, events), id) + return newAppWithDriver(software.NewDriver(painter, events), id) } diff --git a/canvas/rectangle_test.go b/canvas/rectangle_test.go index 6ccb59d2a5..ef3dc93591 100644 --- a/canvas/rectangle_test.go +++ b/canvas/rectangle_test.go @@ -7,7 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/internal/cache" - "fyne.io/fyne/v2/internal/driver/software" + canvas2 "fyne.io/fyne/v2/internal/driver/software" painter "fyne.io/fyne/v2/internal/painter/software" "fyne.io/fyne/v2/test" @@ -39,8 +39,7 @@ func TestRectangle_Radius(t *testing.T) { rect.Resize(fyne.NewSize(50, 50)) test.AssertObjectRendersToMarkup(t, "rounded_rect.xml", rect) - c := software.NewCanvasWithPainter(painter.NewPainter()) - c.Initialize(c, nil) + c := canvas2.NewCanvasWithPainter(painter.NewPainter()) c.SetContent(rect) c.Resize(fyne.NewSize(60, 60)) test.AssertRendersToImage(t, "rounded_rect_stroke.png", c) diff --git a/container/apptabs_desktop_flakey_test.go b/container/apptabs_desktop_flakey_test.go index d888a18636..4b052d5ee6 100644 --- a/container/apptabs_desktop_flakey_test.go +++ b/container/apptabs_desktop_flakey_test.go @@ -15,7 +15,7 @@ func TestAppTabs_ApplyTheme(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow( + w := software.NewWindow( container.NewAppTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), ) defer w.Close() @@ -36,7 +36,7 @@ func TestAppTabs_ChangeItemContent(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) diff --git a/container/apptabs_desktop_test.go b/container/apptabs_desktop_test.go index a327a2a7d0..fcf2a209cd 100644 --- a/container/apptabs_desktop_test.go +++ b/container/apptabs_desktop_test.go @@ -11,6 +11,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -23,7 +24,7 @@ func TestAppTabs_ChangeItemIcon(t *testing.T) { item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -47,7 +48,7 @@ func TestAppTabs_ChangeItemText(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -70,7 +71,7 @@ func TestAppTabs_DynamicTabs(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewAppTabs(item1) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 150)) @@ -123,7 +124,7 @@ func TestAppTabs_HoverButtons(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -151,7 +152,7 @@ func TestAppTabs_Layout(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -255,7 +256,7 @@ func TestAppTabs_SetTabLocation(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.NewAppTabs(item1, item2, item3) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -288,7 +289,7 @@ func TestAppTabs_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.NewAppTabs(item1, item2, item3) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(200, 100)) diff --git a/container/apptabs_mobile_flakey_test.go b/container/apptabs_mobile_flakey_test.go index 8de37b101f..7f7a894c90 100644 --- a/container/apptabs_mobile_flakey_test.go +++ b/container/apptabs_mobile_flakey_test.go @@ -15,7 +15,7 @@ func TestAppTabs_ApplyTheme(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow( + w := software.NewWindow( container.NewAppTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), ) defer w.Close() @@ -36,7 +36,7 @@ func TestAppTabs_ChangeItemContent(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) diff --git a/container/apptabs_mobile_test.go b/container/apptabs_mobile_test.go index 1d1ff8f90d..092854dfda 100644 --- a/container/apptabs_mobile_test.go +++ b/container/apptabs_mobile_test.go @@ -24,7 +24,7 @@ func TestAppTabs_ChangeItemIcon(t *testing.T) { item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -48,7 +48,7 @@ func TestAppTabs_ChangeItemText(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -71,7 +71,7 @@ func TestAppTabs_DynamicTabs(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewAppTabs(item1) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 150)) @@ -125,7 +125,7 @@ func TestAppTabs_HoverButtons(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewAppTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -147,7 +147,7 @@ func TestAppTabs_Layout(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -251,7 +251,7 @@ func TestAppTabs_SetTabLocation(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.NewAppTabs(item1, item2, item3) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -284,7 +284,7 @@ func TestAppTabs_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.NewAppTabs(item1, item2, item3) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(200, 100)) diff --git a/container/doctabs_desktop_test.go b/container/doctabs_desktop_test.go index dc2949de02..40f445ccbf 100644 --- a/container/doctabs_desktop_test.go +++ b/container/doctabs_desktop_test.go @@ -11,6 +11,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -20,7 +21,7 @@ func TestDocTabs_ApplyTheme(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow( + w := software.NewWindow( container.NewDocTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), ) defer w.Close() @@ -41,7 +42,7 @@ func TestDocTabs_ChangeItemContent(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewDocTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -65,7 +66,7 @@ func TestDocTabs_ChangeItemIcon(t *testing.T) { item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} tabs := container.NewDocTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -89,7 +90,7 @@ func TestDocTabs_ChangeItemText(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewDocTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -118,7 +119,7 @@ func TestDocTabs_DynamicTabs(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewDocTabs(item1) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 150)) @@ -174,7 +175,7 @@ func TestDocTabs_HoverButtons(t *testing.T) { tabs.CreateTab = func() *container.TabItem { return &container.TabItem{Text: "Another", Content: widget.NewLabel("Another Tab")} } - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -205,7 +206,7 @@ func TestDocTabs_Layout(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -309,7 +310,7 @@ func TestDocTabs_SetTabLocation(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) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -345,7 +346,7 @@ func TestDocTabs_Tapped(t *testing.T) { tabs.CreateTab = func() *container.TabItem { return &container.TabItem{Text: "Another", Content: widget.NewLabel("Another Tab")} } - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 100)) diff --git a/container/doctabs_mobile_test.go b/container/doctabs_mobile_test.go index 6dd788404c..621fb6f610 100644 --- a/container/doctabs_mobile_test.go +++ b/container/doctabs_mobile_test.go @@ -21,7 +21,7 @@ func TestDocTabs_ApplyTheme(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow( + w := software.NewWindow( container.NewDocTabs(&container.TabItem{Text: "Test", Content: widget.NewLabel("Text")}), ) defer w.Close() @@ -42,7 +42,7 @@ func TestDocTabs_ChangeItemContent(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewDocTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -66,7 +66,7 @@ func TestDocTabs_ChangeItemIcon(t *testing.T) { item1 := &container.TabItem{Icon: theme.CancelIcon(), Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Icon: theme.ConfirmIcon(), Content: widget.NewLabel("Text2")} tabs := container.NewDocTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -90,7 +90,7 @@ func TestDocTabs_ChangeItemText(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewDocTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -113,7 +113,7 @@ func TestDocTabs_DynamicTabs(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text 1")} tabs := container.NewDocTabs(item1) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 150)) @@ -167,7 +167,7 @@ func TestDocTabs_HoverButtons(t *testing.T) { item1 := &container.TabItem{Text: "Test1", Content: widget.NewLabel("Text1")} item2 := &container.TabItem{Text: "Test2", Content: widget.NewLabel("Text2")} tabs := container.NewDocTabs(item1, item2) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(150, 150)) @@ -198,7 +198,7 @@ func TestDocTabs_Layout(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -303,7 +303,7 @@ func TestDocTabs_SetTabLocation(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) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -339,7 +339,7 @@ func TestDocTabs_Tapped(t *testing.T) { tabs.CreateTab = func() *container.TabItem { return &container.TabItem{Text: "Another", Content: widget.NewLabel("Another Tab")} } - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(380, 100)) diff --git a/container/innerwindow_test.go b/container/innerwindow_test.go index 463844f2fa..d9f2fed10f 100644 --- a/container/innerwindow_test.go +++ b/container/innerwindow_test.go @@ -3,18 +3,20 @@ package container import ( "testing" + "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" - "github.com/stretchr/testify/assert" ) func TestInnerWindow_Close(t *testing.T) { w := NewInnerWindow("Thing", widget.NewLabel("Content")) - outer := test.NewWindow(w) + outer := software.NewWindow(w) outer.SetPadded(false) outer.Resize(w.MinSize()) assert.True(t, w.Visible()) diff --git a/container/tabs_test.go b/container/tabs_test.go index f50e78336a..579a6c5031 100644 --- a/container/tabs_test.go +++ b/container/tabs_test.go @@ -3,9 +3,11 @@ package container import ( "testing" - internalTest "fyne.io/fyne/v2/internal/test" "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2/internal/driver/software" + internalTest "fyne.io/fyne/v2/internal/test" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/internal/cache" @@ -33,7 +35,7 @@ func TestTab_ThemeChange(t *testing.T) { tabs := NewAppTabs( NewTabItem("a", widget.NewLabel("a")), NewTabItem("b", widget.NewLabel("b"))) - w := test.NewWindow(tabs) + w := software.NewWindow(tabs) w.Resize(fyne.NewSize(180, 120)) initial := w.Canvas().Capture() diff --git a/dialog/color_button_test.go b/dialog/color_button_test.go index 741d9124f8..403b2b676e 100644 --- a/dialog/color_button_test.go +++ b/dialog/color_button_test.go @@ -6,6 +6,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" ) @@ -33,7 +34,7 @@ func Test_colorButton_Layout(t *testing.T) { color.MouseIn(nil) } - window := test.NewWindow(container.NewCenter(color)) + window := software.NewWindow(container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(50, 50))) test.AssertRendersToImage(t, "color/button_layout_"+name+".png", window.Canvas()) diff --git a/dialog/color_channel_test.go b/dialog/color_channel_test.go index 9bca175afd..8ea785da3f 100644 --- a/dialog/color_channel_test.go +++ b/dialog/color_channel_test.go @@ -4,6 +4,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" ) @@ -36,7 +37,7 @@ func Test_colorChannel_Layout(t *testing.T) { color := newColorChannel(tt.name, min, max, tt.value, nil) color.Resize(size) - window := test.NewWindow(color) + window := software.NewWindow(color) test.AssertRendersToImage(t, "color/channel_layout_"+name+".png", window.Canvas()) diff --git a/dialog/color_picker_test.go b/dialog/color_picker_test.go index c146c900dc..017c327d3b 100644 --- a/dialog/color_picker_test.go +++ b/dialog/color_picker_test.go @@ -5,6 +5,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" ) @@ -15,7 +16,7 @@ func Test_colorGreyscalePicker_Layout(t *testing.T) { color := newColorGreyscalePicker(nil) - window := test.NewWindow(container.NewCenter(color)) + window := software.NewWindow(container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(360, 60))) test.AssertRendersToImage(t, "color/picker_layout_greyscale.png", window.Canvas()) @@ -29,7 +30,7 @@ func Test_colorBasicPicker_Layout(t *testing.T) { color := newColorBasicPicker(nil) - window := test.NewWindow(container.NewCenter(color)) + window := software.NewWindow(container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(360, 60))) test.AssertRendersToImage(t, "color/picker_layout_basic.png", window.Canvas()) @@ -46,7 +47,7 @@ func Test_colorRecentPicker_Layout(t *testing.T) { color := newColorRecentPicker(nil) - window := test.NewWindow(container.NewCenter(color)) + window := software.NewWindow(container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(360, 60))) test.AssertRendersToImage(t, "color/picker_layout_recent.png", window.Canvas()) @@ -62,7 +63,7 @@ func Test_colorAdvancedPicker_Layout(t *testing.T) { color.Refresh() - window := test.NewWindow(container.NewCenter(color)) + window := software.NewWindow(container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(200, 200))) test.AssertRendersToImage(t, "color/picker_layout_advanced.png", window.Canvas()) diff --git a/dialog/color_preview_test.go b/dialog/color_preview_test.go index 538679ff1f..febef3770f 100644 --- a/dialog/color_preview_test.go +++ b/dialog/color_preview_test.go @@ -5,6 +5,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" ) @@ -15,7 +16,7 @@ func Test_colorPreview_Color(t *testing.T) { preview := newColorPreview(color.RGBA{53, 113, 233, 255}) preview.SetColor(color.RGBA{90, 206, 80, 180}) - window := test.NewWindow(preview) + window := software.NewWindow(preview) padding := theme.Padding() * 2 window.Resize(fyne.NewSize(128+padding, 64+padding)) diff --git a/dialog/color_test.go b/dialog/color_test.go index 311132f2de..898f1edf21 100644 --- a/dialog/color_test.go +++ b/dialog/color_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" col "fyne.io/fyne/v2/internal/color" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "github.com/stretchr/testify/assert" @@ -16,7 +17,7 @@ func TestColorDialog_Theme(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(1000, 800)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) @@ -47,7 +48,7 @@ func TestColorDialog_Recents(t *testing.T) { // Inject recent preferences a.Preferences().SetString("color_recents", "#2196f3,#4caf50,#f44336") - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(800, 600)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) @@ -65,7 +66,7 @@ func TestColorDialog_Recents(t *testing.T) { func TestColorDialog_SetColor(t *testing.T) { - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(800, 600)) col := color.RGBA{70, 210, 200, 255} @@ -105,7 +106,7 @@ func TestColorDialogSimple_Theme(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(600, 400)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) @@ -126,7 +127,7 @@ func TestColorDialogSimple_Recents(t *testing.T) { // Inject recent preferences a.Preferences().SetString("color_recents", "#2196f3,#4caf50,#f44336") - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(600, 400)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) diff --git a/dialog/color_wheel_test.go b/dialog/color_wheel_test.go index 39d85036b5..0fef7160a4 100644 --- a/dialog/color_wheel_test.go +++ b/dialog/color_wheel_test.go @@ -4,6 +4,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" ) @@ -13,7 +14,7 @@ func Test_colorWheel_Layout(t *testing.T) { wheel := newColorWheel(nil) wheel.SetHSLA(180, 100, 50, 255) - window := test.NewWindow(wheel) + window := software.NewWindow(wheel) window.Resize(wheel.MinSize().Max(fyne.NewSize(100, 100))) test.AssertRendersToImage(t, "color/wheel_layout.png", window.Canvas()) diff --git a/dialog/confirm_test.go b/dialog/confirm_test.go index fba7ab22c6..d5b1ab98be 100644 --- a/dialog/confirm_test.go +++ b/dialog/confirm_test.go @@ -6,6 +6,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -17,7 +18,7 @@ func TestDialog_ConfirmDoubleCallback(t *testing.T) { ch := make(chan int) cnf := NewConfirm("Test", "Test", func(_ bool) { ch <- 42 - }, test.NewWindow(nil)) + }, software.NewWindow(nil)) cnf.SetDismissText("No") cnf.SetConfirmText("Yes") cnf.SetOnClosed(func() { @@ -34,7 +35,7 @@ func TestDialog_ConfirmDoubleCallback(t *testing.T) { func TestDialog_ConfirmCallbackOnlyOnClosed(t *testing.T) { ch := make(chan int) - cnf := NewConfirm("Test", "Test", nil, test.NewWindow(nil)) + cnf := NewConfirm("Test", "Test", nil, software.NewWindow(nil)) cnf.SetDismissText("No") cnf.SetConfirmText("Yes") cnf.SetOnClosed(func() { @@ -52,7 +53,7 @@ func TestDialog_ConfirmCallbackOnlyOnConfirm(t *testing.T) { ch := make(chan int) cnf := NewConfirm("Test", "Test", func(_ bool) { ch <- 42 - }, test.NewWindow(nil)) + }, software.NewWindow(nil)) cnf.SetDismissText("No") cnf.SetConfirmText("Yes") cnf.Show() @@ -64,7 +65,7 @@ func TestDialog_ConfirmCallbackOnlyOnConfirm(t *testing.T) { } func TestConfirmDialog_Resize(t *testing.T) { - window := test.NewWindow(nil) + window := software.NewWindow(nil) window.Resize(fyne.NewSize(600, 400)) defer window.Close() d := NewConfirm("Test", "Test", nil, window) @@ -72,32 +73,32 @@ func TestConfirmDialog_Resize(t *testing.T) { theDialog := d.dialog d.dialog.Show() // we cannot check window size if not shown - //Test resize - normal size scenario - size := fyne.NewSize(300, 180) //normal size to fit (600,400) + // Test resize - normal size scenario + size := fyne.NewSize(300, 180) // normal size to fit (600,400) theDialog.Resize(size) expectedWidth := float32(300) assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight := float32(180) assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - normal size scenario again - size = fyne.NewSize(310, 280) //normal size to fit (600,400) + // Test resize - normal size scenario again + size = fyne.NewSize(310, 280) // normal size to fit (600,400) theDialog.Resize(size) expectedWidth = 310 assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight = 280 assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - greater than max size scenario + // Test resize - greater than max size scenario size = fyne.NewSize(800, 600) theDialog.Resize(size) - expectedWidth = 600 //since win width only 600 - assert.Equal(t, expectedWidth, theDialog.win.Size().Width) //max, also work + expectedWidth = 600 // since win width only 600 + assert.Equal(t, expectedWidth, theDialog.win.Size().Width) // max, also work assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) - expectedHeight = 400 //since win heigh only 400 - assert.Equal(t, expectedHeight, theDialog.win.Size().Height) //max, also work + expectedHeight = 400 // since win heigh only 400 + assert.Equal(t, expectedHeight, theDialog.win.Size().Height) // max, also work assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test again - extreme small size + // Test again - extreme small size size = fyne.NewSize(1, 1) theDialog.Resize(size) expectedWidth = theDialog.win.Content.MinSize().Width @@ -109,7 +110,7 @@ func TestConfirmDialog_Resize(t *testing.T) { func TestConfirm_Importance(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) diff --git a/dialog/custom_test.go b/dialog/custom_test.go index d94b016a63..7300169363 100644 --- a/dialog/custom_test.go +++ b/dialog/custom_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -17,7 +18,7 @@ func TestShowCustom_ApplyTheme(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) label := widget.NewLabel("Content") label.Alignment = fyne.TextAlignCenter @@ -36,7 +37,7 @@ func TestShowCustom_ApplyTheme(t *testing.T) { } func TestShowCustom_Resize(t *testing.T) { - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(300, 300)) label := widget.NewLabel("Content") @@ -52,7 +53,7 @@ func TestShowCustom_Resize(t *testing.T) { func TestCustom_ApplyThemeOnShow(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) label := widget.NewLabel("Content") @@ -78,7 +79,7 @@ func TestCustom_ApplyThemeOnShow(t *testing.T) { func TestCustom_ResizeOnShow(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -100,7 +101,7 @@ func TestCustom_ResizeOnShow(t *testing.T) { func TestConfirm_SetButtons(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -123,7 +124,7 @@ func TestConfirm_SetButtons(t *testing.T) { func TestConfirmWithoutButtons(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -136,7 +137,7 @@ func TestConfirmWithoutButtons(t *testing.T) { func TestCustomConfirm_Importance(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) diff --git a/dialog/entry_test.go b/dialog/entry_test.go index 329ddb3977..372c719921 100644 --- a/dialog/entry_test.go +++ b/dialog/entry_test.go @@ -3,15 +3,17 @@ package dialog import ( "testing" - "fyne.io/fyne/v2/test" "github.com/stretchr/testify/assert" + + "fyne.io/fyne/v2/internal/driver/software" + "fyne.io/fyne/v2/test" ) func TestEntryDialog_Confirm(t *testing.T) { value := "" ed := NewEntryDialog("Test", "message", func(v string) { value = v - }, test.NewWindow(nil)) + }, software.NewWindow(nil)) ed.Show() test.Type(ed.entry, "123") test.Tap(ed.confirm) @@ -23,7 +25,7 @@ func TestEntryDialog_Dismiss(t *testing.T) { value := "123" ed := NewEntryDialog("Test", "message", func(v string) { value = v - }, test.NewWindow(nil)) + }, software.NewWindow(nil)) ed.Show() test.Type(ed.entry, "XYZ") test.Tap(ed.cancel) diff --git a/dialog/file_test.go b/dialog/file_test.go index 0c67fe767a..baeaf2c265 100644 --- a/dialog/file_test.go +++ b/dialog/file_test.go @@ -11,6 +11,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/storage" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -108,12 +109,12 @@ func TestEffectiveStartingDir(t *testing.T) { } func TestFileDialogResize(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) win.Resize(fyne.NewSize(600, 400)) file := NewFileOpen(func(file fyne.URIReadCloser, err error) {}, win) file.SetFilter(storage.NewExtensionFileFilter([]string{".png"})) - //Mimic the fileopen dialog + // Mimic the fileopen dialog d := &fileDialog{file: file} open := widget.NewButton("open", func() {}) ui := container.NewBorder(nil, nil, nil, open) @@ -124,32 +125,32 @@ func TestFileDialogResize(t *testing.T) { d.win.Resize(originalSize) file.dialog = d - //Test resize - normal size scenario - size := fyne.NewSize(200, 180) //normal size to fit (600,400) + // Test resize - normal size scenario + size := fyne.NewSize(200, 180) // normal size to fit (600,400) file.Resize(size) expectedWidth := float32(200) assert.Equal(t, expectedWidth, file.dialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight := float32(180) assert.Equal(t, expectedHeight, file.dialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - normal size scenario again - size = fyne.NewSize(300, 280) //normal size to fit (600,400) + // Test resize - normal size scenario again + size = fyne.NewSize(300, 280) // normal size to fit (600,400) file.Resize(size) expectedWidth = 300 assert.Equal(t, expectedWidth, file.dialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight = 280 assert.Equal(t, expectedHeight, file.dialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - greater than max size scenario + // Test resize - greater than max size scenario size = fyne.NewSize(800, 600) file.Resize(size) - expectedWidth = 600 //since win width only 600 - assert.Equal(t, expectedWidth, file.dialog.win.Size().Width) //max, also work + expectedWidth = 600 // since win width only 600 + assert.Equal(t, expectedWidth, file.dialog.win.Size().Width) // max, also work assert.Equal(t, expectedWidth, file.dialog.win.Content.Size().Width+theme.Padding()*2) - expectedHeight = 400 //since win heigh only 400 - assert.Equal(t, expectedHeight, file.dialog.win.Size().Height) //max, also work + expectedHeight = 400 // since win heigh only 400 + assert.Equal(t, expectedHeight, file.dialog.win.Size().Height) // max, also work assert.Equal(t, expectedHeight, file.dialog.win.Content.Size().Height+theme.Padding()*2) - //Test again - extreme small size + // Test again - extreme small size size = fyne.NewSize(1, 1) file.Resize(size) expectedWidth = file.dialog.win.Content.MinSize().Width @@ -161,7 +162,7 @@ func TestFileDialogResize(t *testing.T) { func TestShowFileOpen(t *testing.T) { var chosen fyne.URIReadCloser var openErr error - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) d := NewFileOpen(func(file fyne.URIReadCloser, err error) { chosen = file openErr = err @@ -180,10 +181,10 @@ func TestShowFileOpen(t *testing.T) { assert.NotNil(t, popup) ui := popup.Content.(*fyne.Container) - //header + // header title := ui.Objects[1].(*fyne.Container).Objects[1].(*widget.Label) assert.Equal(t, "Open File", title.Text) - //optionsbuttons + // optionsbuttons createNewFolderButton := ui.Objects[1].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button) assert.Equal(t, "", createNewFolderButton.Text) assert.Equal(t, theme.FolderNewIcon().Name(), createNewFolderButton.Icon.Name()) @@ -193,11 +194,11 @@ func TestShowFileOpen(t *testing.T) { optionsButton := ui.Objects[1].(*fyne.Container).Objects[0].(*fyne.Container).Objects[2].(*widget.Button) assert.Equal(t, "", optionsButton.Text) assert.Equal(t, theme.SettingsIcon().Name(), optionsButton.Icon.Name()) - //footer + // footer nameLabel := ui.Objects[2].(*fyne.Container).Objects[1].(*container.Scroll).Content.(*widget.Label) buttons := ui.Objects[2].(*fyne.Container).Objects[0].(*fyne.Container) open := buttons.Objects[1].(*widget.Button) - //body + // body breadcrumb := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[0].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*fyne.Container) assert.Greater(t, len(breadcrumb.Objects), 0) @@ -260,7 +261,7 @@ func TestHiddenFiles(t *testing.T) { t.Error("Failed to hide .hidden", err) } - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) d := NewFileOpen(func(file fyne.URIReadCloser, err error) { }, win) d.SetLocation(dir) @@ -310,7 +311,7 @@ func TestHiddenFiles(t *testing.T) { func TestShowFileSave(t *testing.T) { var chosen fyne.URIWriteCloser var saveErr error - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) saver := NewFileSave(func(file fyne.URIWriteCloser, err error) { chosen = file saveErr = err @@ -386,7 +387,7 @@ func TestShowFileSave(t *testing.T) { } func TestFileFilters(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) f := NewFileOpen(func(file fyne.URIReadCloser, err error) { }, win) @@ -449,7 +450,7 @@ func TestFileFilters(t *testing.T) { } func TestView(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { assert.Nil(t, err) @@ -506,7 +507,7 @@ func TestView(t *testing.T) { } func TestSetView(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(defaultView)) @@ -556,7 +557,7 @@ func TestSetView(t *testing.T) { } func TestSetViewPreferences(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) prefs := fyne.CurrentApp().Preferences() @@ -590,7 +591,7 @@ func TestSetViewPreferences(t *testing.T) { } func TestViewPreferences(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) prefs := fyne.CurrentApp().Preferences() @@ -631,7 +632,7 @@ func TestViewPreferences(t *testing.T) { } func TestFileFavorites(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { assert.Nil(t, err) @@ -676,7 +677,7 @@ func TestFileFavorites(t *testing.T) { } func TestSetFileNameBeforeShow(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) dSave := NewFileSave(func(fyne.URIWriteCloser, error) {}, win) dSave.SetFileName("testfile.zip") dSave.Show() @@ -694,7 +695,7 @@ func TestSetFileNameBeforeShow(t *testing.T) { func TestSetFileNameAfterShow(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) dSave := NewFileSave(func(fyne.URIWriteCloser, error) {}, win) dSave.Show() dSave.SetFileName("testfile.zip") @@ -711,7 +712,7 @@ func TestSetFileNameAfterShow(t *testing.T) { } func TestCreateNewFolderInDir(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) folderDialog := NewFolderOpen(func(lu fyne.ListableURI, err error) { assert.Nil(t, err) @@ -757,7 +758,7 @@ func TestCreateNewFolderInDir(t *testing.T) { } func TestSetOnClosedBeforeShow(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := software.NewWindow(widget.NewLabel("Content")) d := NewFileSave(func(fyne.URIWriteCloser, error) {}, win) onClosedCalled := false d.SetOnClosed(func() { onClosedCalled = true }) diff --git a/dialog/folder_test.go b/dialog/folder_test.go index 768caf9ac5..87d7cb3303 100644 --- a/dialog/folder_test.go +++ b/dialog/folder_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/storage" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/widget" @@ -16,7 +17,7 @@ import ( func TestShowFolderOpen(t *testing.T) { var chosen fyne.ListableURI var openErr error - win := test.NewWindow(widget.NewLabel("OpenDir")) + win := software.NewWindow(widget.NewLabel("OpenDir")) d := NewFolderOpen(func(file fyne.ListableURI, err error) { chosen = file openErr = err diff --git a/dialog/form_test.go b/dialog/form_test.go index 5c7074319f..aab3de60d4 100644 --- a/dialog/form_test.go +++ b/dialog/form_test.go @@ -5,6 +5,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -25,7 +26,7 @@ const ( func TestFormDialog_Control(t *testing.T) { var result formDialogResult - fd := controlFormDialog(&result, test.NewWindow(nil)) + fd := controlFormDialog(&result, software.NewWindow(nil)) fd.Show() test.Tap(fd.confirm) @@ -34,7 +35,7 @@ func TestFormDialog_Control(t *testing.T) { func TestFormDialog_InvalidCannotSubmit(t *testing.T) { var result formDialogResult - fd := validatingFormDialog(&result, test.NewWindow(nil)) + fd := validatingFormDialog(&result, software.NewWindow(nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -46,7 +47,7 @@ func TestFormDialog_InvalidCannotSubmit(t *testing.T) { func TestFormDialog_ValidCanSubmit(t *testing.T) { var result formDialogResult - fd := validatingFormDialog(&result, test.NewWindow(nil)) + fd := validatingFormDialog(&result, software.NewWindow(nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -65,7 +66,7 @@ func TestFormDialog_ValidCanSubmit(t *testing.T) { func TestFormDialog_CanCancelInvalid(t *testing.T) { var result formDialogResult - fd := validatingFormDialog(&result, test.NewWindow(nil)) + fd := validatingFormDialog(&result, software.NewWindow(nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -76,7 +77,7 @@ func TestFormDialog_CanCancelInvalid(t *testing.T) { func TestFormDialog_CanCancelNoValidation(t *testing.T) { var result formDialogResult - fd := controlFormDialog(&result, test.NewWindow(nil)) + fd := controlFormDialog(&result, software.NewWindow(nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -90,7 +91,7 @@ func TestFormDialog_Hints(t *testing.T) { test.NewApp() defer test.NewApp() test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) - w := test.NewWindow(nil) + w := software.NewWindow(nil) w.SetFullScreen(true) var result formDialogResult @@ -136,7 +137,7 @@ func TestFormDialog_Submit(t *testing.T) { items := []*widget.FormItem{validatingItem} form := NewForm("Validating Form Dialog", "Submit", "Cancel", items, func(confirm bool) { confirmed = confirm - }, test.NewWindow(nil)) + }, software.NewWindow(nil)) form.Show() validatingEntry.SetText("cba") diff --git a/dialog/information_test.go b/dialog/information_test.go index c1fc2c4c76..eadb4ced29 100644 --- a/dialog/information_test.go +++ b/dialog/information_test.go @@ -4,14 +4,16 @@ import ( "errors" "testing" + "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" - "github.com/stretchr/testify/assert" ) func TestDialog_MinSize(t *testing.T) { - window := test.NewWindow(nil) + window := software.NewWindow(nil) defer window.Close() d := NewInformation("Looooooooooooooong title", "message...", window) information := d.(*dialog) @@ -23,39 +25,39 @@ func TestDialog_MinSize(t *testing.T) { } func TestDialog_Resize(t *testing.T) { - window := test.NewWindow(nil) + window := software.NewWindow(nil) window.Resize(fyne.NewSize(600, 400)) defer window.Close() d := NewInformation("Looooooooooooooong title", "message...", window) theDialog := d.(*dialog) d.Show() // we cannot check window size if not shown - //Test resize - normal size scenario - size := fyne.NewSize(300, 180) //normal size to fit (600,400) + // Test resize - normal size scenario + size := fyne.NewSize(300, 180) // normal size to fit (600,400) theDialog.Resize(size) expectedWidth := float32(300) assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight := float32(180) assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - normal size scenario again - size = fyne.NewSize(310, 280) //normal size to fit (600,400) + // Test resize - normal size scenario again + size = fyne.NewSize(310, 280) // normal size to fit (600,400) theDialog.Resize(size) expectedWidth = 310 assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight = 280 assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - greater than max size scenario + // Test resize - greater than max size scenario size = fyne.NewSize(800, 600) theDialog.Resize(size) - expectedWidth = 600 //since win width only 600 - assert.Equal(t, expectedWidth, theDialog.win.Size().Width) //max, also work + expectedWidth = 600 // since win width only 600 + assert.Equal(t, expectedWidth, theDialog.win.Size().Width) // max, also work assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) - expectedHeight = 400 //since win heigh only 400 - assert.Equal(t, expectedHeight, theDialog.win.Size().Height) //max, also work + expectedHeight = 400 // since win heigh only 400 + assert.Equal(t, expectedHeight, theDialog.win.Size().Height) // max, also work assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test again - extreme small size + // Test again - extreme small size size = fyne.NewSize(1, 1) theDialog.Resize(size) expectedWidth = theDialog.win.Content.MinSize().Width @@ -65,7 +67,7 @@ func TestDialog_Resize(t *testing.T) { } func TestDialog_TextWrapping(t *testing.T) { - window := test.NewWindow(nil) + window := software.NewWindow(nil) window.Resize(fyne.NewSize(600, 400)) d := NewInformation("Title", "This is a really really long message that will be used to test the dialog text wrapping capabilities", window) @@ -84,7 +86,7 @@ func TestDialog_TextWrapping(t *testing.T) { } func TestDialog_InformationCallback(t *testing.T) { - d := NewInformation("Information", "Hello World", test.NewWindow(nil)) + d := NewInformation("Information", "Hello World", software.NewWindow(nil)) tapped := false d.SetOnClosed(func() { tapped = true }) d.Show() @@ -98,7 +100,7 @@ func TestDialog_InformationCallback(t *testing.T) { func TestDialog_ErrorCallback(t *testing.T) { err := errors.New("Error message") - d := NewError(err, test.NewWindow(nil)) + d := NewError(err, software.NewWindow(nil)) tapped := false d.SetOnClosed(func() { tapped = true }) d.Show() diff --git a/dialog/progressinfinite_test.go b/dialog/progressinfinite_test.go index 9b59214c38..c5ef45a2fd 100644 --- a/dialog/progressinfinite_test.go +++ b/dialog/progressinfinite_test.go @@ -3,15 +3,16 @@ package dialog import ( "testing" + "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2" - "fyne.io/fyne/v2/test" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" - "github.com/stretchr/testify/assert" ) func TestProgressInfiniteDialog_MinSize(t *testing.T) { - window := test.NewWindow(nil) + window := software.NewWindow(nil) defer window.Close() d := NewProgressInfinite("title", "message", window) @@ -22,39 +23,39 @@ func TestProgressInfiniteDialog_MinSize(t *testing.T) { } func TestProgressInfiniteDialog_Resize(t *testing.T) { - window := test.NewWindow(nil) + window := software.NewWindow(nil) window.Resize(fyne.NewSize(600, 400)) defer window.Close() d := NewProgressInfinite("title", "message", window) theDialog := d.dialog d.dialog.Show() // we cannot check window size if not shown - //Test resize - normal size scenario - size := fyne.NewSize(300, 180) //normal size to fit (600,400) + // Test resize - normal size scenario + size := fyne.NewSize(300, 180) // normal size to fit (600,400) theDialog.Resize(size) expectedWidth := float32(300) assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight := float32(180) assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - normal size scenario again - size = fyne.NewSize(310, 280) //normal size to fit (600,400) + // Test resize - normal size scenario again + size = fyne.NewSize(310, 280) // normal size to fit (600,400) theDialog.Resize(size) expectedWidth = 310 assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) expectedHeight = 280 assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test resize - greater than max size scenario + // Test resize - greater than max size scenario size = fyne.NewSize(800, 600) theDialog.Resize(size) - expectedWidth = 600 //since win width only 600 - assert.Equal(t, expectedWidth, theDialog.win.Size().Width) //max, also work + expectedWidth = 600 // since win width only 600 + assert.Equal(t, expectedWidth, theDialog.win.Size().Width) // max, also work assert.Equal(t, expectedWidth, theDialog.win.Content.Size().Width+theme.Padding()*2) - expectedHeight = 400 //since win heigh only 400 - assert.Equal(t, expectedHeight, theDialog.win.Size().Height) //max, also work + expectedHeight = 400 // since win heigh only 400 + assert.Equal(t, expectedHeight, theDialog.win.Size().Height) // max, also work assert.Equal(t, expectedHeight, theDialog.win.Content.Size().Height+theme.Padding()*2) - //Test again - extreme small size + // Test again - extreme small size size = fyne.NewSize(1, 1) theDialog.Resize(size) expectedWidth = theDialog.win.Content.MinSize().Width @@ -67,7 +68,7 @@ func TestProgressInfiniteDialog_Content(t *testing.T) { title := "title" message := "message" - window := test.NewWindow(nil) + window := software.NewWindow(nil) defer window.Close() d := NewProgressInfinite(title, message, window) @@ -76,7 +77,7 @@ func TestProgressInfiniteDialog_Content(t *testing.T) { } func TestProgressInfiniteDialog_Show(t *testing.T) { - window := test.NewWindow(nil) + window := software.NewWindow(nil) defer window.Close() d := NewProgressInfinite("title", "message", window) diff --git a/driver/software/render.go b/driver/software/render.go index b82e6abb03..b9b04e3bbb 100644 --- a/driver/software/render.go +++ b/driver/software/render.go @@ -6,7 +6,6 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/internal/app" "fyne.io/fyne/v2/internal/driver/software" - painter "fyne.io/fyne/v2/internal/painter/software" ) @@ -26,7 +25,6 @@ func Render(obj fyne.CanvasObject, t fyne.Theme) image.Image { fyne.CurrentApp().Settings().SetTheme(t) c := software.NewCanvasWithPainter(painter.NewPainter()) - c.Initialize(c, nil) c.SetPadded(false) c.SetContent(obj) diff --git a/driver/software/render_test.go b/driver/software/render_test.go index ff597251ee..ce3c642c0b 100644 --- a/driver/software/render_test.go +++ b/driver/software/render_test.go @@ -47,7 +47,6 @@ func TestRenderCanvas(t *testing.T) { ))) c := software.NewCanvasWithPainter(painter.NewPainter()) - c.Initialize(c, nil) c.SetContent(obj) if fyne.CurrentDevice().IsMobile() { diff --git a/internal/app/theme.go b/internal/app/theme.go index 9dc81ac979..f51442aef4 100644 --- a/internal/app/theme.go +++ b/internal/app/theme.go @@ -27,6 +27,8 @@ func ApplyThemeTo(content fyne.CanvasObject, canv fyne.Canvas) { } } content.Refresh() + // TODO: This seems wrong + canv.Refresh(content) } // ApplySettings ensures that all widgets and themeable objects in an application will be updated for the current theme. diff --git a/internal/driver/common/canvas_test.go b/internal/driver/common/canvas_test.go index b43fbd0e5e..3278e3271f 100644 --- a/internal/driver/common/canvas_test.go +++ b/internal/driver/common/canvas_test.go @@ -1,439 +1,440 @@ package common -import ( - "errors" - "fmt" - "image/color" - "testing" - - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/canvas" - "fyne.io/fyne/v2/container" - "fyne.io/fyne/v2/test" - "fyne.io/fyne/v2/theme" - "github.com/stretchr/testify/assert" -) - -func TestCanvas_walkTree(t *testing.T) { - test.NewApp() - defer test.NewApp() - - leftObj1 := canvas.NewRectangle(color.Gray16{Y: 1}) - leftObj2 := canvas.NewRectangle(color.Gray16{Y: 2}) - leftCol := container.NewWithoutLayout(leftObj1, leftObj2) - rightObj1 := canvas.NewRectangle(color.Gray16{Y: 10}) - rightObj2 := canvas.NewRectangle(color.Gray16{Y: 20}) - rightCol := container.NewWithoutLayout(rightObj1, rightObj2) - content := container.NewWithoutLayout(leftCol, rightCol) - content.Move(fyne.NewPos(17, 42)) - leftCol.Move(fyne.NewPos(300, 400)) - leftObj1.Move(fyne.NewPos(1, 2)) - leftObj2.Move(fyne.NewPos(20, 30)) - rightObj1.Move(fyne.NewPos(500, 600)) - rightObj2.Move(fyne.NewPos(60, 70)) - rightCol.Move(fyne.NewPos(7, 8)) - - tree := &renderCacheTree{root: &RenderCacheNode{obj: content}} - c := &Canvas{} - c.Initialize(nil, func() {}) - c.SetContentTreeAndFocusMgr(&canvas.Rectangle{FillColor: theme.BackgroundColor()}) - - type nodeInfo struct { - obj fyne.CanvasObject - lastBeforeCallIndex, lastAfterCallIndex int - } - updateInfoBefore := func(node *RenderCacheNode, index int) { - pd, _ := node.painterData.(nodeInfo) - if (pd != nodeInfo{}) && pd.obj != node.obj { - panic("node cache does not match node obj - nodes should not be reused for different objects") - } - pd.obj = node.obj - pd.lastBeforeCallIndex = index - node.painterData = pd - } - updateInfoAfter := func(node *RenderCacheNode, index int) { - pd := node.painterData.(nodeInfo) - if pd.obj != node.obj { - panic("node cache does not match node obj - nodes should not be reused for different objects") - } - pd.lastAfterCallIndex = index - node.painterData = pd - } - - // - // test that first walk calls the hooks correctly - // - type beforeCall struct { - obj fyne.CanvasObject - parent fyne.CanvasObject - pos fyne.Position - } - beforeCalls := []beforeCall{} - type afterCall struct { - obj fyne.CanvasObject - parent fyne.CanvasObject - } - afterCalls := []afterCall{} - - var i int - c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { - var parent fyne.CanvasObject - if node.parent != nil { - parent = node.parent.obj - } - i++ - updateInfoBefore(node, i) - beforeCalls = append(beforeCalls, beforeCall{obj: node.obj, parent: parent, pos: pos}) - }, func(node *RenderCacheNode, _ fyne.Position) { - var parent fyne.CanvasObject - if node.parent != nil { - parent = node.parent.obj - } - i++ - updateInfoAfter(node, i) - node.minSize.Height = node.obj.Position().Y - afterCalls = append(afterCalls, afterCall{obj: node.obj, parent: parent}) - }) - - assert.Equal(t, []beforeCall{ - {obj: content, pos: fyne.NewPos(17, 42)}, - {obj: leftCol, parent: content, pos: fyne.NewPos(317, 442)}, - {obj: leftObj1, parent: leftCol, pos: fyne.NewPos(318, 444)}, - {obj: leftObj2, parent: leftCol, pos: fyne.NewPos(337, 472)}, - {obj: rightCol, parent: content, pos: fyne.NewPos(24, 50)}, - {obj: rightObj1, parent: rightCol, pos: fyne.NewPos(524, 650)}, - {obj: rightObj2, parent: rightCol, pos: fyne.NewPos(84, 120)}, - }, beforeCalls, "calls before children hook with the correct node and position") - assert.Equal(t, []afterCall{ - {obj: leftObj1, parent: leftCol}, - {obj: leftObj2, parent: leftCol}, - {obj: leftCol, parent: content}, - {obj: rightObj1, parent: rightCol}, - {obj: rightObj2, parent: rightCol}, - {obj: rightCol, parent: content}, - {obj: content}, - }, afterCalls, "calls after children hook with the correct node") - - // - // test that second walk gives access to the cache - // - secondRunBeforePainterData := []nodeInfo{} - secondRunAfterPainterData := []nodeInfo{} - nodes := []*RenderCacheNode{} - - c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { - secondRunBeforePainterData = append(secondRunBeforePainterData, node.painterData.(nodeInfo)) - nodes = append(nodes, node) - }, func(node *RenderCacheNode, _ fyne.Position) { - secondRunAfterPainterData = append(secondRunAfterPainterData, node.painterData.(nodeInfo)) - }) - - assert.Equal(t, []nodeInfo{ - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, - {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 13}, - {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, - {obj: rightObj2, lastBeforeCallIndex: 11, lastAfterCallIndex: 12}, - }, secondRunBeforePainterData, "second run uses cached nodes") - assert.Equal(t, []nodeInfo{ - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, - {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, - {obj: rightObj2, lastBeforeCallIndex: 11, lastAfterCallIndex: 12}, - {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 13}, - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, - }, secondRunAfterPainterData, "second run uses cached nodes") - leftObj1Node := nodes[2] - leftObj2Node := nodes[3] - assert.Equal(t, leftObj2Node, leftObj1Node.nextSibling, "correct sibling relation") - assert.Nil(t, leftObj2Node.nextSibling, "no surplus nodes") - rightObj1Node := nodes[5] - rightObj2Node := nodes[6] - assert.Equal(t, rightObj2Node, rightObj1Node.nextSibling, "correct sibling relation") - rightColNode := nodes[4] - assert.Nil(t, rightColNode.nextSibling, "no surplus nodes") - - // - // test that removal, replacement and adding at the end of a children list works - // - deleteAt(leftCol, 1) - leftNewObj2 := canvas.NewRectangle(color.Gray16{Y: 3}) - leftCol.Add(leftNewObj2) - deleteAt(rightCol, 1) - thirdCol := container.NewVBox() - content.Add(thirdCol) - thirdRunBeforePainterData := []nodeInfo{} - thirdRunAfterPainterData := []nodeInfo{} - - i = 0 - c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { - i++ - updateInfoBefore(node, i) - thirdRunBeforePainterData = append(thirdRunBeforePainterData, node.painterData.(nodeInfo)) - }, func(node *RenderCacheNode, _ fyne.Position) { - i++ - updateInfoAfter(node, i) - thirdRunAfterPainterData = append(thirdRunAfterPainterData, node.painterData.(nodeInfo)) - }) - - assert.Equal(t, []nodeInfo{ - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 0}, // new node for replaced obj - {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 13}, - {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, - {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 0}, // new node for third column - }, thirdRunBeforePainterData, "third run uses cached nodes if possible") - assert.Equal(t, []nodeInfo{ - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, // new node for replaced obj - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, - {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, - {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 11}, - {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 13}, // new node for third column - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, - }, thirdRunAfterPainterData, "third run uses cached nodes if possible") - assert.NotEqual(t, leftObj2Node, leftObj1Node.nextSibling, "new node for replaced object") - assert.Nil(t, rightObj1Node.nextSibling, "node for removed object has been removed, too") - assert.NotNil(t, rightColNode.nextSibling, "new node for new object") - - // - // test that insertion at the beginnning or in the middle of a children list - // removes all following siblings and their subtrees - // - leftNewObj2a := canvas.NewRectangle(color.Gray16{Y: 4}) - insert(leftCol, leftNewObj2a, 1) - rightNewObj0 := canvas.NewRectangle(color.Gray16{Y: 30}) - Prepend(rightCol, rightNewObj0) - fourthRunBeforePainterData := []nodeInfo{} - fourthRunAfterPainterData := []nodeInfo{} - nodes = []*RenderCacheNode{} - - i = 0 - c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { - i++ - updateInfoBefore(node, i) - fourthRunBeforePainterData = append(fourthRunBeforePainterData, node.painterData.(nodeInfo)) - nodes = append(nodes, node) - }, func(node *RenderCacheNode, _ fyne.Position) { - i++ - updateInfoAfter(node, i) - fourthRunAfterPainterData = append(fourthRunAfterPainterData, node.painterData.(nodeInfo)) - }) - - assert.Equal(t, []nodeInfo{ - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftNewObj2a, lastBeforeCallIndex: 5, lastAfterCallIndex: 0}, // new node for inserted obj - {obj: leftNewObj2, lastBeforeCallIndex: 7, lastAfterCallIndex: 0}, // new node because of tail cut - {obj: rightCol, lastBeforeCallIndex: 10, lastAfterCallIndex: 11}, - {obj: rightNewObj0, lastBeforeCallIndex: 11, lastAfterCallIndex: 0}, // new node for inserted obj - {obj: rightObj1, lastBeforeCallIndex: 13, lastAfterCallIndex: 0}, // new node because of tail cut - {obj: thirdCol, lastBeforeCallIndex: 16, lastAfterCallIndex: 13}, - }, fourthRunBeforePainterData, "fourth run uses cached nodes if possible") - assert.Equal(t, []nodeInfo{ - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftNewObj2a, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, - {obj: leftNewObj2, lastBeforeCallIndex: 7, lastAfterCallIndex: 8}, - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 9}, - {obj: rightNewObj0, lastBeforeCallIndex: 11, lastAfterCallIndex: 12}, - {obj: rightObj1, lastBeforeCallIndex: 13, lastAfterCallIndex: 14}, - {obj: rightCol, lastBeforeCallIndex: 10, lastAfterCallIndex: 15}, - {obj: thirdCol, lastBeforeCallIndex: 16, lastAfterCallIndex: 17}, - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 18}, - }, fourthRunAfterPainterData, "fourth run uses cached nodes if possible") - // check cache tree integrity - // content node - assert.Equal(t, content, nodes[0].obj) - assert.Equal(t, leftCol, nodes[0].firstChild.obj) - assert.Nil(t, nodes[0].nextSibling) - // leftCol node - assert.Equal(t, leftCol, nodes[1].obj) - assert.Equal(t, leftObj1, nodes[1].firstChild.obj) - assert.Equal(t, rightCol, nodes[1].nextSibling.obj) - // leftObj1 node - assert.Equal(t, leftObj1, nodes[2].obj) - assert.Nil(t, nodes[2].firstChild) - assert.Equal(t, leftNewObj2a, nodes[2].nextSibling.obj) - // leftNewObj2a node - assert.Equal(t, leftNewObj2a, nodes[3].obj) - assert.Nil(t, nodes[3].firstChild) - assert.Equal(t, leftNewObj2, nodes[3].nextSibling.obj) - // leftNewObj2 node - assert.Equal(t, leftNewObj2, nodes[4].obj) - assert.Nil(t, nodes[4].firstChild) - assert.Nil(t, nodes[4].nextSibling) - // rightCol node - assert.Equal(t, rightCol, nodes[5].obj) - assert.Equal(t, rightNewObj0, nodes[5].firstChild.obj) - assert.Equal(t, thirdCol, nodes[5].nextSibling.obj) - // rightNewObj0 node - assert.Equal(t, rightNewObj0, nodes[6].obj) - assert.Nil(t, nodes[6].firstChild) - assert.Equal(t, rightObj1, nodes[6].nextSibling.obj) - // rightObj1 node - assert.Equal(t, rightObj1, nodes[7].obj) - assert.Nil(t, nodes[7].firstChild) - assert.Nil(t, nodes[7].nextSibling) - // thirdCol node - assert.Equal(t, thirdCol, nodes[8].obj) - assert.Nil(t, nodes[8].firstChild) - assert.Nil(t, nodes[8].nextSibling) - - // - // test that removal at the beginning or in the middle of a children list - // removes all following siblings and their subtrees - // - deleteAt(leftCol, 1) - deleteAt(rightCol, 0) - fifthRunBeforePainterData := []nodeInfo{} - fifthRunAfterPainterData := []nodeInfo{} - nodes = []*RenderCacheNode{} - - i = 0 - c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { - i++ - updateInfoBefore(node, i) - fifthRunBeforePainterData = append(fifthRunBeforePainterData, node.painterData.(nodeInfo)) - nodes = append(nodes, node) - }, func(node *RenderCacheNode, _ fyne.Position) { - i++ - updateInfoAfter(node, i) - fifthRunAfterPainterData = append(fifthRunAfterPainterData, node.painterData.(nodeInfo)) - }) - - assert.Equal(t, []nodeInfo{ - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 18}, - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 9}, - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 0}, // new node because of tail cut - {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 15}, - {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 0}, // new node because of tail cut - {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 17}, - }, fifthRunBeforePainterData, "fifth run uses cached nodes if possible") - assert.Equal(t, []nodeInfo{ - {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, - {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, - {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, - {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, - {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 11}, - {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 13}, - {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, - }, fifthRunAfterPainterData, "fifth run uses cached nodes if possible") - // check cache tree integrity - // content node - assert.Equal(t, content, nodes[0].obj) - assert.Equal(t, leftCol, nodes[0].firstChild.obj) - assert.Nil(t, nodes[0].nextSibling) - // leftCol node - assert.Equal(t, leftCol, nodes[1].obj) - assert.Equal(t, leftObj1, nodes[1].firstChild.obj) - assert.Equal(t, rightCol, nodes[1].nextSibling.obj) - // leftObj1 node - assert.Equal(t, leftObj1, nodes[2].obj) - assert.Nil(t, nodes[2].firstChild) - assert.Equal(t, leftNewObj2, nodes[2].nextSibling.obj) - // leftNewObj2 node - assert.Equal(t, leftNewObj2, nodes[3].obj) - assert.Nil(t, nodes[3].firstChild) - assert.Nil(t, nodes[3].nextSibling) - // rightCol node - assert.Equal(t, rightCol, nodes[4].obj) - assert.Equal(t, rightObj1, nodes[4].firstChild.obj) - assert.Equal(t, thirdCol, nodes[4].nextSibling.obj) - // rightObj1 node - assert.Equal(t, rightObj1, nodes[5].obj) - assert.Nil(t, nodes[5].firstChild) - assert.Nil(t, nodes[5].nextSibling) - // thirdCol node - assert.Equal(t, thirdCol, nodes[6].obj) - assert.Nil(t, nodes[6].firstChild) - assert.Nil(t, nodes[6].nextSibling) -} - -func TestCanvas_OverlayStack(t *testing.T) { - o := &overlayStack{} - a := canvas.NewRectangle(color.Black) - b := canvas.NewCircle(color.Black) - c := canvas.NewRectangle(color.White) - o.Add(a) - o.Add(b) - o.Add(c) - assert.Equal(t, 3, len(o.List())) - o.Remove(c) - assert.Equal(t, 2, len(o.List())) - o.Remove(a) - assert.Equal(t, 0, len(o.List())) -} - -func deleteAt(c *fyne.Container, index int) { - if index < len(c.Objects)-1 { - c.Objects = append(c.Objects[:index], c.Objects[index+1:]...) - } else { - c.Objects = c.Objects[:index] - } - c.Refresh() -} - -func insert(c *fyne.Container, object fyne.CanvasObject, index int) { - tail := append([]fyne.CanvasObject{object}, c.Objects[index:]...) - c.Objects = append(c.Objects[:index], tail...) - c.Refresh() -} - -func Prepend(c *fyne.Container, object fyne.CanvasObject) { - c.Objects = append([]fyne.CanvasObject{object}, c.Objects...) - c.Refresh() -} - -func TestRefreshCount(t *testing.T) { // Issue 2548. - var ( - c = &Canvas{} - errCh = make(chan error) - freed uint64 = 0 - refresh uint64 = 1000 - ) - c.Initialize(nil, func() {}) - for i := uint64(0); i < refresh; i++ { - c.Refresh(canvas.NewRectangle(color.Gray16{Y: 1})) - } - - go func() { - freed = c.FreeDirtyTextures() - if freed == 0 { - errCh <- errors.New("expected to free dirty textures but actually not freed") - return - } - errCh <- nil - }() - err := <-errCh - if err != nil { - t.Fatal(err) - } - if freed != refresh { - t.Fatalf("FreeDirtyTextures left refresh tasks behind in a frame, got %v, want %v", freed, refresh) - } -} - -func BenchmarkRefresh(b *testing.B) { - c := &Canvas{} - c.Initialize(nil, func() {}) - - for i := uint64(1); i < 1<<15; i *= 2 { - b.Run(fmt.Sprintf("#%d", i), func(b *testing.B) { - b.ReportAllocs() - - for j := 0; j < b.N; j++ { - for n := uint64(0); n < i; n++ { - c.Refresh(canvas.NewRectangle(color.Black)) - } - c.FreeDirtyTextures() - } - }) - } -} +// +// import ( +// "errors" +// "fmt" +// "image/color" +// "testing" +// +// "fyne.io/fyne/v2" +// "fyne.io/fyne/v2/canvas" +// "fyne.io/fyne/v2/container" +// "fyne.io/fyne/v2/test" +// "fyne.io/fyne/v2/theme" +// "github.com/stretchr/testify/assert" +// ) +// +// func TestCanvas_walkTree(t *testing.T) { +// test.NewApp() +// defer test.NewApp() +// +// leftObj1 := canvas.NewRectangle(color.Gray16{Y: 1}) +// leftObj2 := canvas.NewRectangle(color.Gray16{Y: 2}) +// leftCol := container.NewWithoutLayout(leftObj1, leftObj2) +// rightObj1 := canvas.NewRectangle(color.Gray16{Y: 10}) +// rightObj2 := canvas.NewRectangle(color.Gray16{Y: 20}) +// rightCol := container.NewWithoutLayout(rightObj1, rightObj2) +// content := container.NewWithoutLayout(leftCol, rightCol) +// content.Move(fyne.NewPos(17, 42)) +// leftCol.Move(fyne.NewPos(300, 400)) +// leftObj1.Move(fyne.NewPos(1, 2)) +// leftObj2.Move(fyne.NewPos(20, 30)) +// rightObj1.Move(fyne.NewPos(500, 600)) +// rightObj2.Move(fyne.NewPos(60, 70)) +// rightCol.Move(fyne.NewPos(7, 8)) +// +// tree := &renderCacheTree{root: &RenderCacheNode{obj: content}} +// c := &Canvas{} +// c.Initialize(nil, func() {}) +// c.SetContentTreeAndFocusMgr(&canvas.Rectangle{FillColor: theme.BackgroundColor()}) +// +// type nodeInfo struct { +// obj fyne.CanvasObject +// lastBeforeCallIndex, lastAfterCallIndex int +// } +// updateInfoBefore := func(node *RenderCacheNode, index int) { +// pd, _ := node.painterData.(nodeInfo) +// if (pd != nodeInfo{}) && pd.obj != node.obj { +// panic("node cache does not match node obj - nodes should not be reused for different objects") +// } +// pd.obj = node.obj +// pd.lastBeforeCallIndex = index +// node.painterData = pd +// } +// updateInfoAfter := func(node *RenderCacheNode, index int) { +// pd := node.painterData.(nodeInfo) +// if pd.obj != node.obj { +// panic("node cache does not match node obj - nodes should not be reused for different objects") +// } +// pd.lastAfterCallIndex = index +// node.painterData = pd +// } +// +// // +// // test that first walk calls the hooks correctly +// // +// type beforeCall struct { +// obj fyne.CanvasObject +// parent fyne.CanvasObject +// pos fyne.Position +// } +// beforeCalls := []beforeCall{} +// type afterCall struct { +// obj fyne.CanvasObject +// parent fyne.CanvasObject +// } +// afterCalls := []afterCall{} +// +// var i int +// c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { +// var parent fyne.CanvasObject +// if node.parent != nil { +// parent = node.parent.obj +// } +// i++ +// updateInfoBefore(node, i) +// beforeCalls = append(beforeCalls, beforeCall{obj: node.obj, parent: parent, pos: pos}) +// }, func(node *RenderCacheNode, _ fyne.Position) { +// var parent fyne.CanvasObject +// if node.parent != nil { +// parent = node.parent.obj +// } +// i++ +// updateInfoAfter(node, i) +// node.minSize.Height = node.obj.Position().Y +// afterCalls = append(afterCalls, afterCall{obj: node.obj, parent: parent}) +// }) +// +// assert.Equal(t, []beforeCall{ +// {obj: content, pos: fyne.NewPos(17, 42)}, +// {obj: leftCol, parent: content, pos: fyne.NewPos(317, 442)}, +// {obj: leftObj1, parent: leftCol, pos: fyne.NewPos(318, 444)}, +// {obj: leftObj2, parent: leftCol, pos: fyne.NewPos(337, 472)}, +// {obj: rightCol, parent: content, pos: fyne.NewPos(24, 50)}, +// {obj: rightObj1, parent: rightCol, pos: fyne.NewPos(524, 650)}, +// {obj: rightObj2, parent: rightCol, pos: fyne.NewPos(84, 120)}, +// }, beforeCalls, "calls before children hook with the correct node and position") +// assert.Equal(t, []afterCall{ +// {obj: leftObj1, parent: leftCol}, +// {obj: leftObj2, parent: leftCol}, +// {obj: leftCol, parent: content}, +// {obj: rightObj1, parent: rightCol}, +// {obj: rightObj2, parent: rightCol}, +// {obj: rightCol, parent: content}, +// {obj: content}, +// }, afterCalls, "calls after children hook with the correct node") +// +// // +// // test that second walk gives access to the cache +// // +// secondRunBeforePainterData := []nodeInfo{} +// secondRunAfterPainterData := []nodeInfo{} +// nodes := []*RenderCacheNode{} +// +// c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { +// secondRunBeforePainterData = append(secondRunBeforePainterData, node.painterData.(nodeInfo)) +// nodes = append(nodes, node) +// }, func(node *RenderCacheNode, _ fyne.Position) { +// secondRunAfterPainterData = append(secondRunAfterPainterData, node.painterData.(nodeInfo)) +// }) +// +// assert.Equal(t, []nodeInfo{ +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, +// {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 13}, +// {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, +// {obj: rightObj2, lastBeforeCallIndex: 11, lastAfterCallIndex: 12}, +// }, secondRunBeforePainterData, "second run uses cached nodes") +// assert.Equal(t, []nodeInfo{ +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, +// {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, +// {obj: rightObj2, lastBeforeCallIndex: 11, lastAfterCallIndex: 12}, +// {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 13}, +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, +// }, secondRunAfterPainterData, "second run uses cached nodes") +// leftObj1Node := nodes[2] +// leftObj2Node := nodes[3] +// assert.Equal(t, leftObj2Node, leftObj1Node.nextSibling, "correct sibling relation") +// assert.Nil(t, leftObj2Node.nextSibling, "no surplus nodes") +// rightObj1Node := nodes[5] +// rightObj2Node := nodes[6] +// assert.Equal(t, rightObj2Node, rightObj1Node.nextSibling, "correct sibling relation") +// rightColNode := nodes[4] +// assert.Nil(t, rightColNode.nextSibling, "no surplus nodes") +// +// // +// // test that removal, replacement and adding at the end of a children list works +// // +// deleteAt(leftCol, 1) +// leftNewObj2 := canvas.NewRectangle(color.Gray16{Y: 3}) +// leftCol.Add(leftNewObj2) +// deleteAt(rightCol, 1) +// thirdCol := container.NewVBox() +// content.Add(thirdCol) +// thirdRunBeforePainterData := []nodeInfo{} +// thirdRunAfterPainterData := []nodeInfo{} +// +// i = 0 +// c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { +// i++ +// updateInfoBefore(node, i) +// thirdRunBeforePainterData = append(thirdRunBeforePainterData, node.painterData.(nodeInfo)) +// }, func(node *RenderCacheNode, _ fyne.Position) { +// i++ +// updateInfoAfter(node, i) +// thirdRunAfterPainterData = append(thirdRunAfterPainterData, node.painterData.(nodeInfo)) +// }) +// +// assert.Equal(t, []nodeInfo{ +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 0}, // new node for replaced obj +// {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 13}, +// {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, +// {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 0}, // new node for third column +// }, thirdRunBeforePainterData, "third run uses cached nodes if possible") +// assert.Equal(t, []nodeInfo{ +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, // new node for replaced obj +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, +// {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, +// {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 11}, +// {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 13}, // new node for third column +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, +// }, thirdRunAfterPainterData, "third run uses cached nodes if possible") +// assert.NotEqual(t, leftObj2Node, leftObj1Node.nextSibling, "new node for replaced object") +// assert.Nil(t, rightObj1Node.nextSibling, "node for removed object has been removed, too") +// assert.NotNil(t, rightColNode.nextSibling, "new node for new object") +// +// // +// // test that insertion at the beginnning or in the middle of a children list +// // removes all following siblings and their subtrees +// // +// leftNewObj2a := canvas.NewRectangle(color.Gray16{Y: 4}) +// insert(leftCol, leftNewObj2a, 1) +// rightNewObj0 := canvas.NewRectangle(color.Gray16{Y: 30}) +// Prepend(rightCol, rightNewObj0) +// fourthRunBeforePainterData := []nodeInfo{} +// fourthRunAfterPainterData := []nodeInfo{} +// nodes = []*RenderCacheNode{} +// +// i = 0 +// c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { +// i++ +// updateInfoBefore(node, i) +// fourthRunBeforePainterData = append(fourthRunBeforePainterData, node.painterData.(nodeInfo)) +// nodes = append(nodes, node) +// }, func(node *RenderCacheNode, _ fyne.Position) { +// i++ +// updateInfoAfter(node, i) +// fourthRunAfterPainterData = append(fourthRunAfterPainterData, node.painterData.(nodeInfo)) +// }) +// +// assert.Equal(t, []nodeInfo{ +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftNewObj2a, lastBeforeCallIndex: 5, lastAfterCallIndex: 0}, // new node for inserted obj +// {obj: leftNewObj2, lastBeforeCallIndex: 7, lastAfterCallIndex: 0}, // new node because of tail cut +// {obj: rightCol, lastBeforeCallIndex: 10, lastAfterCallIndex: 11}, +// {obj: rightNewObj0, lastBeforeCallIndex: 11, lastAfterCallIndex: 0}, // new node for inserted obj +// {obj: rightObj1, lastBeforeCallIndex: 13, lastAfterCallIndex: 0}, // new node because of tail cut +// {obj: thirdCol, lastBeforeCallIndex: 16, lastAfterCallIndex: 13}, +// }, fourthRunBeforePainterData, "fourth run uses cached nodes if possible") +// assert.Equal(t, []nodeInfo{ +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftNewObj2a, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, +// {obj: leftNewObj2, lastBeforeCallIndex: 7, lastAfterCallIndex: 8}, +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 9}, +// {obj: rightNewObj0, lastBeforeCallIndex: 11, lastAfterCallIndex: 12}, +// {obj: rightObj1, lastBeforeCallIndex: 13, lastAfterCallIndex: 14}, +// {obj: rightCol, lastBeforeCallIndex: 10, lastAfterCallIndex: 15}, +// {obj: thirdCol, lastBeforeCallIndex: 16, lastAfterCallIndex: 17}, +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 18}, +// }, fourthRunAfterPainterData, "fourth run uses cached nodes if possible") +// // check cache tree integrity +// // content node +// assert.Equal(t, content, nodes[0].obj) +// assert.Equal(t, leftCol, nodes[0].firstChild.obj) +// assert.Nil(t, nodes[0].nextSibling) +// // leftCol node +// assert.Equal(t, leftCol, nodes[1].obj) +// assert.Equal(t, leftObj1, nodes[1].firstChild.obj) +// assert.Equal(t, rightCol, nodes[1].nextSibling.obj) +// // leftObj1 node +// assert.Equal(t, leftObj1, nodes[2].obj) +// assert.Nil(t, nodes[2].firstChild) +// assert.Equal(t, leftNewObj2a, nodes[2].nextSibling.obj) +// // leftNewObj2a node +// assert.Equal(t, leftNewObj2a, nodes[3].obj) +// assert.Nil(t, nodes[3].firstChild) +// assert.Equal(t, leftNewObj2, nodes[3].nextSibling.obj) +// // leftNewObj2 node +// assert.Equal(t, leftNewObj2, nodes[4].obj) +// assert.Nil(t, nodes[4].firstChild) +// assert.Nil(t, nodes[4].nextSibling) +// // rightCol node +// assert.Equal(t, rightCol, nodes[5].obj) +// assert.Equal(t, rightNewObj0, nodes[5].firstChild.obj) +// assert.Equal(t, thirdCol, nodes[5].nextSibling.obj) +// // rightNewObj0 node +// assert.Equal(t, rightNewObj0, nodes[6].obj) +// assert.Nil(t, nodes[6].firstChild) +// assert.Equal(t, rightObj1, nodes[6].nextSibling.obj) +// // rightObj1 node +// assert.Equal(t, rightObj1, nodes[7].obj) +// assert.Nil(t, nodes[7].firstChild) +// assert.Nil(t, nodes[7].nextSibling) +// // thirdCol node +// assert.Equal(t, thirdCol, nodes[8].obj) +// assert.Nil(t, nodes[8].firstChild) +// assert.Nil(t, nodes[8].nextSibling) +// +// // +// // test that removal at the beginning or in the middle of a children list +// // removes all following siblings and their subtrees +// // +// deleteAt(leftCol, 1) +// deleteAt(rightCol, 0) +// fifthRunBeforePainterData := []nodeInfo{} +// fifthRunAfterPainterData := []nodeInfo{} +// nodes = []*RenderCacheNode{} +// +// i = 0 +// c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) { +// i++ +// updateInfoBefore(node, i) +// fifthRunBeforePainterData = append(fifthRunBeforePainterData, node.painterData.(nodeInfo)) +// nodes = append(nodes, node) +// }, func(node *RenderCacheNode, _ fyne.Position) { +// i++ +// updateInfoAfter(node, i) +// fifthRunAfterPainterData = append(fifthRunAfterPainterData, node.painterData.(nodeInfo)) +// }) +// +// assert.Equal(t, []nodeInfo{ +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 18}, +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 9}, +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 0}, // new node because of tail cut +// {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 15}, +// {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 0}, // new node because of tail cut +// {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 17}, +// }, fifthRunBeforePainterData, "fifth run uses cached nodes if possible") +// assert.Equal(t, []nodeInfo{ +// {obj: leftObj1, lastBeforeCallIndex: 3, lastAfterCallIndex: 4}, +// {obj: leftNewObj2, lastBeforeCallIndex: 5, lastAfterCallIndex: 6}, +// {obj: leftCol, lastBeforeCallIndex: 2, lastAfterCallIndex: 7}, +// {obj: rightObj1, lastBeforeCallIndex: 9, lastAfterCallIndex: 10}, +// {obj: rightCol, lastBeforeCallIndex: 8, lastAfterCallIndex: 11}, +// {obj: thirdCol, lastBeforeCallIndex: 12, lastAfterCallIndex: 13}, +// {obj: content, lastBeforeCallIndex: 1, lastAfterCallIndex: 14}, +// }, fifthRunAfterPainterData, "fifth run uses cached nodes if possible") +// // check cache tree integrity +// // content node +// assert.Equal(t, content, nodes[0].obj) +// assert.Equal(t, leftCol, nodes[0].firstChild.obj) +// assert.Nil(t, nodes[0].nextSibling) +// // leftCol node +// assert.Equal(t, leftCol, nodes[1].obj) +// assert.Equal(t, leftObj1, nodes[1].firstChild.obj) +// assert.Equal(t, rightCol, nodes[1].nextSibling.obj) +// // leftObj1 node +// assert.Equal(t, leftObj1, nodes[2].obj) +// assert.Nil(t, nodes[2].firstChild) +// assert.Equal(t, leftNewObj2, nodes[2].nextSibling.obj) +// // leftNewObj2 node +// assert.Equal(t, leftNewObj2, nodes[3].obj) +// assert.Nil(t, nodes[3].firstChild) +// assert.Nil(t, nodes[3].nextSibling) +// // rightCol node +// assert.Equal(t, rightCol, nodes[4].obj) +// assert.Equal(t, rightObj1, nodes[4].firstChild.obj) +// assert.Equal(t, thirdCol, nodes[4].nextSibling.obj) +// // rightObj1 node +// assert.Equal(t, rightObj1, nodes[5].obj) +// assert.Nil(t, nodes[5].firstChild) +// assert.Nil(t, nodes[5].nextSibling) +// // thirdCol node +// assert.Equal(t, thirdCol, nodes[6].obj) +// assert.Nil(t, nodes[6].firstChild) +// assert.Nil(t, nodes[6].nextSibling) +// } +// +// func TestCanvas_OverlayStack(t *testing.T) { +// o := &overlayStack{} +// a := canvas.NewRectangle(color.Black) +// b := canvas.NewCircle(color.Black) +// c := canvas.NewRectangle(color.White) +// o.Add(a) +// o.Add(b) +// o.Add(c) +// assert.Equal(t, 3, len(o.List())) +// o.Remove(c) +// assert.Equal(t, 2, len(o.List())) +// o.Remove(a) +// assert.Equal(t, 0, len(o.List())) +// } +// +// func deleteAt(c *fyne.Container, index int) { +// if index < len(c.Objects)-1 { +// c.Objects = append(c.Objects[:index], c.Objects[index+1:]...) +// } else { +// c.Objects = c.Objects[:index] +// } +// c.Refresh() +// } +// +// func insert(c *fyne.Container, object fyne.CanvasObject, index int) { +// tail := append([]fyne.CanvasObject{object}, c.Objects[index:]...) +// c.Objects = append(c.Objects[:index], tail...) +// c.Refresh() +// } +// +// func Prepend(c *fyne.Container, object fyne.CanvasObject) { +// c.Objects = append([]fyne.CanvasObject{object}, c.Objects...) +// c.Refresh() +// } +// +// func TestRefreshCount(t *testing.T) { // Issue 2548. +// var ( +// c = &Canvas{} +// errCh = make(chan error) +// freed uint64 = 0 +// refresh uint64 = 1000 +// ) +// c.Initialize(nil, func() {}) +// for i := uint64(0); i < refresh; i++ { +// c.Refresh(canvas.NewRectangle(color.Gray16{Y: 1})) +// } +// +// go func() { +// freed = c.FreeDirtyTextures() +// if freed == 0 { +// errCh <- errors.New("expected to free dirty textures but actually not freed") +// return +// } +// errCh <- nil +// }() +// err := <-errCh +// if err != nil { +// t.Fatal(err) +// } +// if freed != refresh { +// t.Fatalf("FreeDirtyTextures left refresh tasks behind in a frame, got %v, want %v", freed, refresh) +// } +// } +// +// func BenchmarkRefresh(b *testing.B) { +// c := &Canvas{} +// c.Initialize(nil, func() {}) +// +// for i := uint64(1); i < 1<<15; i *= 2 { +// b.Run(fmt.Sprintf("#%d", i), func(b *testing.B) { +// b.ReportAllocs() +// +// for j := 0; j < b.N; j++ { +// for n := uint64(0); n < i; n++ { +// c.Refresh(canvas.NewRectangle(color.Black)) +// } +// c.FreeDirtyTextures() +// } +// }) +// } +// } diff --git a/internal/driver/glfw/menu_bar_test.go b/internal/driver/glfw/menu_bar_test.go index 64b3729fa0..b91eff3b79 100644 --- a/internal/driver/glfw/menu_bar_test.go +++ b/internal/driver/glfw/menu_bar_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/internal/driver/glfw" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/widget" @@ -46,7 +47,7 @@ func TestMenuBar(t *testing.T) { menu := fyne.NewMainMenu(m1, m2, m3) t.Run("mouse control and basic behaviour", func(t *testing.T) { - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 300)) @@ -319,7 +320,7 @@ func TestMenuBar(t *testing.T) { }) t.Run("keyboard control", func(t *testing.T) { - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 300)) @@ -464,7 +465,7 @@ func TestMenuBar_Toggle(t *testing.T) { menu := fyne.NewMainMenu(m1, m2) t.Run("when menu bar is inactive", func(t *testing.T) { - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 300)) @@ -484,7 +485,7 @@ func TestMenuBar_Toggle(t *testing.T) { }) t.Run("when menu bar is active (first menu item active)", func(t *testing.T) { - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 300)) @@ -505,7 +506,7 @@ func TestMenuBar_Toggle(t *testing.T) { }) t.Run("when menu bar is active (second menu item active)", func(t *testing.T) { - w := test.NewWindow(nil) + w := software.NewWindow(nil) defer w.Close() w.SetPadded(false) w.Resize(fyne.NewSize(300, 300)) @@ -516,7 +517,7 @@ func TestMenuBar_Toggle(t *testing.T) { menuBar.Resize(fyne.NewSize(300, 0).Max(menuBar.MinSize())) menuBar.Toggle() - c.(test.WindowlessCanvas).FocusNext() + c.(software.WindowlessCanvas).FocusNext() require.True(t, menuBar.IsActive()) test.AssertRendersToMarkup(t, "menu_bar_toggle_second_item_active.xml", c) diff --git a/internal/driver/software/canvas.go b/internal/driver/software/canvas.go index f6ea9fe6e3..b0ceae5574 100644 --- a/internal/driver/software/canvas.go +++ b/internal/driver/software/canvas.go @@ -32,7 +32,7 @@ type WindowlessCanvas interface { Initialize(common.SizeableCanvas, func()) } -type softwareCanvas struct { +type SoftwareCanvas struct { common.Canvas size fyne.Size @@ -48,7 +48,7 @@ type softwareCanvas struct { onTypedKey func(*fyne.KeyEvent) } -func (c *softwareCanvas) MinSize() fyne.Size { +func (c *SoftwareCanvas) MinSize() fyne.Size { // TODO implement me panic("implement me") } @@ -66,19 +66,20 @@ func Canvas() WindowlessCanvas { // NewCanvas returns a single use in-memory canvas used for testing. // This canvas has no painter so calls to Capture() will return a blank image. func NewCanvas() WindowlessCanvas { - c := &softwareCanvas{ + c := &SoftwareCanvas{ focusMgr: app.NewFocusManager(nil), padded: true, scale: 1.0, size: fyne.NewSize(10, 10), } + c.Initialize(c, nil) return c } // NewCanvasWithPainter allows creation of an in-memory canvas with a specific painter. // The painter will be used to render in the Capture() call. func NewCanvasWithPainter(painter painter.Painter) WindowlessCanvas { - canvas := NewCanvas().(*softwareCanvas) + canvas := NewCanvas().(*SoftwareCanvas) canvas.SetPainter(painter) return canvas @@ -89,16 +90,17 @@ func NewCanvasWithPainter(painter painter.Painter) WindowlessCanvas { // // Since: 2.2 func NewTransparentCanvasWithPainter(painter painter.Painter) WindowlessCanvas { - canvas := NewCanvasWithPainter(painter).(*softwareCanvas) + canvas := NewCanvasWithPainter(painter).(*SoftwareCanvas) canvas.transparent = true return canvas } -func (c *softwareCanvas) Capture() image.Image { +func (c *SoftwareCanvas) Capture() image.Image { cache.Clean(true) bounds := image.Rect(0, 0, scale.ToScreenCoordinate(c, c.Size().Width), scale.ToScreenCoordinate(c, c.Size().Height)) var img *image.NRGBA + c.FreeDirtyTextures() if !c.transparent { img = image.NewNRGBA(bounds) // TODO: this is slow, and is slower if the bg color is not color.NRGBA @@ -118,47 +120,78 @@ func (c *softwareCanvas) Capture() image.Image { return img } -func (c *softwareCanvas) Content() fyne.CanvasObject { +func (c *SoftwareCanvas) Content() fyne.CanvasObject { c.RLock() defer c.RUnlock() return c.content } -func (c *softwareCanvas) findObjectAtPositionMatching(pos fyne.Position, test func(object fyne.CanvasObject) bool) (fyne.CanvasObject, fyne.Position, int) { +func (c *SoftwareCanvas) Hovered() desktop.Hoverable { + c.RLock() + defer c.RUnlock() + + return c.hovered +} + +func (c *SoftwareCanvas) IsTransparent() bool { + c.RLock() + defer c.RUnlock() + + return c.transparent +} + +func (c *SoftwareCanvas) SetTransparent(transparent bool) { + c.Lock() + c.transparent = transparent + c.Unlock() +} + +func (c *SoftwareCanvas) SetHovered(hovered desktop.Hoverable) { + c.Lock() + defer c.Unlock() + + c.hovered = hovered +} + +func (c *SoftwareCanvas) findObjectAtPositionMatching(pos fyne.Position, test func(object fyne.CanvasObject) bool) (fyne.CanvasObject, fyne.Position, int) { return driver.FindObjectAtPositionMatching(pos, test, c.Overlays().Top(), c.content) } -func (c *softwareCanvas) InteractiveArea() (fyne.Position, fyne.Size) { +func (c *SoftwareCanvas) InteractiveArea() (fyne.Position, fyne.Size) { return fyne.Position{}, c.Size() } -func (c *softwareCanvas) OnTypedKey() func(*fyne.KeyEvent) { +func (c *SoftwareCanvas) OnTypedKey() func(*fyne.KeyEvent) { c.RLock() defer c.RUnlock() return c.onTypedKey } -func (c *softwareCanvas) OnTypedRune() func(rune) { +func (c *SoftwareCanvas) OnTypedRune() func(rune) { c.RLock() defer c.RUnlock() return c.onTypedRune } -func (c *softwareCanvas) Padded() bool { +func (c *SoftwareCanvas) Padded() bool { c.RLock() defer c.RUnlock() return c.padded } -func (c *softwareCanvas) PixelCoordinateForPosition(pos fyne.Position) (int, int) { +func (c *SoftwareCanvas) PixelCoordinateForPosition(pos fyne.Position) (int, int) { return int(float32(pos.X) * c.scale), int(float32(pos.Y) * c.scale) } -func (c *softwareCanvas) Resize(size fyne.Size) { +func (c *SoftwareCanvas) Resize(size fyne.Size) { + if size == c.size { + return + } + c.Lock() content := c.content overlays := c.Overlays() @@ -182,31 +215,33 @@ func (c *softwareCanvas) Resize(size fyne.Size) { p.Refresh() } else { overlay.Resize(size) + // overlay.Move(fyne.NewSquareOffsetPos(theme.Padding())) } } if padded { - content.Resize(size.Subtract(fyne.NewSize(theme.Padding()*2, theme.Padding()*2))) - content.Move(fyne.NewPos(theme.Padding(), theme.Padding())) + content.Resize(size.Subtract(fyne.NewSquareSize(theme.Padding() * 2))) + content.Move(fyne.NewSquareOffsetPos(theme.Padding())) } else { content.Resize(size) content.Move(fyne.NewPos(0, 0)) } } -func (c *softwareCanvas) Scale() float32 { +func (c *SoftwareCanvas) Scale() float32 { c.RLock() defer c.RUnlock() return c.scale } -func (c *softwareCanvas) SetContent(content fyne.CanvasObject) { - content.Resize(content.MinSize()) +func (c *SoftwareCanvas) SetContent(content fyne.CanvasObject) { + // if content != nil { + // content.Resize(content.MinSize()) + // } c.Lock() - c.content = content - c.focusMgr = app.NewFocusManager(c.content) + c.setContent(content) c.Unlock() if content == nil { @@ -215,27 +250,27 @@ func (c *softwareCanvas) SetContent(content fyne.CanvasObject) { padding := fyne.NewSize(0, 0) if c.padded { - padding = fyne.NewSize(theme.Padding()*2, theme.Padding()*2) + padding = fyne.NewSquareSize(theme.Padding() * 2) } c.Resize(content.MinSize().Add(padding)) c.SetDirty() } -func (c *softwareCanvas) SetOnTypedKey(handler func(*fyne.KeyEvent)) { +func (c *SoftwareCanvas) SetOnTypedKey(handler func(*fyne.KeyEvent)) { c.Lock() defer c.Unlock() c.onTypedKey = handler } -func (c *softwareCanvas) SetOnTypedRune(handler func(rune)) { +func (c *SoftwareCanvas) SetOnTypedRune(handler func(rune)) { c.Lock() defer c.Unlock() c.onTypedRune = handler } -func (c *softwareCanvas) SetPadded(padded bool) { +func (c *SoftwareCanvas) SetPadded(padded bool) { c.Lock() c.padded = padded c.Unlock() @@ -243,21 +278,30 @@ func (c *softwareCanvas) SetPadded(padded bool) { c.Resize(c.Size()) } -func (c *softwareCanvas) SetScale(scale float32) { +func (c *SoftwareCanvas) SetScale(scale float32) { c.Lock() defer c.Unlock() c.scale = scale } -func (c *softwareCanvas) Size() fyne.Size { +func (c *SoftwareCanvas) Size() fyne.Size { c.RLock() defer c.RUnlock() return c.size } -func (c *softwareCanvas) objectTrees() []fyne.CanvasObject { +// canvasSize computes the needed canvas size for the given content size +func (c *SoftwareCanvas) canvasSize(contentSize fyne.Size) fyne.Size { + canvasSize := contentSize.Add(fyne.NewSize(0, 0)) + if c.padded { + return canvasSize.Add(fyne.NewSquareSize(theme.Padding() * 2)) + } + return canvasSize +} + +func (c *SoftwareCanvas) objectTrees() []fyne.CanvasObject { trees := make([]fyne.CanvasObject, 0, len(c.Overlays().List())+1) if c.content != nil { trees = append(trees, c.content) @@ -266,27 +310,12 @@ func (c *softwareCanvas) objectTrees() []fyne.CanvasObject { return trees } -func layoutAndCollect(objects []fyne.CanvasObject, o fyne.CanvasObject, size fyne.Size) []fyne.CanvasObject { - objects = append(objects, o) - switch c := o.(type) { - case fyne.Widget: - r := c.CreateRenderer() - r.Layout(size) - for _, child := range r.Objects() { - objects = layoutAndCollect(objects, child, child.Size()) - } - case *fyne.Container: - if c.Layout != nil { - c.Layout.Layout(c.Objects, size) - } - for _, child := range c.Objects { - objects = layoutAndCollect(objects, child, child.Size()) - } - } - return objects +func (c *SoftwareCanvas) setContent(content fyne.CanvasObject) { + c.content = content + c.SetContentTreeAndFocusMgr(content) } -func (c *softwareCanvas) tapDown(pos fyne.Position, tapID int) { +func (c *SoftwareCanvas) tapDown(pos fyne.Position, tapID int) { // c.lastTapDown[tapID] = time.Now() // c.lastTapDownPos[tapID] = pos // c.dragging = nil @@ -315,7 +344,7 @@ func (c *softwareCanvas) tapDown(pos fyne.Position, tapID int) { } } -// func (c *softwareCanvas) tapMove(pos fyne.Position, tapID int, +// func (c *SoftwareCanvas) tapMove(pos fyne.Position, tapID int, // // dragCallback func(fyne.Draggable, *fyne.DragEvent)) { // previousPos := c.lastTapDownPos[tapID] @@ -364,7 +393,7 @@ func (c *softwareCanvas) tapDown(pos fyne.Position, tapID int) { // // dragCallback(c.dragging, ev) // } -func (c *softwareCanvas) tapUp(pos fyne.Position, tapID int, +func (c *SoftwareCanvas) tapUp(pos fyne.Position, tapID int, tapCallback func(fyne.Tappable, *fyne.PointEvent), tapAltCallback func(fyne.SecondaryTappable, *fyne.PointEvent), doubleTapCallback func(fyne.DoubleTappable, *fyne.PointEvent), diff --git a/test/testcanvas_test.go b/internal/driver/software/canvas_test.go similarity index 95% rename from test/testcanvas_test.go rename to internal/driver/software/canvas_test.go index 9796b210e5..9ad4d927cc 100644 --- a/test/testcanvas_test.go +++ b/internal/driver/software/canvas_test.go @@ -1,4 +1,4 @@ -package test +package software import ( "image/color" @@ -43,7 +43,7 @@ func TestTestCanvas_TransparentCapture(t *testing.T) { } func TestGlCanvas_PixelCoordinateAtPosition(t *testing.T) { - c := NewCanvas().(*testCanvas) + c := NewCanvas().(*SoftwareCanvas) pos := fyne.NewPos(4, 4) c.scale = 2.5 diff --git a/test/testclipboard.go b/internal/driver/software/clipboard.go similarity index 55% rename from test/testclipboard.go rename to internal/driver/software/clipboard.go index d98f689aa0..4b12371890 100644 --- a/test/testclipboard.go +++ b/internal/driver/software/clipboard.go @@ -1,20 +1,20 @@ -package test +package software import "fyne.io/fyne/v2" -type testClipboard struct { +type clipboard struct { content string } -func (c *testClipboard) Content() string { +func (c *clipboard) Content() string { return c.content } -func (c *testClipboard) SetContent(content string) { +func (c *clipboard) SetContent(content string) { c.content = content } // NewClipboard returns a single use in-memory clipboard used for testing func NewClipboard() fyne.Clipboard { - return &testClipboard{} + return &clipboard{} } diff --git a/internal/driver/software/driver.go b/internal/driver/software/driver.go index eb1e29245d..dfa4d53aaf 100644 --- a/internal/driver/software/driver.go +++ b/internal/driver/software/driver.go @@ -21,7 +21,7 @@ import ( "fyne.io/fyne/v2/storage/repository" ) -type softwareDriver struct { +type SoftwareDriver struct { device fyne.Device painter painter.Painter windows []fyne.Window @@ -35,7 +35,7 @@ type softwareDriver struct { } // Declare conformity with Driver -var _ fyne.Driver = (*softwareDriver)(nil) +var _ fyne.Driver = (*SoftwareDriver)(nil) type device struct { } @@ -73,7 +73,7 @@ func (d *device) IsMobile() bool { // NewDriver sets up and registers a new dummy driver for test purpose func NewDriver(painter func(image.Image, []image.Rectangle), events chan any) fyne.Driver { - drv := &softwareDriver{ + drv := &SoftwareDriver{ windowsMutex: sync.RWMutex{}, Output: painter, device: &device{}, @@ -90,37 +90,38 @@ func NewDriver(painter func(image.Image, []image.Rectangle), events chan any) fy // NewDriverWithPainter creates a new dummy driver that will pass the given // painter to all canvases created func NewDriverWithPainter(painter painter.Painter) fyne.Driver { - return &softwareDriver{ + return &SoftwareDriver{ painter: painter, windowsMutex: sync.RWMutex{}, + device: &device{}, } } -func (d *softwareDriver) AbsolutePositionForObject(co fyne.CanvasObject) fyne.Position { +func (d *SoftwareDriver) AbsolutePositionForObject(co fyne.CanvasObject) fyne.Position { c := d.CanvasForObject(co) if c == nil { return fyne.NewPos(0, 0) } - tc := c.(*softwareCanvas) + tc := c.(*SoftwareCanvas) return driver.AbsolutePositionForObject(co, tc.objectTrees()) } -func (d *softwareDriver) AllWindows() []fyne.Window { +func (d *SoftwareDriver) AllWindows() []fyne.Window { d.windowsMutex.RLock() defer d.windowsMutex.RUnlock() return d.windows } -func (d *softwareDriver) CanvasForObject(fyne.CanvasObject) fyne.Canvas { +func (d *SoftwareDriver) CanvasForObject(fyne.CanvasObject) fyne.Canvas { d.windowsMutex.RLock() defer d.windowsMutex.RUnlock() // cheating: probably the last created window is meant return d.windows[len(d.windows)-1].Canvas() } -func (d *softwareDriver) CreateWindow(string) fyne.Window { - canvas := NewTransparentCanvas().(*softwareCanvas) +func (d *SoftwareDriver) CreateWindow(string) fyne.Window { + canvas := NewCanvas().(*SoftwareCanvas) if d.painter != nil { canvas.SetPainter(d.painter) } else { @@ -129,8 +130,8 @@ func (d *softwareDriver) CreateWindow(string) fyne.Window { canvas.Initialize(canvas, canvas.SetDirty) - window := &softwareWindow{canvas: canvas, driver: d} - // window.clipboard = &testClipboard{} + window := &SoftwareWindow{canvas: canvas, driver: d} + window.clipboard = NewClipboard() window.InitEventQueue() go window.RunEventQueue() @@ -140,26 +141,26 @@ func (d *softwareDriver) CreateWindow(string) fyne.Window { return window } -func (d *softwareDriver) CurrentWindow() *softwareWindow { +func (d *SoftwareDriver) CurrentWindow() *SoftwareWindow { d.windowsMutex.RLock() defer d.windowsMutex.RUnlock() if len(d.windows) == 0 { return nil } - return d.windows[len(d.windows)-1].(*softwareWindow) + return d.windows[len(d.windows)-1].(*SoftwareWindow) } -func (d *softwareDriver) Device() fyne.Device { +func (d *SoftwareDriver) Device() fyne.Device { return d.device } -func (d *softwareDriver) handlePaint(w *softwareWindow) { +func (d *SoftwareDriver) handlePaint(w *SoftwareWindow) { if !d.painting.CompareAndSwap(false, true) { return } defer d.painting.Store(false) - c := w.Canvas().(*softwareCanvas) + c := w.Canvas().(*SoftwareCanvas) // d.painting = false if c.Painter() == nil { c.SetPainter(software.NewPainter()) @@ -180,18 +181,20 @@ func (d *softwareDriver) handlePaint(w *softwareWindow) { // w.Resize(newSize) // } - d.Output(c.Capture(), c.Painter().(*software.Painter).DirtyRects()) + if d.Output != nil { + d.Output(c.Capture(), nil) + } fmt.Println("painting took", time.Since(t)) } cache.Clean(canvasNeedRefresh > 0) } // RenderedTextSize looks up how bit a string would be if drawn on screen -func (d *softwareDriver) RenderedTextSize(text string, size float32, style fyne.TextStyle) (fyne.Size, float32) { +func (d *SoftwareDriver) RenderedTextSize(text string, size float32, style fyne.TextStyle) (fyne.Size, float32) { return painter.RenderedTextSize(text, size, style) } -func (d *softwareDriver) Run() { +func (d *SoftwareDriver) Run() { if !d.running.CompareAndSwap(false, true) { return // Run was called twice. } @@ -200,10 +203,10 @@ func (d *softwareDriver) Run() { fyne.CurrentApp().Settings().AddChangeListener(settingsChange) draw := time.NewTicker(time.Second / 15) - // make sure we have a theme set - painter.ClearFontCache() - cache.ResetThemeCaches() - intapp.ApplyThemeTo(d.CurrentWindow().Canvas().Content(), d.CurrentWindow().Canvas()) + // // make sure we have a theme set + // painter.ClearFontCache() + // cache.ResetThemeCaches() + // intapp.ApplyThemeTo(d.CurrentWindow().Canvas().Content(), d.CurrentWindow().Canvas()) for d.running.Load() { select { @@ -222,7 +225,7 @@ func (d *softwareDriver) Run() { if current == nil { continue } - // c := current.Canvas().(*softwareCanvas) + // c := current.Canvas().(*SoftwareCanvas) switch e := e.(type) { // case lifecycle.Event: @@ -260,31 +263,34 @@ func (d *softwareDriver) Run() { case touch.TypeEnd: d.tapUpCanvas(current, e.X, e.Y, e.Sequence) } - // case key.Event: - // if e.Direction == key.DirPress { - // d.typeDownCanvas(c, e.Rune, e.Code, e.Modifiers) - // } else if e.Direction == key.DirRelease { - // d.typeUpCanvas(c, e.Rune, e.Code, e.Modifiers) - // } + // case key.Event: + // if e.Direction == key.DirPress { + // d.typeDownCanvas(c, e.Rune, e.Code, e.Modifiers) + // } else if e.Direction == key.DirRelease { + // d.typeUpCanvas(c, e.Rune, e.Code, e.Modifiers) + // } + case fyne.PointEvent: + d.tapDownCanvas(current, e.Position.X, e.Position.Y, 0) + d.tapUpCanvas(current, e.Position.X, e.Position.Y, 0) } } } } -func (d *softwareDriver) StartAnimation(a *fyne.Animation) { +func (d *SoftwareDriver) StartAnimation(a *fyne.Animation) { // currently no animations in test app, we just initialise it and leave a.Tick(1.0) } -func (d *softwareDriver) StopAnimation(a *fyne.Animation) { +func (d *SoftwareDriver) StopAnimation(a *fyne.Animation) { // currently no animations in test app, do nothing } -func (d *softwareDriver) Quit() { +func (d *SoftwareDriver) Quit() { d.running.Store(false) } -func (d *softwareDriver) removeWindow(w *softwareWindow) { +func (d *SoftwareDriver) removeWindow(w *SoftwareWindow) { d.windowsMutex.Lock() i := 0 for _, window := range d.windows { @@ -298,14 +304,14 @@ func (d *softwareDriver) removeWindow(w *softwareWindow) { d.windowsMutex.Unlock() } -func (d *softwareDriver) DoubleTapDelay() time.Duration { +func (d *SoftwareDriver) DoubleTapDelay() time.Duration { return 300 * time.Millisecond } -func (d *softwareDriver) SetDisableScreenBlanking(_ bool) { +func (d *SoftwareDriver) SetDisableScreenBlanking(_ bool) { // no-op for test } -func (d *softwareDriver) tapDownCanvas(w *softwareWindow, x, y float32, tapID touch.Sequence) { +func (d *SoftwareDriver) tapDownCanvas(w *SoftwareWindow, x, y float32, tapID touch.Sequence) { tapX := scale.ToFyneCoordinate(w.canvas, int(x)) tapY := scale.ToFyneCoordinate(w.canvas, int(y)) pos := fyne.NewPos(tapX, tapY) @@ -315,7 +321,7 @@ func (d *softwareDriver) tapDownCanvas(w *softwareWindow, x, y float32, tapID to w.canvas.tapDown(pos, int(tapID)) } -// func (d *softwareDriver) tapMoveCanvas(w *softwareWindow, x, y float32, tapID touch.Sequence) { +// func (d *SoftwareDriver) tapMoveCanvas(w *SoftwareWindow, x, y float32, tapID touch.Sequence) { // tapX := scale.ToFyneCoordinate(w.canvas, int(x)) // tapY := scale.ToFyneCoordinate(w.canvas, int(y)) // pos := fyne.NewPos(tapX, tapY+tapYOffset) @@ -324,7 +330,7 @@ func (d *softwareDriver) tapDownCanvas(w *softwareWindow, x, y float32, tapID to // w.QueueEvent(func() { wid.Dragged(ev) }) // }) // } -func (d *softwareDriver) tapUpCanvas(w *softwareWindow, x, y float32, tapID touch.Sequence) { +func (d *SoftwareDriver) tapUpCanvas(w *SoftwareWindow, x, y float32, tapID touch.Sequence) { tapX := scale.ToFyneCoordinate(w.canvas, int(x)) tapY := scale.ToFyneCoordinate(w.canvas, int(y)) pos := fyne.NewPos(tapX, tapY) diff --git a/test/testfile.go b/internal/driver/software/file.go similarity index 86% rename from test/testfile.go rename to internal/driver/software/file.go index 9e986a7a6a..eefbaac7ab 100644 --- a/test/testfile.go +++ b/internal/driver/software/file.go @@ -1,4 +1,4 @@ -package test +package software import ( "fmt" @@ -55,15 +55,15 @@ func openFile(uri fyne.URI, create bool) (*file, error) { return &file{File: f, path: path}, err } -func (d *testDriver) FileReaderForURI(uri fyne.URI) (fyne.URIReadCloser, error) { +func (d *SoftwareDriver) FileReaderForURI(uri fyne.URI) (fyne.URIReadCloser, error) { return openFile(uri, false) } -func (d *testDriver) FileWriterForURI(uri fyne.URI) (fyne.URIWriteCloser, error) { +func (d *SoftwareDriver) FileWriterForURI(uri fyne.URI) (fyne.URIWriteCloser, error) { return openFile(uri, true) } -func (d *testDriver) ListerForURI(uri fyne.URI) (fyne.ListableURI, error) { +func (d *SoftwareDriver) ListerForURI(uri fyne.URI) (fyne.ListableURI, error) { if uri.Scheme() != "file" { return nil, fmt.Errorf("unsupported URL protocol") } diff --git a/internal/driver/software/window.go b/internal/driver/software/window.go index 0e20b0712f..a4c35d70a4 100644 --- a/internal/driver/software/window.go +++ b/internal/driver/software/window.go @@ -5,7 +5,7 @@ import ( "fyne.io/fyne/v2/internal/driver/common" ) -type softwareWindow struct { +type SoftwareWindow struct { common.Window title string @@ -15,9 +15,9 @@ type softwareWindow struct { onClosed func() onCloseIntercepted func() - canvas *softwareCanvas + canvas *SoftwareCanvas clipboard fyne.Clipboard - driver *softwareDriver + driver *SoftwareDriver menu *fyne.MainMenu } @@ -25,22 +25,23 @@ type softwareWindow struct { func NewWindow(content fyne.CanvasObject) fyne.Window { window := fyne.CurrentApp().NewWindow("") window.SetContent(content) + window.(*SoftwareWindow).clipboard = NewClipboard() return window } -func (w *softwareWindow) Canvas() fyne.Canvas { +func (w *SoftwareWindow) Canvas() fyne.Canvas { return w.canvas } -func (w *softwareWindow) CenterOnScreen() { +func (w *SoftwareWindow) CenterOnScreen() { // no-op } -func (w *softwareWindow) Clipboard() fyne.Clipboard { +func (w *SoftwareWindow) Clipboard() fyne.Clipboard { return w.clipboard } -func (w *softwareWindow) Close() { +func (w *SoftwareWindow) Close() { if w.onClosed != nil { w.onClosed() } @@ -48,99 +49,99 @@ func (w *softwareWindow) Close() { w.driver.removeWindow(w) } -func (w *softwareWindow) Content() fyne.CanvasObject { +func (w *SoftwareWindow) Content() fyne.CanvasObject { return w.Canvas().Content() } -func (w *softwareWindow) FixedSize() bool { +func (w *SoftwareWindow) FixedSize() bool { return w.fixedSize } -func (w *softwareWindow) FullScreen() bool { +func (w *SoftwareWindow) FullScreen() bool { return w.fullScreen } -func (w *softwareWindow) Hide() { +func (w *SoftwareWindow) Hide() { w.focused = false } -func (w *softwareWindow) Icon() fyne.Resource { +func (w *SoftwareWindow) Icon() fyne.Resource { return fyne.CurrentApp().Icon() } -func (w *softwareWindow) MainMenu() *fyne.MainMenu { +func (w *SoftwareWindow) MainMenu() *fyne.MainMenu { return w.menu } -func (w *softwareWindow) Padded() bool { +func (w *SoftwareWindow) Padded() bool { return w.canvas.Padded() } -func (w *softwareWindow) RequestFocus() { +func (w *SoftwareWindow) RequestFocus() { for _, win := range w.driver.AllWindows() { - win.(*softwareWindow).focused = false + win.(*SoftwareWindow).focused = false } w.focused = true } -func (w *softwareWindow) Resize(size fyne.Size) { +func (w *SoftwareWindow) Resize(size fyne.Size) { w.canvas.Resize(size) } -func (w *softwareWindow) SetContent(obj fyne.CanvasObject) { +func (w *SoftwareWindow) SetContent(obj fyne.CanvasObject) { w.Canvas().SetContent(obj) } -func (w *softwareWindow) SetFixedSize(fixed bool) { +func (w *SoftwareWindow) SetFixedSize(fixed bool) { w.fixedSize = fixed } -func (w *softwareWindow) SetIcon(_ fyne.Resource) { +func (w *SoftwareWindow) SetIcon(_ fyne.Resource) { // no-op } -func (w *softwareWindow) SetFullScreen(fullScreen bool) { +func (w *SoftwareWindow) SetFullScreen(fullScreen bool) { w.fullScreen = fullScreen } -func (w *softwareWindow) SetMainMenu(menu *fyne.MainMenu) { +func (w *SoftwareWindow) SetMainMenu(menu *fyne.MainMenu) { w.menu = menu } -func (w *softwareWindow) SetMaster() { +func (w *SoftwareWindow) SetMaster() { // no-op } -func (w *softwareWindow) SetOnClosed(closed func()) { +func (w *SoftwareWindow) SetOnClosed(closed func()) { w.onClosed = closed } -func (w *softwareWindow) SetCloseIntercept(callback func()) { +func (w *SoftwareWindow) SetCloseIntercept(callback func()) { w.onCloseIntercepted = callback } -func (w *softwareWindow) SetOnDropped(dropped func(fyne.Position, []fyne.URI)) { +func (w *SoftwareWindow) SetOnDropped(dropped func(fyne.Position, []fyne.URI)) { } -func (w *softwareWindow) SetPadded(padded bool) { +func (w *SoftwareWindow) SetPadded(padded bool) { w.canvas.SetPadded(padded) } -func (w *softwareWindow) SetTitle(title string) { +func (w *SoftwareWindow) SetTitle(title string) { w.title = title } -func (w *softwareWindow) Show() { +func (w *SoftwareWindow) Show() { w.RequestFocus() } -func (w *softwareWindow) ShowAndRun() { +func (w *SoftwareWindow) ShowAndRun() { w.Show() w.driver.Run() } -func (w *softwareWindow) Title() string { +func (w *SoftwareWindow) Title() string { return w.title } diff --git a/internal/overlay_stack_test.go b/internal/overlay_stack_test.go index 8baaf159fd..77829e47e7 100644 --- a/internal/overlay_stack_test.go +++ b/internal/overlay_stack_test.go @@ -8,12 +8,12 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/internal" "fyne.io/fyne/v2/internal/app" - "fyne.io/fyne/v2/test" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/widget" ) func TestOverlayStack(t *testing.T) { - s := &internal.OverlayStack{Canvas: test.NewCanvas()} + s := &internal.OverlayStack{Canvas: software.NewCanvas()} o1 := widget.NewLabel("A") o2 := widget.NewLabel("B") o3 := widget.NewLabel("C") diff --git a/internal/painter/image_test.go b/internal/painter/image_test.go index 14c1efb2ba..b8f5b1ef85 100644 --- a/internal/painter/image_test.go +++ b/internal/painter/image_test.go @@ -3,18 +3,20 @@ package painter_test import ( "testing" + "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + canvas2 "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/internal/painter" - "fyne.io/fyne/v2/internal/painter/software" + softwarePainter "fyne.io/fyne/v2/internal/painter/software" "fyne.io/fyne/v2/test" - "github.com/stretchr/testify/assert" ) func TestPaintImage_MinSize(t *testing.T) { img := canvas.NewImageFromFile("testdata/svg-stroke-default.png") img.FillMode = canvas.ImageFillOriginal - c := test.NewCanvasWithPainter(software.NewPainter()) + c := canvas2.NewCanvasWithPainter(softwarePainter.NewPainter()) c.SetScale(1.0) c.SetContent(img) @@ -30,7 +32,7 @@ func TestPaintImage_MinSize(t *testing.T) { func TestPaintImageWithBadSVGElement(t *testing.T) { img := canvas.NewImageFromFile("testdata/stroke-bad-element-data.svg") - c := test.NewCanvasWithPainter(software.NewPainter()) + c := canvas2.NewCanvasWithPainter(softwarePainter.NewPainter()) c.SetContent(img) c.Resize(fyne.NewSize(480, 240)) img.Refresh() @@ -75,7 +77,7 @@ func TestPaintImage_SVG(t *testing.T) { } { t.Run(name, func(t *testing.T) { img := canvas.NewImageFromFile("testdata/stroke.svg") - c := test.NewCanvasWithPainter(software.NewPainter()) + c := canvas2.NewCanvasWithPainter(softwarePainter.NewPainter()) c.SetContent(img) c.Resize(fyne.NewSize(tt.width, tt.height)) img.Refresh() diff --git a/internal/painter/software/painter.go b/internal/painter/software/painter.go index 4516dd3589..6ae015e38b 100644 --- a/internal/painter/software/painter.go +++ b/internal/painter/software/painter.go @@ -44,7 +44,7 @@ func (p *Painter) Capture(c fyne.Canvas) image.Image { paint := func(obj fyne.CanvasObject, pos, clipPos fyne.Position, clipSize fyne.Size) bool { shouldTest := true - shouldPaint := false + shouldPaint := true switch obj.(type) { case *fyne.Container, fyne.Widget: @@ -57,6 +57,7 @@ func (p *Painter) Capture(c fyne.Canvas) image.Image { } if shouldTest { + // TODO: This breaks a bunch of tests, because by default it'll return mostly blank images shouldPaint = driver.WalkVisibleObjectTree(obj, func(obj fyne.CanvasObject, _, _ fyne.Position, _ fyne.Size) bool { switch obj.(type) { case *fyne.Container, fyne.Widget: diff --git a/internal/painter/software/painter_test.go b/internal/painter/software/painter_test.go index a80dcc9527..aae84aa766 100644 --- a/internal/painter/software/painter_test.go +++ b/internal/painter/software/painter_test.go @@ -8,7 +8,8 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" - "fyne.io/fyne/v2/internal/painter/software" + canvas2 "fyne.io/fyne/v2/internal/driver/software" + painter "fyne.io/fyne/v2/internal/painter/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -23,11 +24,11 @@ func TestPainter_paintCircle(t *testing.T) { test.ApplyTheme(t, test.Theme()) obj := canvas.NewCircle(color.Black) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(true) c.SetContent(obj) c.Resize(fyne.NewSize(70+2*theme.Padding(), 70+2*theme.Padding())) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_circle.png", p.Capture(c)) } @@ -38,11 +39,11 @@ func TestPainter_paintCircleStroke(t *testing.T) { obj.StrokeColor = color.Black obj.StrokeWidth = 4 - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(true) c.SetContent(obj) c.Resize(fyne.NewSize(70+2*theme.Padding(), 70+2*theme.Padding())) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_circle_stroke.png", p.Capture(c)) } @@ -56,11 +57,11 @@ func TestPainter_paintGradient_clipped(t *testing.T) { scroll.Resize(fyne.NewSize(50, 50)) scroll.Scrolled(&fyne.ScrollEvent{Scrolled: fyne.NewDelta(-30, -30)}) cont := container.NewWithoutLayout(scroll) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(cont) c.Resize(fyne.NewSize(70, 70)) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_gradient_clipped.png", p.Capture(c)) } @@ -68,11 +69,11 @@ func TestPainter_paintGradient_clipped(t *testing.T) { func TestPainter_paintImage(t *testing.T) { img := canvas.NewImageFromImage(makeTestImage(3, 3)) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(50, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_default.png", target) @@ -88,11 +89,11 @@ func TestPainter_paintImage_clipped(t *testing.T) { scroll.Resize(fyne.NewSize(50, 50)) scroll.Scrolled(&fyne.ScrollEvent{Scrolled: fyne.NewDelta(-15, -15)}) cont := container.NewWithoutLayout(scroll) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(cont) c.Resize(fyne.NewSize(70, 70)) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_image_clipped.png", p.Capture(c)) } @@ -101,11 +102,11 @@ func TestPainter_paintImage_scalePixels(t *testing.T) { img := canvas.NewImageFromImage(makeTestImage(3, 3)) img.ScaleMode = canvas.ImageScalePixels - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(50, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_ImageScalePixels.png", target) @@ -115,11 +116,11 @@ func TestPainter_paintImage_scaleSmooth(t *testing.T) { img := canvas.NewImageFromImage(makeTestImage(3, 3)) img.ScaleMode = canvas.ImageScaleSmooth - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(50, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_ImageScaleSmooth.png", target) @@ -129,33 +130,33 @@ func TestPainter_paintImage_scaleFastest(t *testing.T) { img := canvas.NewImageFromImage(makeTestImage(3, 3)) img.ScaleMode = canvas.ImageScaleFastest - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(50, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_ImageScaleFastest.png", target) } func TestPainter_paintImage_stretchX(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(canvas.NewImageFromImage(makeTestImage(3, 3))) c.Resize(fyne.NewSize(100, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_stretchx.png", target) } func TestPainter_paintImage_stretchY(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(canvas.NewImageFromImage(makeTestImage(3, 3))) c.Resize(fyne.NewSize(50, 100)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_stretchy.png", target) @@ -166,11 +167,11 @@ func TestPainter_paintImage_contain(t *testing.T) { img.FillMode = canvas.ImageFillContain img.ScaleMode = canvas.ImageScalePixels - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(50, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_contain.png", target) @@ -182,11 +183,11 @@ func TestPainter_paintImage_containX(t *testing.T) { img.FillMode = canvas.ImageFillContain img.ScaleMode = canvas.ImageScalePixels - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(100, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_containx.png", target) @@ -198,11 +199,11 @@ func TestPainter_paintImage_containY(t *testing.T) { img.FillMode = canvas.ImageFillContain img.ScaleMode = canvas.ImageScalePixels - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(50, 100)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_image_containy.png", target) @@ -213,17 +214,17 @@ func TestPainter_paintLine(t *testing.T) { obj := canvas.NewLine(color.Black) obj.StrokeWidth = 6 - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(true) c.SetContent(obj) c.Resize(fyne.NewSize(70+2*theme.Padding(), 70+2*theme.Padding())) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_line.png", p.Capture(c)) } func TestPainter_paintLine_thin(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() lines := [5]*canvas.Line{} sws := []float32{4, 2, 1, 0.5, 0.3} for i, sw := range sws { @@ -236,7 +237,7 @@ func TestPainter_paintLine_thin(t *testing.T) { c.SetContent(container.NewWithoutLayout(lines[0], lines[1], lines[2], lines[3], lines[4])) c.Resize(fyne.NewSize(109, 28)) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_line_thin.png", p.Capture(c)) } @@ -250,11 +251,11 @@ func TestPainter_paintRaster(t *testing.T) { return color.Black }) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.Resize(fyne.NewSize(50, 50)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_raster.png", target) @@ -270,12 +271,12 @@ func TestPainter_paintRaster_scaled(t *testing.T) { return color.Black }) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(img) c.SetScale(5.0) c.Resize(fyne.NewSize(5, 5)) - p := software.NewPainter() + p := painter.NewPainter() target := p.Capture(c) test.AssertImageMatches(t, "draw_raster_scale.png", target) @@ -310,11 +311,11 @@ func TestPainter_paintRectangle_clipped(t *testing.T) { scroll.Resize(fyne.NewSize(50, 50)) scroll.Scrolled(&fyne.ScrollEvent{Scrolled: fyne.NewDelta(-10, -10)}) cont := container.NewWithoutLayout(scroll) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(cont) c.Resize(fyne.NewSize(70, 70)) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_rect_clipped.png", p.Capture(c)) } @@ -325,11 +326,11 @@ func TestPainter_paintRectangle_stroke(t *testing.T) { obj.StrokeWidth = 5 obj.StrokeColor = &color.RGBA{R: 0xFF, G: 0x33, B: 0x33, A: 0xFF} - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(true) c.SetContent(obj) c.Resize(fyne.NewSize(70+2*theme.Padding(), 70+2*theme.Padding())) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_rectangle_stroke.png", p.Capture(c)) } @@ -341,11 +342,11 @@ func TestPainter_paintText_clipped(t *testing.T) { scroll.Resize(fyne.NewSize(50, 50)) scroll.Scrolled(&fyne.ScrollEvent{Scrolled: fyne.NewDelta(-10, -10)}) cont := container.NewWithoutLayout(scroll) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(cont) c.Resize(fyne.NewSize(70, 70)) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_text_clipped.png", p.Capture(c)) } @@ -356,11 +357,11 @@ func TestPainter_paintText_boldItalicClip(t *testing.T) { text.TextStyle.Bold = true text.TextStyle.Italic = true text.TextSize = 42 - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(text) c.Resize(fyne.NewSize(70, text.MinSize().Height)) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_text_bolditalic.png", p.Capture(c)) } @@ -369,13 +370,13 @@ func TestPainter_paintText_scale2(t *testing.T) { test.ApplyTheme(t, test.Theme()) text := canvas.NewText("scale2", theme.ForegroundColor()) text.TextSize = 18 - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(text) c.Resize(fyne.NewSize(70, text.MinSize().Height)) c.SetScale(2) - p := software.NewPainter() + p := painter.NewPainter() test.AssertImageMatches(t, "draw_text_scale2.png", p.Capture(c)) } diff --git a/internal/widget/shadow_test.go b/internal/widget/shadow_test.go index e27e7cbafc..bc37f421a9 100644 --- a/internal/widget/shadow_test.go +++ b/internal/widget/shadow_test.go @@ -4,6 +4,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/test" @@ -17,7 +18,7 @@ func TestShadow_ApplyTheme(t *testing.T) { defer test.NewApp() s := widget.NewShadow(widget.ShadowAround, shadowLevel) - w := test.NewWindow(s) + w := software.NewWindow(s) defer w.Close() w.Resize(fyne.NewSize(50, 50)) @@ -34,7 +35,7 @@ func TestShadow_AroundShadow(t *testing.T) { defer test.NewApp() s := widget.NewShadow(widget.ShadowAround, shadowLevel) - w := test.NewWindow(s) + w := software.NewWindow(s) defer w.Close() w.Resize(fyne.NewSize(50, 50)) @@ -48,7 +49,7 @@ func TestShadow_Transparency(t *testing.T) { defer test.NewApp() s := widget.NewShadow(widget.ShadowAround, shadowLevel) - w := test.NewWindow(s) + w := software.NewWindow(s) defer w.Close() w.Resize(fyne.NewSize(50, 50)) @@ -66,7 +67,7 @@ func TestShadow_BottomShadow(t *testing.T) { defer test.NewApp() s := widget.NewShadow(widget.ShadowBottom, shadowLevel) - w := test.NewWindow(s) + w := software.NewWindow(s) defer w.Close() w.Resize(fyne.NewSize(50, 50)) @@ -84,7 +85,7 @@ func TestShadow_TopShadow(t *testing.T) { defer test.NewApp() s := widget.NewShadow(widget.ShadowTop, shadowLevel) - w := test.NewWindow(s) + w := software.NewWindow(s) defer w.Close() w.Resize(fyne.NewSize(50, 50)) diff --git a/internal/widget/simple_renderer_test.go b/internal/widget/simple_renderer_test.go index 6445ea097f..41ed149803 100644 --- a/internal/widget/simple_renderer_test.go +++ b/internal/widget/simple_renderer_test.go @@ -6,6 +6,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/test" ) @@ -14,7 +15,7 @@ func TestNewSimpleRenderer(t *testing.T) { r := canvas.NewRectangle(color.Transparent) o := &simpleWidget{obj: r} o.ExtendBaseWidget(o) - w := test.NewWindow(o) + w := software.NewWindow(o) w.Resize(fyne.NewSize(100, 100)) test.AssertRendersToMarkup(t, "simple_renderer.xml", w.Canvas()) diff --git a/test/markup_renderer.go b/test/markup_renderer.go index eaf00ed3c1..8a18fc564b 100644 --- a/test/markup_renderer.go +++ b/test/markup_renderer.go @@ -13,6 +13,7 @@ import ( "fyne.io/fyne/v2/internal/cache" col "fyne.io/fyne/v2/internal/color" "fyne.io/fyne/v2/internal/driver" + canvas2 "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/theme" ) @@ -198,7 +199,7 @@ func (r *markupRenderer) setStringAttr(attrs map[string]*string, name string, s func (r *markupRenderer) writeCanvas(c fyne.Canvas) { attrs := map[string]*string{} r.setSizeAttr(attrs, "size", c.Size()) - if tc, ok := c.(WindowlessCanvas); ok { + if tc, ok := c.(canvas2.WindowlessCanvas); ok { r.setBoolAttr(attrs, "padded", tc.Padded()) } r.writeTag("canvas", false, attrs) diff --git a/test/markup_renderer_test.go b/test/markup_renderer_test.go index 0892db14f0..6e7b23ca5a 100644 --- a/test/markup_renderer_test.go +++ b/test/markup_renderer_test.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" + canvas2 "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -469,7 +470,7 @@ func Test_snapshot(t *testing.T) { }, } { t.Run(name, func(t *testing.T) { - c := NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) c.SetContent(tt.content) c.Resize(fyne.NewSize(100, 100)) @@ -484,7 +485,7 @@ func Test_snapshot(t *testing.T) { } t.Run("canvas with padding", func(t *testing.T) { - c := NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(true) c.SetContent(canvas.NewCircle(color.Black)) c.Resize(fyne.NewSize(100, 100)) @@ -500,7 +501,7 @@ func Test_snapshot(t *testing.T) { }) t.Run("canvas with overlays", func(t *testing.T) { - c := NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(true) c.SetContent(canvas.NewCircle(color.Black)) c.Overlays().Add(canvas.NewRectangle(color.NRGBA{R: 250, G: 250, B: 250, A: 250})) diff --git a/test/test.go b/test/test.go index 6ca12fe8cd..7cd47266d1 100644 --- a/test/test.go +++ b/test/test.go @@ -13,7 +13,8 @@ import ( "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/internal/cache" "fyne.io/fyne/v2/internal/driver" - "fyne.io/fyne/v2/internal/painter/software" + "fyne.io/fyne/v2/internal/driver/software" + painter "fyne.io/fyne/v2/internal/painter/software" "fyne.io/fyne/v2/internal/test" "github.com/stretchr/testify/assert" @@ -38,7 +39,7 @@ func AssertCanvasTappableAt(t *testing.T, c fyne.Canvas, pos fyne.Position) bool // // Since 2.3 func AssertObjectRendersToImage(t *testing.T, masterFilename string, o fyne.CanvasObject, msgAndArgs ...any) bool { - c := NewCanvasWithPainter(software.NewPainter()) + c := software.NewCanvasWithPainter(painter.NewPainter()) c.SetPadded(false) size := o.MinSize().Max(o.Size()) c.SetContent(o) @@ -60,7 +61,7 @@ func AssertObjectRendersToImage(t *testing.T, masterFilename string, o fyne.Canv // // Since 2.3 func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o fyne.CanvasObject, msgAndArgs ...any) bool { - c := NewCanvas() + c := software.NewCanvas() c.SetPadded(false) size := o.MinSize().Max(o.Size()) c.SetContent(o) @@ -153,8 +154,8 @@ func Drag(c fyne.Canvas, pos fyne.Position, deltaX, deltaY float32) { // FocusNext focuses the next focusable on the canvas. func FocusNext(c fyne.Canvas) { - if tc, ok := c.(*testCanvas); ok { - tc.focusManager().FocusNext() + if tc, ok := c.(*software.SoftwareCanvas); ok { + tc.FocusNext() } else { fyne.LogError("FocusNext can only be called with a test canvas", nil) } @@ -162,8 +163,8 @@ func FocusNext(c fyne.Canvas) { // FocusPrevious focuses the previous focusable on the canvas. func FocusPrevious(c fyne.Canvas) { - if tc, ok := c.(*testCanvas); ok { - tc.focusManager().FocusPrevious() + if tc, ok := c.(*software.SoftwareCanvas); ok { + tc.FocusPrevious() } else { fyne.LogError("FocusPrevious can only be called with a test canvas", nil) } @@ -183,10 +184,10 @@ func MoveMouse(c fyne.Canvas, pos fyne.Position) { return } - tc, _ := c.(*testCanvas) + tc, _ := c.(*software.SoftwareCanvas) var oldHovered, hovered desktop.Hoverable if tc != nil { - oldHovered = tc.hovered + oldHovered = tc.Hovered() } matches := func(object fyne.CanvasObject) bool { if _, ok := object.(desktop.Hoverable); ok { @@ -215,7 +216,7 @@ func MoveMouse(c fyne.Canvas, pos fyne.Position) { oldHovered.MouseOut() } if tc != nil { - tc.hovered = hovered + tc.SetHovered(hovered) } } @@ -323,6 +324,26 @@ func findTappable(c fyne.Canvas, pos fyne.Position) (o fyne.CanvasObject, p fyne return } +func layoutAndCollect(objects []fyne.CanvasObject, o fyne.CanvasObject, size fyne.Size) []fyne.CanvasObject { + objects = append(objects, o) + switch c := o.(type) { + case fyne.Widget: + r := c.CreateRenderer() + r.Layout(size) + for _, child := range r.Objects() { + objects = layoutAndCollect(objects, child, child.Size()) + } + case *fyne.Container: + if c.Layout != nil { + c.Layout.Layout(c.Objects, size) + } + for _, child := range c.Objects { + objects = layoutAndCollect(objects, child, child.Size()) + } + } + return objects +} + func prepareTap(obj any, pos fyne.Position) (*fyne.PointEvent, fyne.Canvas) { d := fyne.CurrentApp().Driver() ev := &fyne.PointEvent{Position: pos} diff --git a/test/test_test.go b/test/test_test.go index 71eef68587..a4dc2016f6 100644 --- a/test/test_test.go +++ b/test/test_test.go @@ -11,12 +11,13 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" + canvas2 "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/widget" ) func TestAssertCanvasTappableAt(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() b := widget.NewButton("foo", nil) c.SetContent(b) c.Resize(fyne.NewSize(300, 300)) @@ -47,7 +48,7 @@ func TestAssertObjectRendersToMarkup(t *testing.T) { } func TestAssertRendersToImage(t *testing.T) { - c := test.NewCanvas() // no painter, would be cycle - images will be blank + c := canvas2.NewCanvas() // no painter, would be cycle - images will be blank c.SetContent(canvas.NewCircle(color.Black)) c.Resize(fyne.NewSize(10, 10)) @@ -83,7 +84,7 @@ func TestAssertRendersToImage(t *testing.T) { } func TestAssertRendersToMarkup(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetContent(canvas.NewCircle(color.Black)) markup := "\n" + @@ -118,7 +119,7 @@ func TestAssertRendersToMarkup(t *testing.T) { } func TestDrag(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) d := &draggable{} c.SetContent(container.NewWithoutLayout(d)) @@ -139,12 +140,13 @@ func TestDrag(t *testing.T) { } func TestFocusNext(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() f1 := &focusable{} f2 := &focusable{} f3 := &focusable{} c.SetContent(container.NewWithoutLayout(f1, f2, f3)) + // c.Focus(f1) assert.Nil(t, c.Focused()) assert.False(t, f1.focused) assert.False(t, f2.focused) @@ -176,7 +178,7 @@ func TestFocusNext(t *testing.T) { } func TestFocusPrevious(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() f1 := &focusable{} f2 := &focusable{} f3 := &focusable{} @@ -213,7 +215,7 @@ func TestFocusPrevious(t *testing.T) { } func TestScroll(t *testing.T) { - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetPadded(false) s := &scrollable{} c.SetContent(container.NewWithoutLayout(s)) diff --git a/test/testapp.go b/test/testapp.go index 6c54eee35d..7e01cede42 100644 --- a/test/testapp.go +++ b/test/testapp.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2/internal" "fyne.io/fyne/v2/internal/app" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/internal/painter" "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/theme" @@ -20,7 +21,7 @@ func init() { } type testApp struct { - driver *testDriver + driver *software.SoftwareDriver settings *testSettings prefs fyne.Preferences propertyLock sync.RWMutex @@ -152,7 +153,7 @@ func NewApp() fyne.App { settings := &testSettings{scale: 1.0, theme: Theme()} prefs := internal.NewInMemoryPreferences() store := &testStorage{} - test := &testApp{settings: settings, prefs: prefs, storage: store, driver: NewDriver().(*testDriver), + test := &testApp{settings: settings, prefs: prefs, storage: store, driver: software.NewDriver(nil, nil).(*software.SoftwareDriver), lifecycle: &app.Lifecycle{}} root, _ := store.docRootURI() store.Docs = &internal.Docs{RootDocURI: root} diff --git a/test/testcanvas.go b/test/testcanvas.go deleted file mode 100644 index 02d2b7a3f1..0000000000 --- a/test/testcanvas.go +++ /dev/null @@ -1,305 +0,0 @@ -package test - -import ( - "image" - "image/draw" - "sync" - - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/driver/desktop" - "fyne.io/fyne/v2/internal" - "fyne.io/fyne/v2/internal/app" - "fyne.io/fyne/v2/internal/cache" - "fyne.io/fyne/v2/internal/scale" - "fyne.io/fyne/v2/theme" -) - -var ( - dummyCanvas fyne.Canvas -) - -// WindowlessCanvas provides functionality for a canvas to operate without a window -type WindowlessCanvas interface { - fyne.Canvas - - Padded() bool - Resize(fyne.Size) - SetPadded(bool) - SetScale(float32) -} - -type testCanvas struct { - size fyne.Size - scale float32 - - content fyne.CanvasObject - overlays *internal.OverlayStack - focusMgr *app.FocusManager - hovered desktop.Hoverable - padded bool - transparent bool - - onTypedRune func(rune) - onTypedKey func(*fyne.KeyEvent) - - fyne.ShortcutHandler - painter SoftwarePainter - propertyLock sync.RWMutex -} - -// Canvas returns a reusable in-memory canvas used for testing -func Canvas() fyne.Canvas { - if dummyCanvas == nil { - dummyCanvas = NewCanvas() - } - - return dummyCanvas -} - -// NewCanvas returns a single use in-memory canvas used for testing. -// This canvas has no painter so calls to Capture() will return a blank image. -func NewCanvas() WindowlessCanvas { - c := &testCanvas{ - focusMgr: app.NewFocusManager(nil), - padded: true, - scale: 1.0, - size: fyne.NewSize(10, 10), - } - c.overlays = &internal.OverlayStack{Canvas: c} - return c -} - -// NewCanvasWithPainter allows creation of an in-memory canvas with a specific painter. -// The painter will be used to render in the Capture() call. -func NewCanvasWithPainter(painter SoftwarePainter) WindowlessCanvas { - canvas := NewCanvas().(*testCanvas) - canvas.painter = painter - - return canvas -} - -// NewTransparentCanvasWithPainter allows creation of an in-memory canvas with a specific painter without a background color. -// The painter will be used to render in the Capture() call. -// -// Since: 2.2 -func NewTransparentCanvasWithPainter(painter SoftwarePainter) WindowlessCanvas { - canvas := NewCanvasWithPainter(painter).(*testCanvas) - canvas.transparent = true - - return canvas -} - -func (c *testCanvas) Capture() image.Image { - cache.Clean(true) - bounds := image.Rect(0, 0, scale.ToScreenCoordinate(c, c.Size().Width), scale.ToScreenCoordinate(c, c.Size().Height)) - img := image.NewNRGBA(bounds) - if !c.transparent { - draw.Draw(img, bounds, image.NewUniform(theme.BackgroundColor()), image.Point{}, draw.Src) - } - - if c.painter != nil { - draw.Draw(img, bounds, c.painter.Capture(c), image.Point{}, draw.Over) - } - - return img -} - -func (c *testCanvas) Content() fyne.CanvasObject { - c.propertyLock.RLock() - defer c.propertyLock.RUnlock() - - return c.content -} - -func (c *testCanvas) Focus(obj fyne.Focusable) { - c.focusManager().Focus(obj) -} - -func (c *testCanvas) FocusNext() { - c.focusManager().FocusNext() -} - -func (c *testCanvas) FocusPrevious() { - c.focusManager().FocusPrevious() -} - -func (c *testCanvas) Focused() fyne.Focusable { - return c.focusManager().Focused() -} - -func (c *testCanvas) InteractiveArea() (fyne.Position, fyne.Size) { - return fyne.Position{}, c.Size() -} - -func (c *testCanvas) OnTypedKey() func(*fyne.KeyEvent) { - c.propertyLock.RLock() - defer c.propertyLock.RUnlock() - - return c.onTypedKey -} - -func (c *testCanvas) OnTypedRune() func(rune) { - c.propertyLock.RLock() - defer c.propertyLock.RUnlock() - - return c.onTypedRune -} - -func (c *testCanvas) Overlays() fyne.OverlayStack { - c.propertyLock.Lock() - defer c.propertyLock.Unlock() - - return c.overlays -} - -func (c *testCanvas) Padded() bool { - c.propertyLock.RLock() - defer c.propertyLock.RUnlock() - - return c.padded -} - -func (c *testCanvas) PixelCoordinateForPosition(pos fyne.Position) (int, int) { - return int(float32(pos.X) * c.scale), int(float32(pos.Y) * c.scale) -} - -func (c *testCanvas) Refresh(fyne.CanvasObject) { -} - -func (c *testCanvas) Resize(size fyne.Size) { - c.propertyLock.Lock() - content := c.content - overlays := c.overlays - padded := c.padded - c.size = size - c.propertyLock.Unlock() - - if content == nil { - return - } - - // Ensure testcanvas mimics real canvas.Resize behavior - for _, overlay := range overlays.List() { - type popupWidget interface { - fyne.CanvasObject - ShowAtPosition(fyne.Position) - } - if p, ok := overlay.(popupWidget); ok { - // TODO: remove this when #707 is being addressed. - // “Notifies” the PopUp of the canvas size change. - p.Refresh() - } else { - overlay.Resize(size) - } - } - - if padded { - content.Resize(size.Subtract(fyne.NewSize(theme.Padding()*2, theme.Padding()*2))) - content.Move(fyne.NewPos(theme.Padding(), theme.Padding())) - } else { - content.Resize(size) - content.Move(fyne.NewPos(0, 0)) - } -} - -func (c *testCanvas) Scale() float32 { - c.propertyLock.RLock() - defer c.propertyLock.RUnlock() - - return c.scale -} - -func (c *testCanvas) SetContent(content fyne.CanvasObject) { - c.propertyLock.Lock() - c.content = content - c.focusMgr = app.NewFocusManager(c.content) - c.propertyLock.Unlock() - - if content == nil { - return - } - - padding := fyne.NewSize(0, 0) - if c.padded { - padding = fyne.NewSize(theme.Padding()*2, theme.Padding()*2) - } - c.Resize(content.MinSize().Add(padding)) -} - -func (c *testCanvas) SetOnTypedKey(handler func(*fyne.KeyEvent)) { - c.propertyLock.Lock() - defer c.propertyLock.Unlock() - - c.onTypedKey = handler -} - -func (c *testCanvas) SetOnTypedRune(handler func(rune)) { - c.propertyLock.Lock() - defer c.propertyLock.Unlock() - - c.onTypedRune = handler -} - -func (c *testCanvas) SetPadded(padded bool) { - c.propertyLock.Lock() - c.padded = padded - c.propertyLock.Unlock() - - c.Resize(c.Size()) -} - -func (c *testCanvas) SetScale(scale float32) { - c.propertyLock.Lock() - defer c.propertyLock.Unlock() - - c.scale = scale -} - -func (c *testCanvas) Size() fyne.Size { - c.propertyLock.RLock() - defer c.propertyLock.RUnlock() - - return c.size -} - -func (c *testCanvas) Unfocus() { - c.focusManager().Focus(nil) -} - -func (c *testCanvas) focusManager() *app.FocusManager { - c.propertyLock.RLock() - defer c.propertyLock.RUnlock() - if focusMgr := c.overlays.TopFocusManager(); focusMgr != nil { - return focusMgr - } - return c.focusMgr -} - -func (c *testCanvas) objectTrees() []fyne.CanvasObject { - trees := make([]fyne.CanvasObject, 0, len(c.Overlays().List())+1) - if c.content != nil { - trees = append(trees, c.content) - } - trees = append(trees, c.Overlays().List()...) - return trees -} - -func layoutAndCollect(objects []fyne.CanvasObject, o fyne.CanvasObject, size fyne.Size) []fyne.CanvasObject { - objects = append(objects, o) - switch c := o.(type) { - case fyne.Widget: - r := c.CreateRenderer() - r.Layout(size) - for _, child := range r.Objects() { - objects = layoutAndCollect(objects, child, child.Size()) - } - case *fyne.Container: - if c.Layout != nil { - c.Layout.Layout(c.Objects, size) - } - for _, child := range c.Objects { - objects = layoutAndCollect(objects, child, child.Size()) - } - } - return objects -} diff --git a/test/testdriver.go b/test/testdriver.go deleted file mode 100644 index 4a1e5f71ce..0000000000 --- a/test/testdriver.go +++ /dev/null @@ -1,140 +0,0 @@ -package test - -import ( - "image" - "sync" - "time" - - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/internal/driver" - "fyne.io/fyne/v2/internal/painter" - "fyne.io/fyne/v2/internal/painter/software" - intRepo "fyne.io/fyne/v2/internal/repository" - "fyne.io/fyne/v2/storage/repository" -) - -// SoftwarePainter describes a simple type that can render canvases -type SoftwarePainter interface { - Capture(fyne.Canvas) image.Image -} - -type testDriver struct { - device *device - painter SoftwarePainter - windows []fyne.Window - windowsMutex sync.RWMutex -} - -// Declare conformity with Driver -var _ fyne.Driver = (*testDriver)(nil) - -// NewDriver sets up and registers a new dummy driver for test purpose -func NewDriver() fyne.Driver { - drv := &testDriver{windowsMutex: sync.RWMutex{}} - repository.Register("file", intRepo.NewFileRepository()) - - // make a single dummy window for rendering tests - drv.CreateWindow("") - - return drv -} - -// NewDriverWithPainter creates a new dummy driver that will pass the given -// painter to all canvases created -func NewDriverWithPainter(painter SoftwarePainter) fyne.Driver { - return &testDriver{ - painter: painter, - windowsMutex: sync.RWMutex{}, - } -} - -func (d *testDriver) AbsolutePositionForObject(co fyne.CanvasObject) fyne.Position { - c := d.CanvasForObject(co) - if c == nil { - return fyne.NewPos(0, 0) - } - - tc := c.(*testCanvas) - return driver.AbsolutePositionForObject(co, tc.objectTrees()) -} - -func (d *testDriver) AllWindows() []fyne.Window { - d.windowsMutex.RLock() - defer d.windowsMutex.RUnlock() - return d.windows -} - -func (d *testDriver) CanvasForObject(fyne.CanvasObject) fyne.Canvas { - d.windowsMutex.RLock() - defer d.windowsMutex.RUnlock() - // cheating: probably the last created window is meant - return d.windows[len(d.windows)-1].Canvas() -} - -func (d *testDriver) CreateWindow(string) fyne.Window { - canvas := NewCanvas().(*testCanvas) - if d.painter != nil { - canvas.painter = d.painter - } else { - canvas.painter = software.NewPainter() - } - - window := &testWindow{canvas: canvas, driver: d} - window.clipboard = &testClipboard{} - - d.windowsMutex.Lock() - d.windows = append(d.windows, window) - d.windowsMutex.Unlock() - return window -} - -func (d *testDriver) Device() fyne.Device { - if d.device == nil { - d.device = &device{} - } - return d.device -} - -// RenderedTextSize looks up how bit a string would be if drawn on screen -func (d *testDriver) RenderedTextSize(text string, size float32, style fyne.TextStyle) (fyne.Size, float32) { - return painter.RenderedTextSize(text, size, style) -} - -func (d *testDriver) Run() { - // no-op -} - -func (d *testDriver) StartAnimation(a *fyne.Animation) { - // currently no animations in test app, we just initialise it and leave - a.Tick(1.0) -} - -func (d *testDriver) StopAnimation(a *fyne.Animation) { - // currently no animations in test app, do nothing -} - -func (d *testDriver) Quit() { - // no-op -} - -func (d *testDriver) removeWindow(w *testWindow) { - d.windowsMutex.Lock() - i := 0 - for _, window := range d.windows { - if window == w { - break - } - i++ - } - - d.windows = append(d.windows[:i], d.windows[i+1:]...) - d.windowsMutex.Unlock() -} - -func (d *testDriver) DoubleTapDelay() time.Duration { - return 300 * time.Millisecond -} - -func (d *testDriver) SetDisableScreenBlanking(_ bool) { - // no-op for test -} diff --git a/test/testwindow.go b/test/testwindow.go deleted file mode 100644 index eeee940941..0000000000 --- a/test/testwindow.go +++ /dev/null @@ -1,142 +0,0 @@ -package test - -import ( - "fyne.io/fyne/v2" -) - -type testWindow struct { - title string - fullScreen bool - fixedSize bool - focused bool - onClosed func() - onCloseIntercepted func() - - canvas *testCanvas - clipboard fyne.Clipboard - driver *testDriver - menu *fyne.MainMenu -} - -// NewWindow creates and registers a new window for test purposes -func NewWindow(content fyne.CanvasObject) fyne.Window { - window := fyne.CurrentApp().NewWindow("") - window.SetContent(content) - return window -} - -func (w *testWindow) Canvas() fyne.Canvas { - return w.canvas -} - -func (w *testWindow) CenterOnScreen() { - // no-op -} - -func (w *testWindow) Clipboard() fyne.Clipboard { - return w.clipboard -} - -func (w *testWindow) Close() { - if w.onClosed != nil { - w.onClosed() - } - w.focused = false - w.driver.removeWindow(w) -} - -func (w *testWindow) Content() fyne.CanvasObject { - return w.Canvas().Content() -} - -func (w *testWindow) FixedSize() bool { - return w.fixedSize -} - -func (w *testWindow) FullScreen() bool { - return w.fullScreen -} - -func (w *testWindow) Hide() { - w.focused = false -} - -func (w *testWindow) Icon() fyne.Resource { - return fyne.CurrentApp().Icon() -} - -func (w *testWindow) MainMenu() *fyne.MainMenu { - return w.menu -} - -func (w *testWindow) Padded() bool { - return w.canvas.Padded() -} - -func (w *testWindow) RequestFocus() { - for _, win := range w.driver.AllWindows() { - win.(*testWindow).focused = false - } - - w.focused = true -} - -func (w *testWindow) Resize(size fyne.Size) { - w.canvas.Resize(size) -} - -func (w *testWindow) SetContent(obj fyne.CanvasObject) { - w.Canvas().SetContent(obj) -} - -func (w *testWindow) SetFixedSize(fixed bool) { - w.fixedSize = fixed -} - -func (w *testWindow) SetIcon(_ fyne.Resource) { - // no-op -} - -func (w *testWindow) SetFullScreen(fullScreen bool) { - w.fullScreen = fullScreen -} - -func (w *testWindow) SetMainMenu(menu *fyne.MainMenu) { - w.menu = menu -} - -func (w *testWindow) SetMaster() { - // no-op -} - -func (w *testWindow) SetOnClosed(closed func()) { - w.onClosed = closed -} - -func (w *testWindow) SetCloseIntercept(callback func()) { - w.onCloseIntercepted = callback -} - -func (w *testWindow) SetOnDropped(dropped func(fyne.Position, []fyne.URI)) { - -} - -func (w *testWindow) SetPadded(padded bool) { - w.canvas.SetPadded(padded) -} - -func (w *testWindow) SetTitle(title string) { - w.title = title -} - -func (w *testWindow) Show() { - w.RequestFocus() -} - -func (w *testWindow) ShowAndRun() { - w.Show() -} - -func (w *testWindow) Title() string { - return w.title -} diff --git a/widget/accordion_test.go b/widget/accordion_test.go index 68704071c3..e469863521 100644 --- a/widget/accordion_test.go +++ b/widget/accordion_test.go @@ -5,6 +5,7 @@ import ( "time" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -39,7 +40,7 @@ func TestAccordion_ChangeTheme(t *testing.T) { ac.Append(widget.NewAccordionItem("foo0", widget.NewLabel("foobar0"))) ac.Append(widget.NewAccordionItem("foo1", widget.NewLabel("foobar1"))) - w := test.NewWindow(ac) + w := software.NewWindow(ac) defer w.Close() w.Resize(ac.MinSize().Add(fyne.NewSize(theme.InnerPadding(), theme.InnerPadding()))) @@ -207,7 +208,7 @@ func TestAccordion_Layout(t *testing.T) { accordion.Open(o) } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) window.Resize(accordion.MinSize().Add(fyne.NewSquareSize(theme.Padding() * 2))) test.AssertRendersToMarkup(t, "accordion/layout_"+name+".xml", window.Canvas()) @@ -325,7 +326,7 @@ func TestAccordion_Layout_Expanded(t *testing.T) { accordion.Open(o) } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) window.Resize(accordion.MinSize().Max(fyne.NewSize(150, 280))) test.AssertRendersToMarkup(t, "accordion/layout_"+name+".xml", window.Canvas()) diff --git a/widget/activity_internal_test.go b/widget/activity_internal_test.go index 13372186da..151e73a8d0 100644 --- a/widget/activity_internal_test.go +++ b/widget/activity_internal_test.go @@ -3,6 +3,7 @@ package widget import ( "testing" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" ) @@ -12,7 +13,7 @@ func TestActivity_Animation(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) a := NewActivity() - w := test.NewWindow(a) + w := software.NewWindow(a) w.SetPadded(false) defer w.Close() w.Resize(a.MinSize()) diff --git a/widget/activity_test.go b/widget/activity_test.go index a758af384f..2f103d05ac 100644 --- a/widget/activity_test.go +++ b/widget/activity_test.go @@ -4,9 +4,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" - "github.com/stretchr/testify/assert" ) func TestActivity_Start(t *testing.T) { @@ -15,7 +17,7 @@ func TestActivity_Start(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) a := NewActivity() - w := test.NewWindow(a) + w := software.NewWindow(a) defer w.Close() w.Resize(fyne.NewSize(50, 50)) @@ -34,7 +36,7 @@ func TestActivity_Stop(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) a := NewActivity() - w := test.NewWindow(a) + w := software.NewWindow(a) defer w.Close() w.Resize(fyne.NewSize(50, 50)) diff --git a/widget/button_internal_test.go b/widget/button_internal_test.go index bc4298abce..2058e29aa6 100644 --- a/widget/button_internal_test.go +++ b/widget/button_internal_test.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/internal/cache" col "fyne.io/fyne/v2/internal/color" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -206,7 +207,7 @@ func TestButtonRenderer_TapAnimation(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) button := NewButton("Hi", func() {}) - w := test.NewWindow(button) + w := software.NewWindow(button) defer w.Close() w.Resize(fyne.NewSize(50, 50).Add(fyne.NewSize(20, 20))) button.Resize(fyne.NewSize(50, 50)) diff --git a/widget/button_test.go b/widget/button_test.go index c13b2a841f..f3beef615b 100644 --- a/widget/button_test.go +++ b/widget/button_test.go @@ -6,6 +6,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -75,7 +76,7 @@ func TestButton_Disable(t *testing.T) { tapped = true }) button.Disable() - w := test.NewWindow(button) + w := software.NewWindow(button) defer w.Close() test.Tap(button) @@ -127,7 +128,7 @@ func TestButton_LowImportance(t *testing.T) { defer test.NewApp() b := &widget.Button{Text: "Text", Icon: theme.HomeIcon(), Importance: widget.LowImportance} - w := test.NewWindow(b) + w := software.NewWindow(b) defer w.Close() test.AssertImageMatches(t, "button/low_importance.png", w.Canvas().Capture()) @@ -142,7 +143,7 @@ func TestButton_Hover(t *testing.T) { test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) b := widget.NewButtonWithIcon("Test", theme.HomeIcon(), func() {}) - w := test.NewWindow(b) + w := software.NewWindow(b) defer w.Close() if !fyne.CurrentDevice().IsMobile() { @@ -284,7 +285,7 @@ func TestButton_Layout(t *testing.T) { IconPlacement: tt.placement, } - window := test.NewWindow(button) + window := software.NewWindow(button) defer window.Close() window.Resize(button.MinSize().Max(fyne.NewSize(150, 200))) @@ -298,7 +299,7 @@ func TestButton_ChangeTheme(t *testing.T) { defer test.NewApp() b := widget.NewButton("Test", func() {}) - w := test.NewWindow(b) + w := software.NewWindow(b) defer w.Close() w.Resize(fyne.NewSize(200, 200)) b.Resize(b.MinSize()) @@ -328,7 +329,7 @@ func TestButtonSuccess(t *testing.T) { test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) b := widget.NewButtonWithIcon("Test", theme.HomeIcon(), func() {}) - w := test.NewWindow(b) + w := software.NewWindow(b) defer w.Close() b.Importance = widget.SuccessImportance diff --git a/widget/card_test.go b/widget/card_test.go index 1765040a63..c409124069 100644 --- a/widget/card_test.go +++ b/widget/card_test.go @@ -6,6 +6,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -104,7 +105,7 @@ func TestCard_Layout(t *testing.T) { Content: tt.content, } - window := test.NewWindow(card) + window := software.NewWindow(card) size := card.MinSize().Max(fyne.NewSize(80, 0)) // give a little width for image only tests window.Resize(size.Add(fyne.NewSize(theme.InnerPadding(), theme.InnerPadding()))) if tt.content != nil { @@ -128,7 +129,7 @@ func TestCard_MinSize(t *testing.T) { func TestCard_Refresh(t *testing.T) { text := widget.NewLabel("Test") card := widget.NewCard("", "", text) - w := test.NewWindow(card) + w := software.NewWindow(card) test.AssertRendersToMarkup(t, "card/content_label.xml", w.Canvas()) text.Text = "Changed" diff --git a/widget/check_group_test.go b/widget/check_group_test.go index 8605ccb806..8c4b41302f 100644 --- a/widget/check_group_test.go +++ b/widget/check_group_test.go @@ -4,6 +4,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/widget" @@ -13,11 +14,11 @@ import ( func TestCheckGroup_FocusRendering(t *testing.T) { t.Run("gain/lose focus", func(t *testing.T) { check := widget.NewCheckGroup([]string{"Option A", "Option B", "Option C"}, nil) - window := test.NewWindow(check) + window := software.NewWindow(check) defer window.Close() window.Resize(check.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) test.AssertRendersToMarkup(t, "check_group/focus_none_focused_none_selected.xml", canvas) canvas.FocusNext() test.AssertRendersToMarkup(t, "check_group/focus_a_focused_none_selected.xml", canvas) @@ -38,11 +39,11 @@ func TestCheckGroup_FocusRendering(t *testing.T) { t.Run("disable/enable focused", func(t *testing.T) { check := &widget.CheckGroup{Options: []string{"Option A", "Option B", "Option C"}} - window := test.NewWindow(check) + window := software.NewWindow(check) defer window.Close() window.Resize(check.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) canvas.FocusNext() check.Disable() test.AssertRendersToMarkup(t, "check_group/focus_disabled_none_selected.xml", canvas) @@ -52,11 +53,11 @@ func TestCheckGroup_FocusRendering(t *testing.T) { t.Run("append disabled", func(t *testing.T) { check := &widget.CheckGroup{Options: []string{"Option A", "Option B"}} - window := test.NewWindow(check) + window := software.NewWindow(check) defer window.Close() window.Resize(check.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) check.Disable() test.AssertRendersToMarkup(t, "check_group/disabled_none_selected.xml", canvas) check.Append("Option C") @@ -154,7 +155,7 @@ func TestCheckGroup_Layout(t *testing.T) { check.Disable() } - window := test.NewWindow(check) + window := software.NewWindow(check) window.Resize(check.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "check_group/layout_"+name+".xml", window.Canvas()) @@ -166,13 +167,13 @@ func TestCheckGroup_Layout(t *testing.T) { func TestCheckGroup_ToggleSelectionWithSpaceKey(t *testing.T) { check := &widget.CheckGroup{Options: []string{"Option A", "Option B", "Option C"}} - window := test.NewWindow(check) + window := software.NewWindow(check) defer window.Close() var empty []string assert.Equal(t, empty, check.Selected) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) canvas.FocusNext() canvas.FocusNext() test.Type(canvas.Focused(), " ") diff --git a/widget/check_internal_test.go b/widget/check_internal_test.go index 9eec2a0984..90399fb56b 100644 --- a/widget/check_internal_test.go +++ b/widget/check_internal_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" ) @@ -127,7 +128,7 @@ func TestCheck_Enable(t *testing.T) { func TestCheck_Focused(t *testing.T) { check := NewCheck("Test", func(on bool) {}) - w := test.NewWindow(check) + w := software.NewWindow(check) defer w.Close() render := test.WidgetRenderer(check).(*checkRenderer) @@ -166,7 +167,7 @@ func TestCheck_Focused(t *testing.T) { func TestCheck_Hovered(t *testing.T) { check := NewCheck("Test", func(on bool) {}) - w := test.NewWindow(check) + w := software.NewWindow(check) defer w.Close() render := test.WidgetRenderer(check).(*checkRenderer) @@ -212,7 +213,7 @@ func TestCheck_Hovered(t *testing.T) { func TestCheck_HoveredOutsideActiveArea(t *testing.T) { check := NewCheck("Test", func(on bool) {}) - w := test.NewWindow(check) + w := software.NewWindow(check) defer w.Close() render := test.WidgetRenderer(check).(*checkRenderer) @@ -230,7 +231,7 @@ func TestCheck_HoveredOutsideActiveArea(t *testing.T) { func TestCheck_TappedOutsideActiveArea(t *testing.T) { check := NewCheck("Test", func(on bool) {}) - w := test.NewWindow(check) + w := software.NewWindow(check) defer w.Close() check.SetChecked(true) @@ -244,7 +245,7 @@ func TestCheck_TappedOutsideActiveArea(t *testing.T) { func TestCheck_TypedRune(t *testing.T) { check := NewCheck("Test", func(on bool) {}) - w := test.NewWindow(check) + w := software.NewWindow(check) defer w.Close() assert.False(t, check.Checked) diff --git a/widget/check_test.go b/widget/check_test.go index 6b4210e926..000a55bf42 100644 --- a/widget/check_test.go +++ b/widget/check_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/data/binding" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/widget" @@ -72,7 +73,7 @@ func TestCheck_Layout(t *testing.T) { check.Disable() } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{check}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{check}}) window.Resize(check.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "check/layout_"+name+".xml", window.Canvas()) diff --git a/widget/entry_internal_test.go b/widget/entry_internal_test.go index 57313ca48f..60759e1c45 100644 --- a/widget/entry_internal_test.go +++ b/widget/entry_internal_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" intWidget "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -63,7 +64,7 @@ func TestEntry_DoubleTapped_AfterCol(t *testing.T) { entry := NewEntry() entry.SetText("A\nB\n") - window := test.NewWindow(entry) + window := software.NewWindow(entry) defer window.Close() window.SetPadded(false) window.Resize(entry.MinSize()) @@ -391,7 +392,7 @@ func TestEntry_PlaceholderTextStyle(t *testing.T) { e := NewEntry() e.TextStyle = fyne.TextStyle{Bold: true, Italic: true} - w := test.NewWindow(e) + w := software.NewWindow(e) assert.Equal(t, e.TextStyle, e.placeholder.Segments[0].(*TextSegment).Style.TextStyle) w.Canvas().Focus(e) @@ -409,7 +410,7 @@ func TestEntry_Tab(t *testing.T) { assert.Equal(t, "a", r.Objects()[0].(*canvas.Text).Text) assert.Equal(t, "\tb", r.Objects()[1].(*canvas.Text).Text) - w := test.NewWindow(e) + w := software.NewWindow(e) w.Resize(fyne.NewSize(86, 86)) w.Canvas().Focus(e) test.AssertImageMatches(t, "entry/tab-content.png", w.Canvas().Capture()) @@ -428,7 +429,7 @@ func TestEntry_TabSelection(t *testing.T) { assert.Equal(t, "\tb", e.SelectedText()) - w := test.NewWindow(e) + w := software.NewWindow(e) w.Resize(fyne.NewSize(86, 86)) w.Canvas().Focus(e) test.AssertImageMatches(t, "entry/tab-select.png", w.Canvas().Capture()) diff --git a/widget/entry_test.go b/widget/entry_test.go index 588ee00bfe..e176968201 100644 --- a/widget/entry_test.go +++ b/widget/entry_test.go @@ -12,6 +12,7 @@ import ( "fyne.io/fyne/v2/data/binding" "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/internal/driver" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -252,7 +253,7 @@ func TestEntry_CursorColumn_Wrap2(t *testing.T) { entry.SetText("1234") entry.CursorColumn = 3 - w := test.NewWindow(entry) + w := software.NewWindow(entry) w.Resize(fyne.NewSize(72, 64)) test.Type(entry, "a") @@ -569,7 +570,7 @@ func TestEntry_OnCopy(t *testing.T) { e.SetText("Testing") typeKeys(e, fyne.KeyRight, fyne.KeyRight, keyShiftLeftDown, fyne.KeyRight, fyne.KeyRight, fyne.KeyRight) - clipboard := test.NewClipboard() + clipboard := software.NewClipboard() shortcut := &fyne.ShortcutCopy{Clipboard: clipboard} e.TypedShortcut(shortcut) @@ -582,7 +583,7 @@ func TestEntry_OnCopy_Password(t *testing.T) { e.SetText("Testing") typeKeys(e, keyShiftLeftDown, fyne.KeyRight, fyne.KeyRight, fyne.KeyRight) - clipboard := test.NewClipboard() + clipboard := software.NewClipboard() shortcut := &fyne.ShortcutCopy{Clipboard: clipboard} e.TypedShortcut(shortcut) @@ -595,7 +596,7 @@ func TestEntry_OnCut(t *testing.T) { e.SetText("Testing") typeKeys(e, fyne.KeyRight, fyne.KeyRight, keyShiftLeftDown, fyne.KeyRight, fyne.KeyRight, fyne.KeyRight) - clipboard := test.NewClipboard() + clipboard := software.NewClipboard() shortcut := &fyne.ShortcutCut{Clipboard: clipboard} e.TypedShortcut(shortcut) @@ -608,7 +609,7 @@ func TestEntry_OnCut_Password(t *testing.T) { e.SetText("Testing") typeKeys(e, keyShiftLeftDown, fyne.KeyRight, fyne.KeyRight, fyne.KeyRight) - clipboard := test.NewClipboard() + clipboard := software.NewClipboard() shortcut := &fyne.ShortcutCut{Clipboard: clipboard} e.TypedShortcut(shortcut) @@ -843,7 +844,7 @@ func TestEntry_OnKeyDown_Newline(t *testing.T) { } func TestEntry_OnPaste(t *testing.T) { - clipboard := test.NewClipboard() + clipboard := software.NewClipboard() shortcut := &fyne.ShortcutPaste{Clipboard: clipboard} tests := []struct { name string @@ -990,7 +991,7 @@ func TestEntry_PasteOverSelection(t *testing.T) { e.SetText("Testing") typeKeys(e, fyne.KeyRight, fyne.KeyRight, keyShiftLeftDown, fyne.KeyRight, fyne.KeyRight, fyne.KeyRight) - clipboard := test.NewClipboard() + clipboard := software.NewClipboard() clipboard.SetContent("Insert") shortcut := &fyne.ShortcutPaste{Clipboard: clipboard} e.TypedShortcut(shortcut) @@ -1004,7 +1005,7 @@ func TestEntry_PasteUnicode(t *testing.T) { e.SetText("line") e.CursorColumn = 4 - clipboard := test.NewClipboard() + clipboard := software.NewClipboard() clipboard.SetContent("thing {\n\titem: 'val测试'\n}") shortcut := &fyne.ShortcutPaste{Clipboard: clipboard} e.TypedShortcut(shortcut) @@ -1021,7 +1022,7 @@ func TestEntry_Placeholder(t *testing.T) { entry.Text = "Text" entry.PlaceHolder = "Placehold" - window := test.NewWindow(entry) + window := software.NewWindow(entry) defer teardownImageTest(window) c := window.Canvas() @@ -1874,7 +1875,7 @@ func TestPasswordEntry_Reveal(t *testing.T) { t.Run("NewPasswordEntry constructor", func(t *testing.T) { entry := widget.NewPasswordEntry() - window := test.NewWindow(entry) + window := software.NewWindow(entry) defer window.Close() window.Resize(fyne.NewSize(150, 100)) entry.Resize(entry.MinSize().Max(fyne.NewSize(130, 0))) @@ -1922,7 +1923,7 @@ func TestPasswordEntry_Reveal(t *testing.T) { t.Run("Entry with Password field", func(t *testing.T) { entry := &widget.Entry{Password: true, Wrapping: fyne.TextWrapWord} entry.Refresh() - window := test.NewWindow(entry) + window := software.NewWindow(entry) defer window.Close() window.Resize(fyne.NewSize(150, 100)) entry.Resize(entry.MinSize().Max(fyne.NewSize(130, 0))) @@ -1977,7 +1978,7 @@ func TestEntry_CarriageReturn(t *testing.T) { entry.Wrapping = fyne.TextWrapOff entry.Scroll = container.ScrollNone entry.SetText("\r\n\r") - w := test.NewWindow(entry) + w := software.NewWindow(entry) w.Resize(fyne.NewSize(64, 64)) test.AssertImageMatches(t, "entry/carriage_return_empty.png", w.Canvas().Capture()) entry.SetText("\rH\re\rl\rl\ro\r\n\rW\ro\rr\rl\rd\r!\r") @@ -2084,7 +2085,7 @@ func setupImageTest(t *testing.T, multiLine bool) (*widget.Entry, fyne.Window) { } else { entry = &widget.Entry{Wrapping: fyne.TextWrapOff, Scroll: container.ScrollNone} } - w := test.NewWindow(entry) + w := software.NewWindow(entry) w.Resize(fyne.NewSize(150, 200)) if multiLine { @@ -2107,7 +2108,7 @@ func setupPasswordTest(t *testing.T) (*widget.Entry, fyne.Window) { test.NewApp() entry := widget.NewPasswordEntry() - w := test.NewWindow(entry) + w := software.NewWindow(entry) w.Resize(fyne.NewSize(150, 100)) entry.Resize(entry.MinSize().Max(fyne.NewSize(130, 0))) diff --git a/widget/entry_validation_test.go b/widget/entry_validation_test.go index b8f4aa1509..3f73c358b4 100644 --- a/widget/entry_validation_test.go +++ b/widget/entry_validation_test.go @@ -5,6 +5,7 @@ import ( "testing" "fyne.io/fyne/v2/data/validation" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -73,7 +74,7 @@ func TestEntry_NotEmptyValidator(t *testing.T) { } return nil } - w := test.NewWindow(entry) + w := software.NewWindow(entry) defer w.Close() test.AssertRendersToMarkup(t, "entry/validator_not_empty_initial.xml", w.Canvas()) diff --git a/widget/fileicon_test.go b/widget/fileicon_test.go index a655e39e41..3c3038ca50 100644 --- a/widget/fileicon_test.go +++ b/widget/fileicon_test.go @@ -8,7 +8,8 @@ import ( "github.com/stretchr/testify/assert" "fyne.io/fyne/v2" - "fyne.io/fyne/v2/driver/software" + software2 "fyne.io/fyne/v2/driver/software" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/storage" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -27,7 +28,7 @@ func TestFileIcon_NewFileIcon_Rendered(t *testing.T) { icon := widget.NewFileIcon(nil) - w := test.NewWindow(icon) + w := software.NewWindow(icon) w.Resize(fyne.NewSize(150, 150)) test.AssertImageMatches(t, "fileicon/fileicon_nil.png", w.Canvas().Capture()) @@ -72,8 +73,8 @@ func TestFileIcon_Icon(t *testing.T) { icon2 := widget.NewFileIcon(trash) // test icon change - icon1Img := software.Render(icon1, test.Theme()) - icon2Img := software.Render(icon2, test.Theme()) + icon1Img := software2.Render(icon1, test.Theme()) + icon2Img := software2.Render(icon2, test.Theme()) assert.NotEqual(t, icon1Img, icon2Img) } diff --git a/widget/form_test.go b/widget/form_test.go index efa32a0e07..2a20872174 100644 --- a/widget/form_test.go +++ b/widget/form_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/data/validation" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -107,7 +108,7 @@ func TestForm_Renderer(t *testing.T) { {Text: "test2", Widget: NewEntry()}, }, OnSubmit: func() {}, OnCancel: func() {}} - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() test.AssertRendersToMarkup(t, "form/layout.xml", w.Canvas()) @@ -136,7 +137,7 @@ func TestForm_ChangeTheme(t *testing.T) { {Text: "test2", Widget: NewLabel("static")}, }, OnSubmit: func() {}, OnCancel: func() {}} - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() test.AssertImageMatches(t, "form/theme_initial.png", w.Canvas().Capture()) @@ -159,7 +160,7 @@ func TestForm_Disabled(t *testing.T) { NewFormItem("Form Item 1", NewEntry()), NewFormItem("Form Item 2", disabled)) - w := test.NewWindow(f) + w := software.NewWindow(f) defer w.Close() test.AssertImageMatches(t, "form/disabled.png", w.Canvas().Capture()) @@ -178,7 +179,7 @@ func TestForm_Hints(t *testing.T) { } form := &Form{Items: items, OnSubmit: func() {}, OnCancel: func() {}} - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() test.AssertImageMatches(t, "form/hint_initial.png", w.Canvas().Capture()) @@ -205,19 +206,19 @@ func TestForm_Validation(t *testing.T) { } form := &Form{Items: items, OnSubmit: func() {}, OnCancel: func() {}} - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() test.AssertImageMatches(t, "form/validation_initial.png", w.Canvas().Capture()) test.Type(entry2, "not-") entry1.SetText("incorrect") - w = test.NewWindow(form) + w = software.NewWindow(form) test.AssertImageMatches(t, "form/validation_invalid.png", w.Canvas().Capture()) entry1.SetText("15-true") - w = test.NewWindow(form) + w = software.NewWindow(form) test.AssertImageMatches(t, "form/validation_valid.png", w.Canvas().Capture()) } @@ -242,7 +243,7 @@ func TestForm_EntryValidation_FirstTypeValid(t *testing.T) { } form := &Form{Items: items, OnSubmit: func() {}, OnCancel: func() {}} - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() test.AssertImageMatches(t, "form/validation_entry_first_type_initial.png", w.Canvas().Capture()) @@ -251,13 +252,13 @@ func TestForm_EntryValidation_FirstTypeValid(t *testing.T) { test.Type(entry2, "L") entry1.focused = false entry1.Refresh() - w = test.NewWindow(form) + w = software.NewWindow(form) test.AssertImageMatches(t, "form/validation_entry_first_type_valid.png", w.Canvas().Capture()) entry1.SetText("") entry2.SetText("") - w = test.NewWindow(form) + w = software.NewWindow(form) test.AssertImageMatches(t, "form/validation_entry_first_type_invalid.png", w.Canvas().Capture()) } @@ -272,7 +273,7 @@ func TestForm_DisableEnable(t *testing.T) { {Text: "test1", Widget: NewEntry()}, }, OnSubmit: func() {}, OnCancel: func() {}} - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() if form.Disabled() { @@ -306,7 +307,7 @@ func TestForm_Disable_Validation(t *testing.T) { entry := &Entry{Validator: validation.NewRegexp(`^\d{2}-\w{4}$`, "Input is not valid"), Text: "wrong"} form := &Form{Items: []*FormItem{{Text: "test", Widget: entry}}, OnSubmit: func() {}, OnCancel: func() {}} - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() test.AssertImageMatches(t, "form/disable_validation_initial.png", w.Canvas().Capture()) @@ -351,7 +352,7 @@ func TestForm_HintsRendered(t *testing.T) { f.AppendItem(fi3) - w := test.NewWindow(f) + w := software.NewWindow(f) defer w.Close() test.AssertImageMatches(t, "form/hints_rendered.png", w.Canvas().Capture()) @@ -429,7 +430,7 @@ func TestForm_ExtendedEntry(t *testing.T) { {Text: "Extended entry", Widget: extendedEntry}, }, } - w := test.NewWindow(form) + w := software.NewWindow(form) defer w.Close() test.AssertRendersToMarkup(t, "form/extended_entry.xml", w.Canvas()) diff --git a/widget/gridwrap_test.go b/widget/gridwrap_test.go index 29dd28f060..4e11aede62 100644 --- a/widget/gridwrap_test.go +++ b/widget/gridwrap_test.go @@ -3,20 +3,22 @@ package widget import ( "testing" + "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" - "github.com/stretchr/testify/assert" ) func TestGridWrap_Focus(t *testing.T) { defer test.NewApp() list := createGridWrap(100) - window := test.NewWindow(list) + window := software.NewWindow(list) defer window.Close() window.Resize(list.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) assert.Nil(t, canvas.Focused()) canvas.FocusNext() diff --git a/widget/hyperlink_test.go b/widget/hyperlink_test.go index 55f17f0fe7..2a99595d26 100644 --- a/widget/hyperlink_test.go +++ b/widget/hyperlink_test.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" @@ -78,7 +79,7 @@ func TestHyperlink_Focus(t *testing.T) { app.Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) hyperlink := &Hyperlink{Text: "Test"} - w := test.NewWindow(hyperlink) + w := software.NewWindow(hyperlink) w.SetPadded(false) defer w.Close() w.Resize(hyperlink.MinSize()) @@ -160,7 +161,7 @@ func TestHyperlink_ThemeOverride(t *testing.T) { hyperlink := &Hyperlink{Text: "Test"} bg := canvas.NewRectangle(color.Gray{Y: 0xc0}) - w := test.NewWindow(&fyne.Container{Layout: layout.NewStackLayout(), + w := software.NewWindow(&fyne.Container{Layout: layout.NewStackLayout(), Objects: []fyne.CanvasObject{bg, hyperlink}}) w.SetPadded(false) defer w.Close() diff --git a/widget/icon_test.go b/widget/icon_test.go index b4c369326d..43ca1dcdfe 100644 --- a/widget/icon_test.go +++ b/widget/icon_test.go @@ -4,6 +4,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -27,7 +28,7 @@ func TestIcon_Layout(t *testing.T) { Resource: tt.resource, } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{icon}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{icon}}) window.Resize(icon.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "icon/layout_"+name+".xml", window.Canvas()) diff --git a/widget/label_test.go b/widget/label_test.go index d359683d96..c53ed03728 100644 --- a/widget/label_test.go +++ b/widget/label_test.go @@ -7,7 +7,8 @@ import ( "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/data/binding" "fyne.io/fyne/v2/internal/cache" - "fyne.io/fyne/v2/internal/painter/software" + "fyne.io/fyne/v2/internal/driver/software" + painter "fyne.io/fyne/v2/internal/painter/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -186,7 +187,7 @@ func TestLabel_ChangeTruncate(t *testing.T) { test.NewApp() defer test.NewApp() - c := test.NewCanvasWithPainter(software.NewPainter()) + c := software.NewCanvasWithPainter(painter.NewPainter()) c.SetPadded(false) text := NewLabel("Hello") c.SetContent(text) @@ -215,7 +216,7 @@ func TestLabelImportance(t *testing.T) { test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) lbl := NewLabel("hello, fyne") - w := test.NewWindow(lbl) + w := software.NewWindow(lbl) defer w.Close() test.AssertImageMatches(t, "label/label_importance_medium.png", w.Canvas().Capture()) diff --git a/widget/list_test.go b/widget/list_test.go index 74f2019ece..3a7d61df97 100644 --- a/widget/list_test.go +++ b/widget/list_test.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/data/binding" "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -126,7 +127,7 @@ func TestList_SetItemHeight(t *testing.T) { assert.Equal(t, fyne.NewSize(10, 10*5+(4*theme.Padding())+40), lay.MinSize()) list.Select(2) - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(200, 200)) test.AssertImageMatches(t, "list/list_item_height.png", w.Canvas().Capture()) } @@ -161,7 +162,7 @@ func TestList_OffsetChange(t *testing.T) { defer test.NewApp() list := createList(1000) - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(200, 400)) assert.Equal(t, float32(0), list.offsetY) @@ -406,7 +407,7 @@ func TestList_SmallList(t *testing.T) { item.(*fyne.Container).Objects[1].(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(200, 400)) visibleCount := len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) @@ -457,7 +458,7 @@ func TestList_RemoveItem(t *testing.T) { item.(*fyne.Container).Objects[1].(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(200, 400)) visibleCount := len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) @@ -491,7 +492,7 @@ func TestList_ScrollThenShrink(t *testing.T) { item.(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(300, 300)) visibles := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children @@ -531,7 +532,7 @@ func TestList_ScrollThenResizeWindow(t *testing.T) { item.(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(300, 300)) list.scroller.ScrollToBottom() @@ -547,7 +548,7 @@ func TestList_ScrollThenResizeWindow(t *testing.T) { func TestList_NoFunctionsSet(t *testing.T) { list := &List{} - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(200, 400)) list.Refresh() } @@ -555,11 +556,11 @@ func TestList_NoFunctionsSet(t *testing.T) { func TestList_Focus(t *testing.T) { defer test.NewApp() list := createList(10) - window := test.NewWindow(list) + window := software.NewWindow(list) defer window.Close() window.Resize(list.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) assert.Nil(t, canvas.Focused()) canvas.FocusNext() @@ -620,7 +621,7 @@ func changeData(list *List) { func setupList(t *testing.T) (*List, fyne.Window) { test.NewApp() list := createList(1000) - w := test.NewWindow(list) + w := software.NewWindow(list) w.Resize(fyne.NewSize(200, 400)) test.AssertRendersToMarkup(t, "list/initial.xml", w.Canvas()) return list, w @@ -642,7 +643,7 @@ func TestList_LimitUpdateItem(t *testing.T) { }, ) w.SetContent(list) - w.ShowAndRun() + w.Show() assert.Equal(t, "0.0.", printOut) list.scrollTo(1) assert.Equal(t, "0.0.1.", printOut) @@ -666,7 +667,7 @@ func TestList_RefreshUpdatesAllItems(t *testing.T) { }, ) w.SetContent(list) - w.ShowAndRun() + w.Show() assert.Equal(t, "0.", printOut) list.Refresh() diff --git a/widget/menu_desktop_test.go b/widget/menu_desktop_test.go index 4d4f5743a2..2dd0b1d2de 100644 --- a/widget/menu_desktop_test.go +++ b/widget/menu_desktop_test.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/internal/driver/software" internalWidget "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -23,7 +24,7 @@ func TestMenu_Layout(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -201,7 +202,7 @@ func TestMenu_Scrolling(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() w.SetPadded(false) c := w.Canvas() diff --git a/widget/menu_mobile_test.go b/widget/menu_mobile_test.go index 9c81ed0381..0d1abfd4d3 100644 --- a/widget/menu_mobile_test.go +++ b/widget/menu_mobile_test.go @@ -18,7 +18,7 @@ func TestMenu_Layout(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() w.SetPadded(false) c := w.Canvas() @@ -138,7 +138,7 @@ func TestMenu_Dragging(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) defer w.Close() w.SetPadded(false) c := w.Canvas() diff --git a/widget/popup_menu_test.go b/widget/popup_menu_test.go index bd1bec1dc5..13c9c972b7 100644 --- a/widget/popup_menu_test.go +++ b/widget/popup_menu_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/widget" ) @@ -93,7 +94,7 @@ func TestPopUpMenu_ShowAtPosition(t *testing.T) { func setupPopUpMenuTest() (*widget.PopUpMenu, fyne.Window) { test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) + w := software.NewWindow(canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) w.Resize(fyne.NewSize(200, 200)) m := widget.NewPopUpMenu(fyne.NewMenu( "", @@ -106,7 +107,7 @@ func setupPopUpMenuTest() (*widget.PopUpMenu, fyne.Window) { func setupPopUpMenuWithSubmenusTest(callback func(string)) (*widget.PopUpMenu, fyne.Window) { test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) + w := software.NewWindow(canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) w.Resize(fyne.NewSize(800, 600)) itemA := fyne.NewMenuItem("Option A", func() { callback("Option A") }) itemB := fyne.NewMenuItem("Option B", func() { callback("Option B") }) diff --git a/widget/popup_test.go b/widget/popup_test.go index 8a955ec236..310dae6c9d 100644 --- a/widget/popup_test.go +++ b/widget/popup_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" @@ -18,22 +19,22 @@ import ( func TestNewPopUp(t *testing.T) { label := NewLabel("Hi") - pop := NewPopUp(label, test.Canvas()) - defer test.Canvas().Overlays().Remove(pop) + pop := NewPopUp(label, software.Canvas()) + defer software.Canvas().Overlays().Remove(pop) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Equal(t, 0, len(software.Canvas().Overlays().List())) pop.Show() assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(test.Canvas().Overlays().List())) - assert.Equal(t, pop, test.Canvas().Overlays().List()[0]) + assert.Equal(t, 1, len(software.Canvas().Overlays().List())) + assert.Equal(t, pop, software.Canvas().Overlays().List()[0]) } func TestShowPopUp(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 200)) require.Nil(t, w.Canvas().Overlays().Top()) @@ -51,7 +52,7 @@ func TestShowPopUp(t *testing.T) { } func TestShowPopUpAtPosition(t *testing.T) { - c := test.NewCanvas() + c := software.NewCanvas() c.Resize(fyne.NewSize(100, 100)) pos := fyne.NewPos(6, 9) label := NewLabel("Hi") @@ -69,7 +70,7 @@ func TestShowPopUpAtRelativePosition(t *testing.T) { label := NewLabel("Hi") parent1 := NewLabel("Parent1") parent2 := NewLabel("Parent2") - w := test.NewWindow( + w := software.NewWindow( &fyne.Container{Layout: layout.NewVBoxLayout(), Objects: []fyne.CanvasObject{parent1, parent2}}) w.Resize(fyne.NewSize(100, 200)) @@ -86,7 +87,7 @@ func TestShowModalPopUp(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 199)) require.Nil(t, w.Canvas().Overlays().Top()) @@ -104,7 +105,7 @@ func TestShowModalPopUp(t *testing.T) { } func TestPopUp_Show(t *testing.T) { - c := test.NewCanvas() + c := software.NewCanvas() cSize := fyne.NewSize(100, 100) c.Resize(cSize) label := NewLabel("Hi") @@ -119,7 +120,7 @@ func TestPopUp_Show(t *testing.T) { } func TestPopUp_ShowAtPosition(t *testing.T) { - c := test.NewCanvas() + c := software.NewCanvas() cSize := fyne.NewSize(100, 100) c.Resize(cSize) label := NewLabel("Hi") @@ -137,18 +138,18 @@ func TestPopUp_ShowAtPosition(t *testing.T) { func TestPopUp_Hide(t *testing.T) { label := NewLabel("Hi") - pop := NewPopUp(label, test.Canvas()) + pop := NewPopUp(label, software.Canvas()) pop.Show() assert.True(t, pop.Visible()) pop.Hide() assert.False(t, pop.Visible()) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Equal(t, 0, len(software.Canvas().Overlays().List())) } func TestPopUp_MinSize(t *testing.T) { label := NewLabel("Hi") - pop := NewPopUp(label, test.Canvas()) + pop := NewPopUp(label, software.Canvas()) inner := pop.Content.MinSize() assert.Equal(t, label.MinSize().Width, inner.Width) @@ -161,11 +162,11 @@ func TestPopUp_MinSize(t *testing.T) { func TestPopUp_Move(t *testing.T) { label := NewLabel("Hi") - win := test.NewWindow(NewLabel("OK")) + win := software.NewWindow(NewLabel("OK")) defer win.Close() win.Resize(fyne.NewSize(70, 70)) pop := newPopUp(label, win.Canvas()) - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) pos := fyne.NewPos(10, 10) pop.Move(pos) @@ -179,12 +180,12 @@ func TestPopUp_Move(t *testing.T) { func TestPopUp_Move_Constrained(t *testing.T) { label := NewLabel("Hi") - win := test.NewWindow(NewLabel("OK")) + win := software.NewWindow(NewLabel("OK")) defer win.Close() win.Resize(fyne.NewSize(60, 48)) pop := NewPopUp(label, win.Canvas()) pop.Show() - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) pos := fyne.NewPos(30, 20) pop.Move(pos) @@ -202,12 +203,12 @@ func TestPopUp_Move_Constrained(t *testing.T) { func TestPopUp_Move_ConstrainedWindowToSmall(t *testing.T) { label := NewLabel("Hi") - win := test.NewWindow(NewLabel("OK")) + win := software.NewWindow(NewLabel("OK")) defer win.Close() win.Resize(fyne.NewSize(10, 5)) pop := NewPopUp(label, win.Canvas()) pop.Show() - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) pos := fyne.NewPos(20, 10) pop.Move(pos) @@ -219,13 +220,13 @@ func TestPopUp_Move_ConstrainedWindowToSmall(t *testing.T) { func TestPopUp_Resize(t *testing.T) { label := NewLabel("Hi") - win := test.NewWindow(NewLabel("OK")) + win := software.NewWindow(NewLabel("OK")) defer win.Close() win.Resize(fyne.NewSize(80, 80)) pop := newPopUp(label, win.Canvas()) pop.Show() - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) size := fyne.NewSize(60, 50) pop.Resize(size) @@ -238,67 +239,67 @@ func TestPopUp_Resize(t *testing.T) { func TestPopUp_Tapped(t *testing.T) { label := NewLabel("Hi") - pop := NewPopUp(label, test.Canvas()) + pop := NewPopUp(label, software.Canvas()) pop.Show() assert.True(t, pop.Visible()) test.Tap(pop) assert.False(t, pop.Visible()) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Equal(t, 0, len(software.Canvas().Overlays().List())) } func TestPopUp_TappedSecondary(t *testing.T) { label := NewLabel("Hi") - pop := NewPopUp(label, test.Canvas()) + pop := NewPopUp(label, software.Canvas()) pop.Show() assert.True(t, pop.Visible()) test.TapSecondary(pop) assert.False(t, pop.Visible()) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Equal(t, 0, len(software.Canvas().Overlays().List())) } func TestPopUp_Stacked(t *testing.T) { - assert.Nil(t, test.Canvas().Overlays().Top()) - assert.Empty(t, test.Canvas().Overlays().List()) + assert.Nil(t, software.Canvas().Overlays().Top()) + assert.Empty(t, software.Canvas().Overlays().List()) - pop1 := NewPopUp(NewLabel("Hi"), test.Canvas()) + pop1 := NewPopUp(NewLabel("Hi"), software.Canvas()) pop1.Show() assert.True(t, pop1.Visible()) - assert.Equal(t, pop1, test.Canvas().Overlays().Top()) - assert.Equal(t, []fyne.CanvasObject{pop1}, test.Canvas().Overlays().List()) + assert.Equal(t, pop1, software.Canvas().Overlays().Top()) + assert.Equal(t, []fyne.CanvasObject{pop1}, software.Canvas().Overlays().List()) - pop2 := NewPopUp(NewLabel("Hi"), test.Canvas()) + pop2 := NewPopUp(NewLabel("Hi"), software.Canvas()) pop2.Show() assert.True(t, pop1.Visible()) assert.True(t, pop2.Visible()) - assert.Equal(t, pop2, test.Canvas().Overlays().Top()) - assert.Equal(t, []fyne.CanvasObject{pop1, pop2}, test.Canvas().Overlays().List()) + assert.Equal(t, pop2, software.Canvas().Overlays().Top()) + assert.Equal(t, []fyne.CanvasObject{pop1, pop2}, software.Canvas().Overlays().List()) - pop3 := NewPopUp(NewLabel("Hi"), test.Canvas()) + pop3 := NewPopUp(NewLabel("Hi"), software.Canvas()) pop3.Show() assert.True(t, pop1.Visible()) assert.True(t, pop2.Visible()) assert.True(t, pop3.Visible()) - assert.Equal(t, pop3, test.Canvas().Overlays().Top()) - assert.Equal(t, []fyne.CanvasObject{pop1, pop2, pop3}, test.Canvas().Overlays().List()) + assert.Equal(t, pop3, software.Canvas().Overlays().Top()) + assert.Equal(t, []fyne.CanvasObject{pop1, pop2, pop3}, software.Canvas().Overlays().List()) pop3.Hide() assert.True(t, pop1.Visible()) assert.True(t, pop2.Visible()) assert.False(t, pop3.Visible()) - assert.Equal(t, pop2, test.Canvas().Overlays().Top()) - assert.Equal(t, []fyne.CanvasObject{pop1, pop2}, test.Canvas().Overlays().List()) + assert.Equal(t, pop2, software.Canvas().Overlays().Top()) + assert.Equal(t, []fyne.CanvasObject{pop1, pop2}, software.Canvas().Overlays().List()) // hiding a pop-up cuts stack pop1.Hide() assert.False(t, pop1.Visible()) - assert.Nil(t, test.Canvas().Overlays().Top()) - assert.Empty(t, test.Canvas().Overlays().List()) + assert.Nil(t, software.Canvas().Overlays().Top()) + assert.Empty(t, software.Canvas().Overlays().List()) } func TestPopUp_Layout(t *testing.T) { - win := test.NewWindow(NewLabel("OK")) + win := software.NewWindow(NewLabel("OK")) defer win.Close() win.Resize(fyne.NewSize(80, 80)) @@ -306,7 +307,7 @@ func TestPopUp_Layout(t *testing.T) { pop := newPopUp(content, win.Canvas()) pos := fyne.NewPos(6, 9) pop.ShowAtPosition(pos) - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) size := fyne.NewSize(60, 50) pop.Resize(size) @@ -328,7 +329,7 @@ func TestPopUp_Layout(t *testing.T) { func TestPopUp_ApplyThemeOnShow(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) pop := NewPopUp(NewLabel("Label"), w.Canvas()) @@ -352,7 +353,7 @@ func TestPopUp_ApplyThemeOnShow(t *testing.T) { func TestPopUp_ResizeOnShow(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -376,7 +377,7 @@ func TestPopUp_ResizeBeforeShow_CanvasSizeZero(t *testing.T) { // Simulate canvas size {0,0} rect := canvas.NewRectangle(color.Black) rect.SetMinSize(fyne.NewSize(0, 0)) - w := test.NewWindow(rect) + w := software.NewWindow(rect) w.SetPadded(false) w.Resize(fyne.NewSize(0, 0)) assert.Zero(t, w.Canvas().Size()) @@ -398,39 +399,39 @@ func TestPopUp_ResizeBeforeShow_CanvasSizeZero(t *testing.T) { func TestModalPopUp_Tapped(t *testing.T) { label := NewLabel("Hi") - pop := NewModalPopUp(label, test.Canvas()) + pop := NewModalPopUp(label, software.Canvas()) pop.Show() - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) assert.True(t, pop.Visible()) test.Tap(pop) assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(test.Canvas().Overlays().List())) - assert.Equal(t, pop, test.Canvas().Overlays().List()[0]) + assert.Equal(t, 1, len(software.Canvas().Overlays().List())) + assert.Equal(t, pop, software.Canvas().Overlays().List()[0]) } func TestModalPopUp_TappedSecondary(t *testing.T) { label := NewLabel("Hi") - pop := NewModalPopUp(label, test.Canvas()) + pop := NewModalPopUp(label, software.Canvas()) pop.Show() - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) assert.True(t, pop.Visible()) test.TapSecondary(pop) assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(test.Canvas().Overlays().List())) - assert.Equal(t, pop, test.Canvas().Overlays().List()[0]) + assert.Equal(t, 1, len(software.Canvas().Overlays().List())) + assert.Equal(t, pop, software.Canvas().Overlays().List()[0]) } func TestModalPopUp_Resize(t *testing.T) { label := NewLabel("Hi") - win := test.NewWindow(NewLabel("OK")) + win := software.NewWindow(NewLabel("OK")) defer win.Close() win.Resize(fyne.NewSize(80, 80)) pop := newModalPopUp(label, win.Canvas()) pop.Show() - defer test.Canvas().Overlays().Remove(pop) + defer software.Canvas().Overlays().Remove(pop) size := fyne.NewSize(50, 48) pop.Resize(size) @@ -443,7 +444,7 @@ func TestModalPopUp_Resize(t *testing.T) { func TestModalPopUp_Resize_Constrained(t *testing.T) { label := NewLabel("Hi") - win := test.NewWindow(NewLabel("OK")) + win := software.NewWindow(NewLabel("OK")) win.Resize(fyne.NewSize(80, 80)) pop := NewModalPopUp(label, win.Canvas()) @@ -457,7 +458,7 @@ func TestModalPopUp_Resize_Constrained(t *testing.T) { func TestModalPopUp_ApplyThemeOnShow(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) pop := NewModalPopUp(NewLabel("Label"), w.Canvas()) @@ -481,7 +482,7 @@ func TestModalPopUp_ApplyThemeOnShow(t *testing.T) { func TestModalPopUp_ResizeOnShow(t *testing.T) { test.NewApp() defer test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := software.NewWindow(canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -505,7 +506,7 @@ func TestModelPopUp_ResizeBeforeShow_CanvasSizeZero(t *testing.T) { // Simulate canvas size {0,0} rect := canvas.NewRectangle(color.Black) rect.SetMinSize(fyne.NewSize(0, 0)) - w := test.NewWindow(rect) + w := software.NewWindow(rect) w.SetPadded(false) w.Resize(fyne.NewSize(0, 0)) assert.Zero(t, w.Canvas().Size()) diff --git a/widget/radio_group_test.go b/widget/radio_group_test.go index a51639b29a..a273a16bac 100644 --- a/widget/radio_group_test.go +++ b/widget/radio_group_test.go @@ -4,6 +4,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/widget" @@ -14,11 +15,11 @@ import ( func TestRadioGroup_FocusRendering(t *testing.T) { t.Run("gain/lose focus", func(t *testing.T) { radio := widget.NewRadioGroup([]string{"Option A", "Option B", "Option C"}, nil) - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) defer window.Close() window.Resize(radio.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) test.AssertRendersToMarkup(t, "radio_group/focus_none_focused_none_selected.xml", canvas) canvas.FocusNext() test.AssertRendersToMarkup(t, "radio_group/focus_a_focused_none_selected.xml", canvas) @@ -39,11 +40,11 @@ func TestRadioGroup_FocusRendering(t *testing.T) { t.Run("disable/enable focused", func(t *testing.T) { radio := &widget.RadioGroup{Options: []string{"Option A", "Option B", "Option C"}} - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) defer window.Close() window.Resize(radio.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) canvas.FocusNext() radio.Disable() test.AssertRendersToMarkup(t, "radio_group/focus_disabled_none_selected.xml", canvas) @@ -53,11 +54,11 @@ func TestRadioGroup_FocusRendering(t *testing.T) { t.Run("append disabled", func(t *testing.T) { radio := &widget.RadioGroup{Options: []string{"Option A", "Option B"}} - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) defer window.Close() window.Resize(radio.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) radio.Disable() test.AssertRendersToMarkup(t, "radio_group/disabled_none_selected.xml", canvas) radio.Append("Option C") @@ -155,7 +156,7 @@ func TestRadioGroup_Layout(t *testing.T) { radio.Disable() } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) window.Resize(radio.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "radio_group/layout_"+name+".xml", window.Canvas()) @@ -167,12 +168,12 @@ func TestRadioGroup_Layout(t *testing.T) { func TestRadioGroup_ToggleSelectionWithSpaceKey(t *testing.T) { radio := &widget.RadioGroup{Options: []string{"Option A", "Option B", "Option C"}} - window := test.NewWindow(radio) + window := software.NewWindow(radio) defer window.Close() assert.Equal(t, "", radio.Selected) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) canvas.FocusNext() canvas.FocusNext() test.Type(canvas.Focused(), " ") diff --git a/widget/richtext_objects_test.go b/widget/richtext_objects_test.go index ff22b923b5..741905062d 100644 --- a/widget/richtext_objects_test.go +++ b/widget/richtext_objects_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + canvas2 "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/storage" "fyne.io/fyne/v2/test" ) @@ -43,7 +44,7 @@ func TestRichText_HyperLink(t *testing.T) { linkText := test.WidgetRenderer(richLink).Objects()[0].(*canvas.Text) assert.Equal(t, "Link", linkText.Text) - c := test.NewCanvas() + c := canvas2.NewCanvas() c.SetContent(text) assert.Equal(t, texts[0].Position().Y, linkText.Position().Y) } diff --git a/widget/richtext_test.go b/widget/richtext_test.go index eaff83bd0b..4b9359ef3a 100644 --- a/widget/richtext_test.go +++ b/widget/richtext_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -348,7 +349,7 @@ func TestText_Multiline(t *testing.T) { &TextSegment{Text: "line1\nli", Style: RichTextStyleStrong}, &TextSegment{Text: "ne2\nline3", Style: RichTextStyleInline}) - w := test.NewWindow(text) + w := software.NewWindow(text) w.Resize(fyne.NewSize(64, 90)) test.AssertImageMatches(t, "richtext/richtext_multiline.png", w.Canvas().Capture()) } diff --git a/widget/select_entry_internal_test.go b/widget/select_entry_internal_test.go index 0a14466d41..cf1815e459 100644 --- a/widget/select_entry_internal_test.go +++ b/widget/select_entry_internal_test.go @@ -4,6 +4,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -16,7 +17,7 @@ func TestSelectEntry_Disableable(t *testing.T) { options := []string{"A", "B", "C"} e := NewSelectEntry(options) - w := test.NewWindow(e) + w := software.NewWindow(e) defer w.Close() w.Resize(fyne.NewSize(150, 200)) e.Resize(e.MinSize().Max(fyne.NewSize(130, 0))) @@ -54,7 +55,7 @@ func TestSelectEntry_DropDown(t *testing.T) { options := []string{"A", "B", "C"} e := NewSelectEntry(options) - w := test.NewWindow(e) + w := software.NewWindow(e) defer w.Close() w.Resize(fyne.NewSize(150, 200)) e.Resize(e.MinSize().Max(fyne.NewSize(130, 0))) @@ -85,7 +86,7 @@ func TestSelectEntry_DropDownMove(t *testing.T) { defer test.NewApp() e := NewSelectEntry([]string{"one"}) - w := test.NewWindow(e) + w := software.NewWindow(e) defer w.Close() entrySize := e.MinSize() w.Resize(entrySize.Add(fyne.NewSize(100, 100))) @@ -117,7 +118,7 @@ func TestSelectEntry_DropDownResize(t *testing.T) { options := []string{"A", "B", "C"} e := NewSelectEntry(options) - w := test.NewWindow(e) + w := software.NewWindow(e) defer w.Close() w.Resize(fyne.NewSize(150, 200)) e.Resize(e.MinSize().Max(fyne.NewSize(130, 0))) @@ -185,7 +186,7 @@ func TestSelectEntry_SetOptions(t *testing.T) { defer test.NewApp() e := NewSelectEntry([]string{"A", "B", "C"}) - w := test.NewWindow(e) + w := software.NewWindow(e) defer w.Close() w.Resize(fyne.NewSize(150, 200)) e.Resize(e.MinSize().Max(fyne.NewSize(130, 0))) @@ -207,7 +208,7 @@ func TestSelectEntry_SetOptions_Empty(t *testing.T) { defer test.NewApp() e := NewSelectEntry([]string{}) - w := test.NewWindow(e) + w := software.NewWindow(e) defer w.Close() w.Resize(fyne.NewSize(150, 200)) e.Resize(e.MinSize().Max(fyne.NewSize(130, 0))) diff --git a/widget/select_internal_test.go b/widget/select_internal_test.go index a030e15035..3b52f61bb0 100644 --- a/widget/select_internal_test.go +++ b/widget/select_internal_test.go @@ -3,10 +3,12 @@ package widget import ( "testing" + "github.com/stretchr/testify/assert" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" - "github.com/stretchr/testify/assert" ) func TestSelect_SetOptions(t *testing.T) { @@ -41,7 +43,7 @@ func TestSelectRenderer_TapAnimation(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) sel := NewSelect([]string{"one"}, func(s string) {}) - w := test.NewWindow(sel) + w := software.NewWindow(sel) defer w.Close() w.Resize(sel.MinSize().Add(fyne.NewSize(10, 10))) sel.Resize(sel.MinSize()) diff --git a/widget/select_test.go b/widget/select_test.go index ac97654d09..c6de7d6749 100644 --- a/widget/select_test.go +++ b/widget/select_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/internal/cache" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -29,7 +30,7 @@ func TestSelect_Align(t *testing.T) { sel := widget.NewSelect([]string{"Hi"}, func(string) {}) sel.Alignment = fyne.TextAlignCenter - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) defer w.Close() w.Resize(fyne.NewSize(200, 150)) c := fyne.CurrentApp().Driver().CanvasForObject(sel) @@ -47,7 +48,7 @@ func TestSelect_ChangeTheme(t *testing.T) { defer test.NewApp() combo := widget.NewSelect([]string{"1", "2"}, func(s string) {}) - w := test.NewWindow(combo) + w := software.NewWindow(combo) defer w.Close() w.Resize(fyne.NewSize(220, 220)) combo.Resize(combo.MinSize()) @@ -108,7 +109,7 @@ func TestSelect_Disable(t *testing.T) { defer test.NewApp() sel := widget.NewSelect([]string{"Hi"}, func(string) {}) - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) defer w.Close() w.Resize(fyne.NewSize(200, 150)) c := fyne.CurrentApp().Driver().CanvasForObject(sel) @@ -153,7 +154,7 @@ func TestSelect_FocusRendering(t *testing.T) { t.Run("gain/lose focus", func(t *testing.T) { sel := widget.NewSelect([]string{"Option A", "Option B", "Option C"}, nil) - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) defer w.Close() w.Resize(fyne.NewSize(200, 150)) @@ -174,11 +175,11 @@ func TestSelect_FocusRendering(t *testing.T) { }) t.Run("disable/enable focused", func(t *testing.T) { sel := widget.NewSelect([]string{"Option A", "Option B", "Option C"}, nil) - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) defer w.Close() w.Resize(fyne.NewSize(200, 150)) - c := w.Canvas().(test.WindowlessCanvas) + c := w.Canvas().(software.WindowlessCanvas) c.FocusNext() test.AssertRendersToMarkup(t, "select/focus_focused_none_selected.xml", c) sel.Disable() @@ -194,7 +195,7 @@ func TestSelect_KeyboardControl(t *testing.T) { t.Run("activate pop-up", func(t *testing.T) { sel := widget.NewSelect([]string{"Option A", "Option B"}, nil) - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) defer w.Close() w.Resize(fyne.NewSize(150, 200)) c := w.Canvas() @@ -222,7 +223,7 @@ func TestSelect_KeyboardControl(t *testing.T) { t.Run("traverse options without pop-up", func(t *testing.T) { sel := widget.NewSelect([]string{"Option A", "Option B", "Option C"}, nil) - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) defer w.Close() w.Resize(fyne.NewSize(150, 200)) c := w.Canvas() @@ -258,7 +259,7 @@ func TestSelect_KeyboardControl(t *testing.T) { t.Run("trying to traverse empty options without pop-up", func(t *testing.T) { sel := widget.NewSelect([]string{}, nil) - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{sel}}) defer w.Close() w.Resize(fyne.NewSize(150, 200)) c := w.Canvas() @@ -286,7 +287,7 @@ func TestSelect_Move(t *testing.T) { defer test.NewApp() combo := widget.NewSelect([]string{"1", "2"}, nil) - w := test.NewWindow(combo) + w := software.NewWindow(combo) defer w.Close() w.Resize(fyne.NewSize(200, 150)) @@ -331,7 +332,7 @@ func TestSelect_SetSelected(t *testing.T) { triggered = true triggeredValue = s }) - w := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{combo}}) + w := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{combo}}) defer w.Close() w.Resize(fyne.NewSize(200, 150)) @@ -419,7 +420,7 @@ func TestSelect_Tapped(t *testing.T) { defer test.NewApp() combo := widget.NewSelect([]string{"1", "2"}, func(s string) {}) - w := test.NewWindow(combo) + w := software.NewWindow(combo) defer w.Close() w.Resize(fyne.NewSize(200, 150)) combo.Resize(combo.MinSize()) @@ -435,7 +436,7 @@ func TestSelect_Tapped_Constrained(t *testing.T) { defer test.NewApp() combo := widget.NewSelect([]string{"1", "2"}, func(s string) {}) - w := test.NewWindow(combo) + w := software.NewWindow(combo) defer w.Close() w.Resize(fyne.NewSize(200, 150)) combo.Resize(combo.MinSize()) @@ -548,7 +549,7 @@ func TestSelect_Layout(t *testing.T) { Selected: tt.selected, } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{combo}}) + window := software.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{combo}}) if tt.expanded { test.Tap(combo) } diff --git a/widget/slider_test.go b/widget/slider_test.go index 4dcc473a2a..1f3512ff3c 100644 --- a/widget/slider_test.go +++ b/widget/slider_test.go @@ -5,6 +5,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/data/binding" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -89,7 +90,7 @@ func TestSlider_HorizontalLayout(t *testing.T) { assert.Greater(t, wSize.Width, aSize.Width) assert.Equal(t, theme.InputBorderSize()*2, aSize.Height) - w := test.NewWindow(slider) + w := software.NewWindow(slider) defer w.Close() w.Resize(fyne.NewSize(220, 50)) @@ -132,7 +133,7 @@ func TestSlider_VerticalLayout(t *testing.T) { assert.Greater(t, wSize.Height, aSize.Height) assert.Equal(t, theme.InputBorderSize()*2, aSize.Width) - w := test.NewWindow(slider) + w := software.NewWindow(slider) defer w.Close() w.Resize(fyne.NewSize(50, 220)) diff --git a/widget/table_desktop_test.go b/widget/table_desktop_test.go index e06990b227..ba134b4841 100644 --- a/widget/table_desktop_test.go +++ b/widget/table_desktop_test.go @@ -7,6 +7,7 @@ import ( "testing" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "github.com/stretchr/testify/assert" @@ -25,7 +26,7 @@ func TestTable_Hovered(t *testing.T) { c.(*Label).SetText(fmt.Sprintf("Cell %d, %d", id.Row, id.Col)) }) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(180, 180)) diff --git a/widget/table_test.go b/widget/table_test.go index b634f532a8..3cd598c2c8 100644 --- a/widget/table_test.go +++ b/widget/table_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -25,7 +26,7 @@ func TestTable_Empty(t *testing.T) { } func TestTable_Cache(t *testing.T) { - c := test.NewCanvas() + c := software.NewCanvas() table := NewTable( func() (int, int) { return 3, 5 }, func() fyne.CanvasObject { @@ -70,7 +71,7 @@ func TestTable_ChangeTheme(t *testing.T) { table.Resize(fyne.NewSize(50, 30)) content := test.WidgetRenderer(table.content.Content.(*tableCells)).(*tableCellsRenderer) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(180, 180)) test.AssertImageMatches(t, "table/theme_initial.png", w.Canvas().Capture()) @@ -99,7 +100,7 @@ func TestTable_Filled(t *testing.T) { }, func(TableCellID, fyne.CanvasObject) {}) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(180, 180)) w.Content().Refresh() @@ -119,11 +120,11 @@ func TestTable_Focus(t *testing.T) { }, func(TableCellID, fyne.CanvasObject) {}) - window := test.NewWindow(table) + window := software.NewWindow(table) defer window.Close() window.Resize(table.MinSize().Max(fyne.NewSize(300, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) assert.Nil(t, canvas.Focused()) canvas.FocusNext() @@ -179,7 +180,7 @@ func TestTable_JustHeaders(t *testing.T) { func(_ TableCellID, _ fyne.CanvasObject) { }) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(120, 120)) @@ -315,7 +316,7 @@ func TestTable_Resize(t *testing.T) { }, func(TableCellID, fyne.CanvasObject) {}) - w := test.NewWindow(table) + w := software.NewWindow(table) w.Resize(fyne.NewSize(100, 100)) test.AssertImageMatches(t, "table/resize.png", w.Canvas().Capture()) } @@ -339,7 +340,7 @@ func TestTable_Unselect(t *testing.T) { unselectedColumn = id.Col } table.selectedCell = &TableCellID{1, 1} - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(180, 180)) @@ -407,7 +408,7 @@ func TestTable_ScrollTo(t *testing.T) { func() fyne.CanvasObject { return templ }, func(TableCellID, fyne.CanvasObject) {}) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() // these position expectations have a built-in assumption that the window @@ -501,7 +502,7 @@ func TestTable_ScrollToBottom(t *testing.T) { func() fyne.CanvasObject { return templ }, func(TableCellID, fyne.CanvasObject) {}) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(200, 200)) @@ -530,7 +531,7 @@ func TestTable_ScrollToLeading(t *testing.T) { c.(*Label).SetText(text) }) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() table.ScrollTo(TableCellID{Row: 8, Col: 4}) @@ -561,7 +562,7 @@ func TestTable_ScrollToTop(t *testing.T) { func() fyne.CanvasObject { return templ }, func(TableCellID, fyne.CanvasObject) {}) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() table.ScrollTo(TableCellID{12, 3}) @@ -588,7 +589,7 @@ func TestTable_ScrollToTrailing(t *testing.T) { c.(*Label).SetText(text) }) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(200, 200)) @@ -618,7 +619,7 @@ func TestTable_Selection(t *testing.T) { }) assert.Nil(t, table.selectedCell) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(180, 180)) @@ -662,7 +663,7 @@ func TestTable_Selection_OnHeader(t *testing.T) { }) assert.Nil(t, table.selectedCell) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(180, 180)) @@ -691,7 +692,7 @@ func TestTable_Select(t *testing.T) { c.(*Label).SetText(text) }) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(180, 180)) @@ -748,7 +749,7 @@ func TestTable_SetColumnWidth(t *testing.T) { assert.Equal(t, float32(24), cellRenderer.(*tableCellsRenderer).Objects()[0].Size().Width) assert.Equal(t, float32(24)+cell1Offset, cellRenderer.(*tableCellsRenderer).Objects()[1].Position().X) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(120+(2*theme.Padding()), 120+(2*theme.Padding()))) test.AssertImageMatches(t, "table/col_size.png", w.Canvas().Capture()) @@ -768,7 +769,7 @@ func TestTable_SetColumnWidth_Dragged(t *testing.T) { table.StickyColumnCount = 0 table.Refresh() - c := test.NewCanvas() + c := software.NewCanvas() c.SetPadded(false) c.SetContent(table) c.Resize(fyne.NewSize(120, 120)) @@ -828,7 +829,7 @@ func TestTable_SetRowHeight(t *testing.T) { assert.Equal(t, float32(32), cellRenderer.(*tableCellsRenderer).Objects()[0].Size().Height) assert.Equal(t, float32(32)+cell1Offset, cellRenderer.(*tableCellsRenderer).Objects()[3].Position().Y) - w := test.NewWindow(table) + w := software.NewWindow(table) defer w.Close() w.Resize(fyne.NewSize(120+(2*theme.Padding()), 120+(2*theme.Padding()))) test.AssertImageMatches(t, "table/row_size.png", w.Canvas().Capture()) @@ -848,7 +849,7 @@ func TestTable_SetRowHeight_Dragged(t *testing.T) { table.StickyRowCount = 0 table.Refresh() - c := test.NewCanvas() + c := software.NewCanvas() c.SetPadded(false) c.SetContent(table) c.Resize(fyne.NewSize(120, 150)) diff --git a/widget/tree_internal_test.go b/widget/tree_internal_test.go index 2107b4c982..bc7b8d4818 100644 --- a/widget/tree_internal_test.go +++ b/widget/tree_internal_test.go @@ -8,6 +8,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/internal/driver/software" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -167,11 +168,11 @@ func TestTree_Focus(t *testing.T) { "foo": {"foobar", "barbar"}, } tree := NewTreeWithStrings(treeData) - window := test.NewWindow(tree) + window := software.NewWindow(tree) defer window.Close() window.Resize(tree.MinSize().Max(fyne.NewSize(150, 200))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) assert.Nil(t, canvas.Focused()) canvas.FocusNext() @@ -214,11 +215,11 @@ func TestTree_Keyboard(t *testing.T) { "item_1_2": {"item_1_2_1", "item_1_2_2"}, } tree := NewTreeWithStrings(treeData) - window := test.NewWindow(tree) + window := software.NewWindow(tree) defer window.Close() window.Resize(tree.MinSize().Max(fyne.NewSize(250, 400))) - canvas := window.Canvas().(test.WindowlessCanvas) + canvas := window.Canvas().(software.WindowlessCanvas) assert.Nil(t, canvas.Focused()) // Start with a fully collapsed tree @@ -570,7 +571,7 @@ func TestTree_ScrollTo(t *testing.T) { tree.OpenBranch("D") tree.OpenBranch("E") - w := test.NewWindow(tree) + w := software.NewWindow(tree) defer w.Close() var ( @@ -606,7 +607,7 @@ func TestTree_ScrollToBottom(t *testing.T) { tree.OpenBranch("D") tree.OpenBranch("E") - w := test.NewWindow(tree) + w := software.NewWindow(tree) defer w.Close() var ( @@ -675,7 +676,7 @@ func TestTree_ScrollToTop(t *testing.T) { tree.OpenBranch("D") tree.OpenBranch("E") - w := test.NewWindow(tree) + w := software.NewWindow(tree) defer w.Close() tree.ScrollTo("F") @@ -878,7 +879,7 @@ func TestTree_RefreshItem(t *testing.T) { } tree.OpenBranch("foo") - c := test.NewWindow(tree) + c := software.NewWindow(tree) c.Resize(fyne.NewSize(100, 100)) r := test.WidgetRenderer(tree.scroller.Content.(*treeContent)).(*treeContentRenderer) diff --git a/widget/tree_test.go b/widget/tree_test.go index d53b3fc5cf..3209d2fb61 100644 --- a/widget/tree_test.go +++ b/widget/tree_test.go @@ -7,6 +7,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/data/binding" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" "fyne.io/fyne/v2/test" "fyne.io/fyne/v2/theme" @@ -275,7 +276,7 @@ func TestTree_Layout(t *testing.T) { } tree.Select(tt.selected) - window := test.NewWindow(tree) + window := software.NewWindow(tree) defer window.Close() window.Resize(fyne.NewSize(200, 300)) @@ -293,7 +294,7 @@ func TestTree_ChangeTheme(t *testing.T) { tree := widget.NewTreeWithStrings(treeData) tree.OpenBranch("foo") - window := test.NewWindow(tree) + window := software.NewWindow(tree) defer window.Close() window.Resize(fyne.NewSize(220, 220)) @@ -315,7 +316,7 @@ func TestTree_Move(t *testing.T) { tree := widget.NewTreeWithStrings(treeData) tree.OpenBranch("foo") - window := test.NewWindow(tree) + window := software.NewWindow(tree) defer window.Close() window.Resize(fyne.NewSize(220, 220)) @@ -345,7 +346,7 @@ func TestTree_Refresh(t *testing.T) { } tree.OpenBranch("foo") - window := test.NewWindow(tree) + window := software.NewWindow(tree) defer window.Close() window.Resize(fyne.NewSize(220, 220)) diff --git a/widget/widget_test.go b/widget/widget_test.go index 780ff2ec8e..c0da38d4f9 100644 --- a/widget/widget_test.go +++ b/widget/widget_test.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/internal/driver/software" internalTest "fyne.io/fyne/v2/internal/test" internalWidget "fyne.io/fyne/v2/internal/widget" "fyne.io/fyne/v2/layout" @@ -34,7 +35,7 @@ func (m *myWidget) CreateRenderer() fyne.WidgetRenderer { func TestApplyThemeCalled(t *testing.T) { widget := &myWidget{refreshed: make(chan bool)} - window := test.NewWindow(widget) + window := software.NewWindow(widget) fyne.CurrentApp().Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) func() { @@ -52,7 +53,7 @@ func TestApplyThemeCalledChild(t *testing.T) { child := &myWidget{refreshed: make(chan bool)} parent := &fyne.Container{Layout: layout.NewVBoxLayout(), Objects: []fyne.CanvasObject{child}} - window := test.NewWindow(parent) + window := software.NewWindow(parent) fyne.CurrentApp().Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) func() { select { @@ -73,7 +74,7 @@ func TestSimpleRenderer(t *testing.T) { newTestWidget(canvas.NewRectangle(color.Gray{Y: 0x79})), newTestWidget(canvas.NewText("Hi", color.Black))}} - window := test.NewWindow(c) + window := software.NewWindow(c) defer window.Close() test.AssertImageMatches(t, "simple_renderer.png", window.Canvas().Capture())