From a5c20c0c317055338627f1af7420801dd91a8a21 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Mon, 22 Jun 2020 14:28:21 +0200 Subject: [PATCH 1/3] WIP - Fix a lot of recommendations from staticcheck --- app/app_test.go | 3 --- app/settings_desktop_test.go | 6 +++--- cmd/fyne/vendor.go | 4 ++-- cmd/fyne/version.go | 2 +- cmd/fyne_demo/screens/window.go | 2 +- cmd/fyne_settings/data/gen.go | 1 - cmd/fyne_settings/data/language.svg | 1 - cmd/fyne_settings/settings/bundled.go | 4 ---- driver/desktop/shortcut_test.go | 2 -- internal/driver/glfw/window.go | 3 +-- internal/painter/gl/gl_core.go | 2 +- internal/painter/image.go | 2 +- internal/painter/software/draw.go | 4 ++-- internal/painter/software/painter.go | 2 +- test/testapp.go | 9 +-------- test/testcanvas.go | 2 +- test/util_test.go | 4 ++-- widget/entry.go | 16 ++++++++-------- widget/group_test.go | 1 - widget/progressbarinfinite.go | 7 ++----- widget/radio_extended_test.go | 1 - widget/radio_internal_test.go | 1 - widget/widget.go | 3 +-- 23 files changed, 28 insertions(+), 54 deletions(-) delete mode 100644 cmd/fyne_settings/data/language.svg diff --git a/app/app_test.go b/app/app_test.go index ccb5c0f709..f511e2358f 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -46,8 +46,5 @@ func TestFyneApp_OpenURL(t *testing.T) { return // when running in CI mode we don't actually open URLs... } - // wait for the command to execute then check the URL we loaded - for opened == "" { - } assert.Equal(t, urlStr, opened) } diff --git a/app/settings_desktop_test.go b/app/settings_desktop_test.go index ddd7cef0dc..6dbca7362c 100644 --- a/app/settings_desktop_test.go +++ b/app/settings_desktop_test.go @@ -37,7 +37,7 @@ func TestWatchSettings(t *testing.T) { settings.fileChanged() // simulate the settings file changing select { - case _ = <-listener: + case <-listener: case <-time.After(100 * time.Millisecond): t.Error("Settings listener was not called") } @@ -58,7 +58,7 @@ func TestWatchFile(t *testing.T) { file.Close() select { - case _ = <-called: + case <-called: case <-time.After(100 * time.Millisecond): t.Error("File watcher callback was not called") } @@ -84,7 +84,7 @@ func TestFileWatcher_FileDeleted(t *testing.T) { f, _ = os.Create(path) select { - case _ = <-called: + case <-called: case <-time.After(100 * time.Millisecond): t.Error("File watcher callback was not called") } diff --git a/cmd/fyne/vendor.go b/cmd/fyne/vendor.go index 63d882e946..4c69f8acdd 100644 --- a/cmd/fyne/vendor.go +++ b/cmd/fyne/vendor.go @@ -65,7 +65,7 @@ func cacheModPath(r io.Reader) (string, string, error) { } if err := scanner.Err(); err != nil { - return "", "", fmt.Errorf("Cannot read content: %v", err) + return "", "", fmt.Errorf("cannot read content: %v", err) } return "", "", nil } @@ -73,7 +73,7 @@ func cacheModPath(r io.Reader) (string, string, error) { func recursiveCopy(src, target string) error { files, err := ioutil.ReadDir(src) if err != nil { - return fmt.Errorf("Cannot read dir %s: %v", src, err) + return fmt.Errorf("cannot read dir %s: %v", src, err) } err = ensureDir(target) if err != nil { diff --git a/cmd/fyne/version.go b/cmd/fyne/version.go index d74de66635..155f3da4c1 100644 --- a/cmd/fyne/version.go +++ b/cmd/fyne/version.go @@ -43,7 +43,7 @@ func (v *version) run(args []string) { func (v *version) get() (string, error) { info, ok := debug.ReadBuildInfo() if !ok { - return "", fmt.Errorf("Could not retrieve version information. Please ensure module support is activated and build again") + return "", fmt.Errorf("could not retrieve version information (ensure module support is activated and build again)") } return info.Main.Version, nil } diff --git a/cmd/fyne_demo/screens/window.go b/cmd/fyne_demo/screens/window.go index f79d68b27a..0053a3ce5a 100644 --- a/cmd/fyne_demo/screens/window.go +++ b/cmd/fyne_demo/screens/window.go @@ -100,7 +100,7 @@ func loadDialogGroup(win fyne.Window) *widget.Group { dialog.ShowInformation("Information", "You should know this thing...", win) }), widget.NewButton("Error", func() { - err := errors.New("A dummy error message") + err := errors.New("a dummy error message") dialog.ShowError(err, win) }), widget.NewButton("Confirm", func() { diff --git a/cmd/fyne_settings/data/gen.go b/cmd/fyne_settings/data/gen.go index 760cab3c10..49d6ddfb22 100644 --- a/cmd/fyne_settings/data/gen.go +++ b/cmd/fyne_settings/data/gen.go @@ -57,5 +57,4 @@ func main() { bundleFile("themeLightPreview", "widgets-light.png", f) bundleFile("appearanceIcon", "appearance.svg", f) - bundleFile("languageIcon", "language.svg", f) } diff --git a/cmd/fyne_settings/data/language.svg b/cmd/fyne_settings/data/language.svg deleted file mode 100644 index a45572e4dd..0000000000 --- a/cmd/fyne_settings/data/language.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/cmd/fyne_settings/settings/bundled.go b/cmd/fyne_settings/settings/bundled.go index 8efc487ea3..e6b218a1cc 100644 --- a/cmd/fyne_settings/settings/bundled.go +++ b/cmd/fyne_settings/settings/bundled.go @@ -16,7 +16,3 @@ var appearanceIcon = &fyne.StaticResource{ StaticName: "appearance.svg", StaticContent: []byte{ 60, 115, 118, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47, 50, 48, 48, 48, 47, 115, 118, 103, 34, 32, 119, 105, 100, 116, 104, 61, 34, 50, 52, 34, 32, 104, 101, 105, 103, 104, 116, 61, 34, 50, 52, 34, 32, 118, 105, 101, 119, 66, 111, 120, 61, 34, 48, 32, 48, 32, 50, 52, 32, 50, 52, 34, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 48, 32, 48, 104, 50, 52, 118, 50, 52, 72, 48, 122, 34, 32, 102, 105, 108, 108, 61, 34, 110, 111, 110, 101, 34, 47, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 50, 49, 32, 51, 72, 51, 99, 45, 49, 46, 49, 32, 48, 45, 50, 32, 46, 57, 45, 50, 32, 50, 118, 49, 52, 99, 48, 32, 49, 46, 49, 46, 57, 32, 50, 32, 50, 32, 50, 104, 49, 56, 99, 49, 46, 49, 32, 48, 32, 50, 45, 46, 57, 32, 50, 45, 50, 86, 53, 99, 48, 45, 49, 46, 49, 45, 46, 57, 45, 50, 45, 50, 45, 50, 122, 109, 48, 32, 49, 54, 46, 48, 49, 72, 51, 86, 52, 46, 57, 57, 104, 49, 56, 118, 49, 52, 46, 48, 50, 122, 77, 56, 32, 49, 54, 104, 50, 46, 53, 108, 49, 46, 53, 32, 49, 46, 53, 32, 49, 46, 53, 45, 49, 46, 53, 72, 49, 54, 118, 45, 50, 46, 53, 108, 49, 46, 53, 45, 49, 46, 53, 45, 49, 46, 53, 45, 49, 46, 53, 86, 56, 104, 45, 50, 46, 53, 76, 49, 50, 32, 54, 46, 53, 32, 49, 48, 46, 53, 32, 56, 72, 56, 118, 50, 46, 53, 76, 54, 46, 53, 32, 49, 50, 32, 56, 32, 49, 51, 46, 53, 86, 49, 54, 122, 109, 52, 45, 55, 99, 49, 46, 54, 54, 32, 48, 32, 51, 32, 49, 46, 51, 52, 32, 51, 32, 51, 115, 45, 49, 46, 51, 52, 32, 51, 45, 51, 32, 51, 86, 57, 122, 34, 47, 62, 60, 47, 115, 118, 103, 62}} -var languageIcon = &fyne.StaticResource{ - StaticName: "language.svg", - StaticContent: []byte{ - 60, 115, 118, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47, 50, 48, 48, 48, 47, 115, 118, 103, 34, 32, 119, 105, 100, 116, 104, 61, 34, 50, 52, 34, 32, 104, 101, 105, 103, 104, 116, 61, 34, 50, 52, 34, 32, 118, 105, 101, 119, 66, 111, 120, 61, 34, 48, 32, 48, 32, 50, 52, 32, 50, 52, 34, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 48, 32, 48, 104, 50, 52, 118, 50, 52, 72, 48, 122, 34, 32, 102, 105, 108, 108, 61, 34, 110, 111, 110, 101, 34, 47, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 49, 49, 46, 57, 57, 32, 50, 67, 54, 46, 52, 55, 32, 50, 32, 50, 32, 54, 46, 52, 56, 32, 50, 32, 49, 50, 115, 52, 46, 52, 55, 32, 49, 48, 32, 57, 46, 57, 57, 32, 49, 48, 67, 49, 55, 46, 53, 50, 32, 50, 50, 32, 50, 50, 32, 49, 55, 46, 53, 50, 32, 50, 50, 32, 49, 50, 83, 49, 55, 46, 53, 50, 32, 50, 32, 49, 49, 46, 57, 57, 32, 50, 122, 109, 54, 46, 57, 51, 32, 54, 104, 45, 50, 46, 57, 53, 99, 45, 46, 51, 50, 45, 49, 46, 50, 53, 45, 46, 55, 56, 45, 50, 46, 52, 53, 45, 49, 46, 51, 56, 45, 51, 46, 53, 54, 32, 49, 46, 56, 52, 46, 54, 51, 32, 51, 46, 51, 55, 32, 49, 46, 57, 49, 32, 52, 46, 51, 51, 32, 51, 46, 53, 54, 122, 77, 49, 50, 32, 52, 46, 48, 52, 99, 46, 56, 51, 32, 49, 46, 50, 32, 49, 46, 52, 56, 32, 50, 46, 53, 51, 32, 49, 46, 57, 49, 32, 51, 46, 57, 54, 104, 45, 51, 46, 56, 50, 99, 46, 52, 51, 45, 49, 46, 52, 51, 32, 49, 46, 48, 56, 45, 50, 46, 55, 54, 32, 49, 46, 57, 49, 45, 51, 46, 57, 54, 122, 77, 52, 46, 50, 54, 32, 49, 52, 67, 52, 46, 49, 32, 49, 51, 46, 51, 54, 32, 52, 32, 49, 50, 46, 54, 57, 32, 52, 32, 49, 50, 115, 46, 49, 45, 49, 46, 51, 54, 46, 50, 54, 45, 50, 104, 51, 46, 51, 56, 99, 45, 46, 48, 56, 46, 54, 54, 45, 46, 49, 52, 32, 49, 46, 51, 50, 45, 46, 49, 52, 32, 50, 32, 48, 32, 46, 54, 56, 46, 48, 54, 32, 49, 46, 51, 52, 46, 49, 52, 32, 50, 72, 52, 46, 50, 54, 122, 109, 46, 56, 50, 32, 50, 104, 50, 46, 57, 53, 99, 46, 51, 50, 32, 49, 46, 50, 53, 46, 55, 56, 32, 50, 46, 52, 53, 32, 49, 46, 51, 56, 32, 51, 46, 53, 54, 45, 49, 46, 56, 52, 45, 46, 54, 51, 45, 51, 46, 51, 55, 45, 49, 46, 57, 45, 52, 46, 51, 51, 45, 51, 46, 53, 54, 122, 109, 50, 46, 57, 53, 45, 56, 72, 53, 46, 48, 56, 99, 46, 57, 54, 45, 49, 46, 54, 54, 32, 50, 46, 52, 57, 45, 50, 46, 57, 51, 32, 52, 46, 51, 51, 45, 51, 46, 53, 54, 67, 56, 46, 56, 49, 32, 53, 46, 53, 53, 32, 56, 46, 51, 53, 32, 54, 46, 55, 53, 32, 56, 46, 48, 51, 32, 56, 122, 77, 49, 50, 32, 49, 57, 46, 57, 54, 99, 45, 46, 56, 51, 45, 49, 46, 50, 45, 49, 46, 52, 56, 45, 50, 46, 53, 51, 45, 49, 46, 57, 49, 45, 51, 46, 57, 54, 104, 51, 46, 56, 50, 99, 45, 46, 52, 51, 32, 49, 46, 52, 51, 45, 49, 46, 48, 56, 32, 50, 46, 55, 54, 45, 49, 46, 57, 49, 32, 51, 46, 57, 54, 122, 77, 49, 52, 46, 51, 52, 32, 49, 52, 72, 57, 46, 54, 54, 99, 45, 46, 48, 57, 45, 46, 54, 54, 45, 46, 49, 54, 45, 49, 46, 51, 50, 45, 46, 49, 54, 45, 50, 32, 48, 45, 46, 54, 56, 46, 48, 55, 45, 49, 46, 51, 53, 46, 49, 54, 45, 50, 104, 52, 46, 54, 56, 99, 46, 48, 57, 46, 54, 53, 46, 49, 54, 32, 49, 46, 51, 50, 46, 49, 54, 32, 50, 32, 48, 32, 46, 54, 56, 45, 46, 48, 55, 32, 49, 46, 51, 52, 45, 46, 49, 54, 32, 50, 122, 109, 46, 50, 53, 32, 53, 46, 53, 54, 99, 46, 54, 45, 49, 46, 49, 49, 32, 49, 46, 48, 54, 45, 50, 46, 51, 49, 32, 49, 46, 51, 56, 45, 51, 46, 53, 54, 104, 50, 46, 57, 53, 99, 45, 46, 57, 54, 32, 49, 46, 54, 53, 45, 50, 46, 52, 57, 32, 50, 46, 57, 51, 45, 52, 46, 51, 51, 32, 51, 46, 53, 54, 122, 77, 49, 54, 46, 51, 54, 32, 49, 52, 99, 46, 48, 56, 45, 46, 54, 54, 46, 49, 52, 45, 49, 46, 51, 50, 46, 49, 52, 45, 50, 32, 48, 45, 46, 54, 56, 45, 46, 48, 54, 45, 49, 46, 51, 52, 45, 46, 49, 52, 45, 50, 104, 51, 46, 51, 56, 99, 46, 49, 54, 46, 54, 52, 46, 50, 54, 32, 49, 46, 51, 49, 46, 50, 54, 32, 50, 115, 45, 46, 49, 32, 49, 46, 51, 54, 45, 46, 50, 54, 32, 50, 104, 45, 51, 46, 51, 56, 122, 34, 47, 62, 60, 47, 115, 118, 103, 62}} diff --git a/driver/desktop/shortcut_test.go b/driver/desktop/shortcut_test.go index 7837159ebe..cb7afbe610 100644 --- a/driver/desktop/shortcut_test.go +++ b/driver/desktop/shortcut_test.go @@ -47,8 +47,6 @@ func TestCustomShortcut_Shortcut(t *testing.T) { } func Test_modifierToString(t *testing.T) { - type args struct { - } tests := []struct { name string mods Modifier diff --git a/internal/driver/glfw/window.go b/internal/driver/glfw/window.go index 4bde2f9d92..34c4c0543b 100644 --- a/internal/driver/glfw/window.go +++ b/internal/driver/glfw/window.go @@ -51,7 +51,6 @@ type window struct { fixedSize bool cursor *glfw.Cursor - painted int // part of the macOS GL fix, updated GLFW should fix this canvas *glCanvas title string icon fyne.Resource @@ -653,7 +652,7 @@ func (w *window) mouseClicked(_ *glfw.Window, btn glfw.MouseButton, action glfw. _, tap := co.(fyne.Tappable) _, altTap := co.(fyne.SecondaryTappable) // Prevent Tapped from triggering if DoubleTapped has been sent - if (tap || altTap) && doubleTapped == false { + if (tap || altTap) && !doubleTapped { if action == glfw.Press { w.mousePressed = co } else if action == glfw.Release { diff --git a/internal/painter/gl/gl_core.go b/internal/painter/gl/gl_core.go index 101ab266da..c5524f504f 100644 --- a/internal/painter/gl/gl_core.go +++ b/internal/painter/gl/gl_core.go @@ -74,7 +74,7 @@ func (p *glPainter) imgToTexture(img image.Image, textureFilter canvas.ImageScal return texture default: rgba := image.NewRGBA(image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy())) - draw.Draw(rgba, rgba.Rect, img, image.ZP, draw.Over) + draw.Draw(rgba, rgba.Rect, img, image.Point{}, draw.Over) return p.imgToTexture(rgba, textureFilter) } } diff --git a/internal/painter/image.go b/internal/painter/image.go index f0827bf68c..040c1d4ca2 100644 --- a/internal/painter/image.go +++ b/internal/painter/image.go @@ -125,7 +125,7 @@ func drawSVGSafely(icon *oksvg.SvgIcon, raster *rasterx.Dasher) error { var err error defer func() { if r := recover(); r != nil { - err = errors.New("Crash when rendering SVG") + err = errors.New("crash when rendering svg") } }() icon.Draw(raster, 1) diff --git a/internal/painter/software/draw.go b/internal/painter/software/draw.go index 636b88b39e..ba8f25874f 100644 --- a/internal/painter/software/draw.go +++ b/internal/painter/software/draw.go @@ -121,7 +121,7 @@ func drawRectangle(c fyne.Canvas, rect *canvas.Rectangle, pos fyne.Position, bas scaledHeight := internal.ScaleInt(c, rect.Size().Height) scaledX, scaledY := internal.ScaleInt(c, pos.X), internal.ScaleInt(c, pos.Y) bounds := clip.Intersect(image.Rect(scaledX, scaledY, scaledX+scaledWidth, scaledY+scaledHeight)) - draw.Draw(base, bounds, image.NewUniform(rect.FillColor), image.ZP, draw.Over) + draw.Draw(base, bounds, image.NewUniform(rect.FillColor), image.Point{}, draw.Over) } func drawWidget(c fyne.Canvas, wid fyne.Widget, pos fyne.Position, base *image.NRGBA, clip image.Rectangle) { @@ -129,5 +129,5 @@ func drawWidget(c fyne.Canvas, wid fyne.Widget, pos fyne.Position, base *image.N scaledHeight := internal.ScaleInt(c, wid.Size().Height) scaledX, scaledY := internal.ScaleInt(c, pos.X), internal.ScaleInt(c, pos.Y) bounds := clip.Intersect(image.Rect(scaledX, scaledY, scaledX+scaledWidth, scaledY+scaledHeight)) - draw.Draw(base, bounds, image.NewUniform(cache.Renderer(wid).BackgroundColor()), image.ZP, draw.Over) + draw.Draw(base, bounds, image.NewUniform(cache.Renderer(wid).BackgroundColor()), image.Point{}, draw.Over) } diff --git a/internal/painter/software/painter.go b/internal/painter/software/painter.go index 59870f65f1..50df8730bd 100644 --- a/internal/painter/software/painter.go +++ b/internal/painter/software/painter.go @@ -28,7 +28,7 @@ func (*Painter) Paint(c fyne.Canvas) image.Image { size := c.Size().Max(c.Content().MinSize()) bounds := image.Rect(0, 0, internal.ScaleInt(c, size.Width), internal.ScaleInt(c, size.Height)) base := image.NewNRGBA(bounds) - draw.Draw(base, bounds, image.NewUniform(theme.BackgroundColor()), image.ZP, draw.Src) + draw.Draw(base, bounds, image.NewUniform(theme.BackgroundColor()), image.Point{}, draw.Src) paint := func(obj fyne.CanvasObject, pos, clipPos fyne.Position, clipSize fyne.Size) bool { clip := image.Rect( diff --git a/test/testapp.go b/test/testapp.go index 73d33c4c52..d1fd447a3d 100644 --- a/test/testapp.go +++ b/test/testapp.go @@ -83,13 +83,6 @@ func (a *testApp) lastAppliedTheme() fyne.Theme { return a.appliedTheme } -func (a *testApp) lastNotificationSent() *fyne.Notification { - a.propertyLock.Lock() - defer a.propertyLock.Unlock() - - return a.lastNotification -} - // NewApp returns a new dummy app used for testing. // It loads a test driver which creates a virtual window in memory for testing. func NewApp() fyne.App { @@ -102,7 +95,7 @@ func NewApp() fyne.App { test.Settings().AddChangeListener(listener) go func() { for { - _ = <-listener + <-listener painter.SvgCacheReset() app.ApplySettings(test.Settings(), test) diff --git a/test/testcanvas.go b/test/testcanvas.go index 276311ff2a..e83bc02ffb 100644 --- a/test/testcanvas.go +++ b/test/testcanvas.go @@ -224,7 +224,7 @@ func (c *testCanvas) Capture() image.Image { bounds := image.Rect(0, 0, internal.ScaleInt(c, c.Size().Width), internal.ScaleInt(c, c.Size().Height)) img := image.NewNRGBA(bounds) - draw.Draw(img, bounds, image.NewUniform(theme.BackgroundColor()), image.ZP, draw.Src) + draw.Draw(img, bounds, image.NewUniform(theme.BackgroundColor()), image.Point{}, draw.Src) return img } diff --git a/test/util_test.go b/test/util_test.go index 04aceabe1a..c87bb30a60 100644 --- a/test/util_test.go +++ b/test/util_test.go @@ -39,7 +39,7 @@ func TestAssertCanvasTappableAt(t *testing.T) { func TestAssertImageMatches(t *testing.T) { bounds := image.Rect(0, 0, 100, 50) img := image.NewNRGBA(bounds) - draw.Draw(img, bounds, image.NewUniform(color.White), image.ZP, draw.Src) + draw.Draw(img, bounds, image.NewUniform(color.White), image.Point{}, draw.Src) txtImg := image.NewNRGBA(bounds) opts := truetype.Options{Size: 20, DPI: 96} @@ -52,7 +52,7 @@ func TestAssertImageMatches(t *testing.T) { Dot: freetype.Pt(0, 50-face.Metrics().Descent.Ceil()), } d.DrawString("Hello!") - draw.Draw(img, bounds, txtImg, image.ZP, draw.Over) + draw.Draw(img, bounds, txtImg, image.Point{}, draw.Over) tt := &testing.T{} assert.False(t, test.AssertImageMatches(tt, "non_existing_master.png", img), "non existing master is not equal a given image") diff --git a/widget/entry.go b/widget/entry.go index 4057ee70c1..5054a71b69 100644 --- a/widget/entry.go +++ b/widget/entry.go @@ -143,7 +143,7 @@ func (e *Entry) DoubleTapped(_ *fyne.PointEvent) { } e.setFieldsAndRefresh(func() { - if e.selectKeyDown == false { + if !e.selectKeyDown { e.selectRow = e.CursorRow e.selectColumn = start } @@ -241,7 +241,7 @@ func (e *Entry) KeyDown(key *fyne.KeyEvent) { // Note: selection start is where the highlight started (if the user moves the selection up or left then // the selectRow/Column will not match SelectionStart) if key.Name == desktop.KeyShiftLeft || key.Name == desktop.KeyShiftRight { - if e.selecting == false { + if !e.selecting { e.selectRow = e.CursorRow e.selectColumn = e.CursorColumn } @@ -280,7 +280,7 @@ func (e *Entry) MouseDown(m *desktop.MouseEvent) { if e.selectKeyDown { e.selecting = true } - if e.selecting && e.selectKeyDown == false && m.Button == desktop.LeftMouseButton { + if e.selecting && !e.selectKeyDown && m.Button == desktop.LeftMouseButton { e.selecting = false } e.propertyLock.Unlock() @@ -297,7 +297,7 @@ func (e *Entry) MouseUp(_ *desktop.MouseEvent) { e.propertyLock.Lock() defer e.propertyLock.Unlock() - if start == -1 && e.selecting && e.selectKeyDown == false { + if start == -1 && e.selecting && !e.selectKeyDown { e.selecting = false } } @@ -791,7 +791,7 @@ func (e *Entry) selectAll() { // returns true if the keypress has been fully handled func (e *Entry) selectingKeyHandler(key *fyne.KeyEvent) bool { - if e.selectKeyDown && e.selecting == false { + if e.selectKeyDown && !e.selecting { switch key.Name { case fyne.KeyUp, fyne.KeyDown, fyne.KeyLeft, fyne.KeyRight, @@ -801,7 +801,7 @@ func (e *Entry) selectingKeyHandler(key *fyne.KeyEvent) bool { } } - if e.selecting == false { + if !e.selecting { return false } @@ -816,7 +816,7 @@ func (e *Entry) selectingKeyHandler(key *fyne.KeyEvent) bool { return false } - if e.selectKeyDown == false { + if !e.selectKeyDown { switch key.Name { case fyne.KeyLeft: // seek to the start of the selection -- return handled @@ -1006,7 +1006,7 @@ func (r *entryRenderer) MinSize() fyne.Size { minSize = r.entry.text.MinSize() } - if r.entry.MultiLine == true { + if r.entry.MultiLine { // ensure multiline height is at least charMinSize * multilineRows minSize.Height = fyne.Max(minSize.Height, r.entry.text.charMinSize().Height*multiLineRows) } diff --git a/widget/group_test.go b/widget/group_test.go index dc4177ad4e..16431c55aa 100644 --- a/widget/group_test.go +++ b/widget/group_test.go @@ -4,7 +4,6 @@ import ( "testing" "fyne.io/fyne/test" - _ "fyne.io/fyne/test" "github.com/stretchr/testify/assert" ) diff --git a/widget/progressbarinfinite.go b/widget/progressbarinfinite.go index 0470d87503..22f5e1de9c 100644 --- a/widget/progressbarinfinite.go +++ b/widget/progressbarinfinite.go @@ -130,11 +130,8 @@ func (p *infProgressRenderer) infiniteProgressLoop() { ticker := p.ticker.C p.progress.propertyLock.RUnlock() - select { - case <-ticker: - p.doRefresh() - break - } + <-ticker + p.doRefresh() } p.progress.propertyLock.RLock() diff --git a/widget/radio_extended_test.go b/widget/radio_extended_test.go index 02da84235a..b054c66502 100644 --- a/widget/radio_extended_test.go +++ b/widget/radio_extended_test.go @@ -7,7 +7,6 @@ import ( "fyne.io/fyne/driver/desktop" "fyne.io/fyne/internal/cache" "fyne.io/fyne/test" - _ "fyne.io/fyne/test" "fyne.io/fyne/theme" "github.com/stretchr/testify/assert" ) diff --git a/widget/radio_internal_test.go b/widget/radio_internal_test.go index 891fee32fe..cb464ada83 100644 --- a/widget/radio_internal_test.go +++ b/widget/radio_internal_test.go @@ -7,7 +7,6 @@ import ( "fyne.io/fyne" "fyne.io/fyne/driver/desktop" "fyne.io/fyne/test" - _ "fyne.io/fyne/test" "fyne.io/fyne/theme" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/widget/widget.go b/widget/widget.go index acb31fc91a..2f945b4331 100644 --- a/widget/widget.go +++ b/widget/widget.go @@ -170,8 +170,7 @@ func (w *BaseWidget) super() fyne.Widget { impl := w.getImpl() if impl == nil { - var x interface{} - x = w + var x interface{} = w return x.(fyne.Widget) } From a21b0a7ed0a8c2f500b3e4b20cd8b326ffa17f33 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Mon, 22 Jun 2020 15:11:31 +0200 Subject: [PATCH 2/3] Some more fixes - Removed some more unused functions. - Partly reverted progressbarinfinite chenges (might have caused a small issue) --- internal/driver/glfw/canvas_test.go | 1 - internal/driver/glfw/file.go | 13 ------------- theme/theme.go | 2 +- widget/box.go | 4 ---- widget/progressbarinfinite.go | 6 ++++-- 5 files changed, 5 insertions(+), 21 deletions(-) diff --git a/internal/driver/glfw/canvas_test.go b/internal/driver/glfw/canvas_test.go index e6cb307219..a5e6840ee0 100644 --- a/internal/driver/glfw/canvas_test.go +++ b/internal/driver/glfw/canvas_test.go @@ -429,7 +429,6 @@ func Test_glCanvas_walkTree(t *testing.T) { // test that first walk calls the hooks correctly // type beforeCall struct { - node *renderCacheNode obj fyne.CanvasObject parent fyne.CanvasObject pos fyne.Position diff --git a/internal/driver/glfw/file.go b/internal/driver/glfw/file.go index dcce3fb0ec..9c558b98e0 100644 --- a/internal/driver/glfw/file.go +++ b/internal/driver/glfw/file.go @@ -26,23 +26,10 @@ func (f *file) URI() fyne.URI { return storage.NewURI("file://" + f.path) } -type fileWriter struct { - *os.File - path string -} - func (d *gLDriver) FileWriterForURI(uri fyne.URI) (fyne.URIWriteCloser, error) { return openFile(uri, true) } -func (f *fileWriter) Name() string { - return filepath.Base(f.path) -} - -func (f *fileWriter) URI() fyne.URI { - return storage.NewURI("file://" + f.path) -} - func openFile(uri fyne.URI, create bool) (*file, error) { if uri.Scheme() != "file" { return nil, fmt.Errorf("invalid URI for file: %s", uri) diff --git a/theme/theme.go b/theme/theme.go index ebf7575f2a..1c5191b484 100644 --- a/theme/theme.go +++ b/theme/theme.go @@ -136,7 +136,7 @@ func (t *builtinTheme) TextSize() int { } func loadCustomFont(env, variant string, fallback fyne.Resource) fyne.Resource { - variantPath := strings.Replace(env, "Regular", variant, 0) + variantPath := strings.Replace(env, "Regular", variant, 0) // n == 0 gives no results. Wrong value? res, err := fyne.LoadResourceFromPath(variantPath) if err != nil { diff --git a/widget/box.go b/widget/box.go index 70fc17d766..b0c8ff18a5 100644 --- a/widget/box.go +++ b/widget/box.go @@ -62,10 +62,6 @@ func (b *Box) CreateRenderer() fyne.WidgetRenderer { return &boxRenderer{BaseRenderer: widget.NewBaseRenderer(b.Children), layout: lay, box: b} } -func (b *Box) setBackgroundColor(bg color.Color) { - b.background = bg -} - // NewHBox creates a new horizontally aligned box widget with the specified list of child objects func NewHBox(children ...fyne.CanvasObject) *Box { return &Box{BaseWidget: BaseWidget{}, Horizontal: true, Children: children} diff --git a/widget/progressbarinfinite.go b/widget/progressbarinfinite.go index 22f5e1de9c..6835d2d80b 100644 --- a/widget/progressbarinfinite.go +++ b/widget/progressbarinfinite.go @@ -130,8 +130,10 @@ func (p *infProgressRenderer) infiniteProgressLoop() { ticker := p.ticker.C p.progress.propertyLock.RUnlock() - <-ticker - p.doRefresh() + select { + case <-ticker: + p.doRefresh() + } } p.progress.propertyLock.RLock() From 103a1bdbd1a7ba670d1bdbabf33e19d66450a07b Mon Sep 17 00:00:00 2001 From: Jacalz Date: Tue, 23 Jun 2020 10:19:10 +0200 Subject: [PATCH 3/3] Use n == -1 for string replace, add in language.svg again and add small fix This fixes the strings.Replace function to use n == -1 instead of 0 which gives no results at all. Added back the language icon and do a small fix to use the correct package in the bundled code. --- cmd/fyne_settings/data/gen.go | 3 ++- cmd/fyne_settings/data/language.svg | 1 + cmd/fyne_settings/settings/bundled.go | 4 ++++ theme/theme.go | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 cmd/fyne_settings/data/language.svg diff --git a/cmd/fyne_settings/data/gen.go b/cmd/fyne_settings/data/gen.go index 49d6ddfb22..8a88c89e10 100644 --- a/cmd/fyne_settings/data/gen.go +++ b/cmd/fyne_settings/data/gen.go @@ -38,7 +38,7 @@ func openFile(filename string) *os.File { return nil } - _, err = f.WriteString("// **** THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT IT **** //\n\npackage main\n\nimport \"fyne.io/fyne\"\n\n") + _, err = f.WriteString("// **** THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT IT **** //\n\npackage settings\n\nimport \"fyne.io/fyne\"\n\n") if err != nil { fyne.LogError("Unable to write file "+filename, err) return nil @@ -57,4 +57,5 @@ func main() { bundleFile("themeLightPreview", "widgets-light.png", f) bundleFile("appearanceIcon", "appearance.svg", f) + bundleFile("languageIcon", "language.svg", f) } diff --git a/cmd/fyne_settings/data/language.svg b/cmd/fyne_settings/data/language.svg new file mode 100644 index 0000000000..2a4ff5b380 --- /dev/null +++ b/cmd/fyne_settings/data/language.svg @@ -0,0 +1 @@ + diff --git a/cmd/fyne_settings/settings/bundled.go b/cmd/fyne_settings/settings/bundled.go index e6b218a1cc..7501d8ca0c 100644 --- a/cmd/fyne_settings/settings/bundled.go +++ b/cmd/fyne_settings/settings/bundled.go @@ -16,3 +16,7 @@ var appearanceIcon = &fyne.StaticResource{ StaticName: "appearance.svg", StaticContent: []byte{ 60, 115, 118, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47, 50, 48, 48, 48, 47, 115, 118, 103, 34, 32, 119, 105, 100, 116, 104, 61, 34, 50, 52, 34, 32, 104, 101, 105, 103, 104, 116, 61, 34, 50, 52, 34, 32, 118, 105, 101, 119, 66, 111, 120, 61, 34, 48, 32, 48, 32, 50, 52, 32, 50, 52, 34, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 48, 32, 48, 104, 50, 52, 118, 50, 52, 72, 48, 122, 34, 32, 102, 105, 108, 108, 61, 34, 110, 111, 110, 101, 34, 47, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 50, 49, 32, 51, 72, 51, 99, 45, 49, 46, 49, 32, 48, 45, 50, 32, 46, 57, 45, 50, 32, 50, 118, 49, 52, 99, 48, 32, 49, 46, 49, 46, 57, 32, 50, 32, 50, 32, 50, 104, 49, 56, 99, 49, 46, 49, 32, 48, 32, 50, 45, 46, 57, 32, 50, 45, 50, 86, 53, 99, 48, 45, 49, 46, 49, 45, 46, 57, 45, 50, 45, 50, 45, 50, 122, 109, 48, 32, 49, 54, 46, 48, 49, 72, 51, 86, 52, 46, 57, 57, 104, 49, 56, 118, 49, 52, 46, 48, 50, 122, 77, 56, 32, 49, 54, 104, 50, 46, 53, 108, 49, 46, 53, 32, 49, 46, 53, 32, 49, 46, 53, 45, 49, 46, 53, 72, 49, 54, 118, 45, 50, 46, 53, 108, 49, 46, 53, 45, 49, 46, 53, 45, 49, 46, 53, 45, 49, 46, 53, 86, 56, 104, 45, 50, 46, 53, 76, 49, 50, 32, 54, 46, 53, 32, 49, 48, 46, 53, 32, 56, 72, 56, 118, 50, 46, 53, 76, 54, 46, 53, 32, 49, 50, 32, 56, 32, 49, 51, 46, 53, 86, 49, 54, 122, 109, 52, 45, 55, 99, 49, 46, 54, 54, 32, 48, 32, 51, 32, 49, 46, 51, 52, 32, 51, 32, 51, 115, 45, 49, 46, 51, 52, 32, 51, 45, 51, 32, 51, 86, 57, 122, 34, 47, 62, 60, 47, 115, 118, 103, 62}} +var languageIcon = &fyne.StaticResource{ + StaticName: "language.svg", + StaticContent: []byte{ + 60, 115, 118, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47, 50, 48, 48, 48, 47, 115, 118, 103, 34, 32, 119, 105, 100, 116, 104, 61, 34, 50, 52, 34, 32, 104, 101, 105, 103, 104, 116, 61, 34, 50, 52, 34, 32, 118, 105, 101, 119, 66, 111, 120, 61, 34, 48, 32, 48, 32, 50, 52, 32, 50, 52, 34, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 48, 32, 48, 104, 50, 52, 118, 50, 52, 72, 48, 122, 34, 32, 102, 105, 108, 108, 61, 34, 110, 111, 110, 101, 34, 47, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 49, 49, 46, 57, 57, 32, 50, 67, 54, 46, 52, 55, 32, 50, 32, 50, 32, 54, 46, 52, 56, 32, 50, 32, 49, 50, 115, 52, 46, 52, 55, 32, 49, 48, 32, 57, 46, 57, 57, 32, 49, 48, 67, 49, 55, 46, 53, 50, 32, 50, 50, 32, 50, 50, 32, 49, 55, 46, 53, 50, 32, 50, 50, 32, 49, 50, 83, 49, 55, 46, 53, 50, 32, 50, 32, 49, 49, 46, 57, 57, 32, 50, 122, 109, 54, 46, 57, 51, 32, 54, 104, 45, 50, 46, 57, 53, 99, 45, 46, 51, 50, 45, 49, 46, 50, 53, 45, 46, 55, 56, 45, 50, 46, 52, 53, 45, 49, 46, 51, 56, 45, 51, 46, 53, 54, 32, 49, 46, 56, 52, 46, 54, 51, 32, 51, 46, 51, 55, 32, 49, 46, 57, 49, 32, 52, 46, 51, 51, 32, 51, 46, 53, 54, 122, 77, 49, 50, 32, 52, 46, 48, 52, 99, 46, 56, 51, 32, 49, 46, 50, 32, 49, 46, 52, 56, 32, 50, 46, 53, 51, 32, 49, 46, 57, 49, 32, 51, 46, 57, 54, 104, 45, 51, 46, 56, 50, 99, 46, 52, 51, 45, 49, 46, 52, 51, 32, 49, 46, 48, 56, 45, 50, 46, 55, 54, 32, 49, 46, 57, 49, 45, 51, 46, 57, 54, 122, 77, 52, 46, 50, 54, 32, 49, 52, 67, 52, 46, 49, 32, 49, 51, 46, 51, 54, 32, 52, 32, 49, 50, 46, 54, 57, 32, 52, 32, 49, 50, 115, 46, 49, 45, 49, 46, 51, 54, 46, 50, 54, 45, 50, 104, 51, 46, 51, 56, 99, 45, 46, 48, 56, 46, 54, 54, 45, 46, 49, 52, 32, 49, 46, 51, 50, 45, 46, 49, 52, 32, 50, 32, 48, 32, 46, 54, 56, 46, 48, 54, 32, 49, 46, 51, 52, 46, 49, 52, 32, 50, 72, 52, 46, 50, 54, 122, 109, 46, 56, 50, 32, 50, 104, 50, 46, 57, 53, 99, 46, 51, 50, 32, 49, 46, 50, 53, 46, 55, 56, 32, 50, 46, 52, 53, 32, 49, 46, 51, 56, 32, 51, 46, 53, 54, 45, 49, 46, 56, 52, 45, 46, 54, 51, 45, 51, 46, 51, 55, 45, 49, 46, 57, 45, 52, 46, 51, 51, 45, 51, 46, 53, 54, 122, 109, 50, 46, 57, 53, 45, 56, 72, 53, 46, 48, 56, 99, 46, 57, 54, 45, 49, 46, 54, 54, 32, 50, 46, 52, 57, 45, 50, 46, 57, 51, 32, 52, 46, 51, 51, 45, 51, 46, 53, 54, 67, 56, 46, 56, 49, 32, 53, 46, 53, 53, 32, 56, 46, 51, 53, 32, 54, 46, 55, 53, 32, 56, 46, 48, 51, 32, 56, 122, 77, 49, 50, 32, 49, 57, 46, 57, 54, 99, 45, 46, 56, 51, 45, 49, 46, 50, 45, 49, 46, 52, 56, 45, 50, 46, 53, 51, 45, 49, 46, 57, 49, 45, 51, 46, 57, 54, 104, 51, 46, 56, 50, 99, 45, 46, 52, 51, 32, 49, 46, 52, 51, 45, 49, 46, 48, 56, 32, 50, 46, 55, 54, 45, 49, 46, 57, 49, 32, 51, 46, 57, 54, 122, 77, 49, 52, 46, 51, 52, 32, 49, 52, 72, 57, 46, 54, 54, 99, 45, 46, 48, 57, 45, 46, 54, 54, 45, 46, 49, 54, 45, 49, 46, 51, 50, 45, 46, 49, 54, 45, 50, 32, 48, 45, 46, 54, 56, 46, 48, 55, 45, 49, 46, 51, 53, 46, 49, 54, 45, 50, 104, 52, 46, 54, 56, 99, 46, 48, 57, 46, 54, 53, 46, 49, 54, 32, 49, 46, 51, 50, 46, 49, 54, 32, 50, 32, 48, 32, 46, 54, 56, 45, 46, 48, 55, 32, 49, 46, 51, 52, 45, 46, 49, 54, 32, 50, 122, 109, 46, 50, 53, 32, 53, 46, 53, 54, 99, 46, 54, 45, 49, 46, 49, 49, 32, 49, 46, 48, 54, 45, 50, 46, 51, 49, 32, 49, 46, 51, 56, 45, 51, 46, 53, 54, 104, 50, 46, 57, 53, 99, 45, 46, 57, 54, 32, 49, 46, 54, 53, 45, 50, 46, 52, 57, 32, 50, 46, 57, 51, 45, 52, 46, 51, 51, 32, 51, 46, 53, 54, 122, 77, 49, 54, 46, 51, 54, 32, 49, 52, 99, 46, 48, 56, 45, 46, 54, 54, 46, 49, 52, 45, 49, 46, 51, 50, 46, 49, 52, 45, 50, 32, 48, 45, 46, 54, 56, 45, 46, 48, 54, 45, 49, 46, 51, 52, 45, 46, 49, 52, 45, 50, 104, 51, 46, 51, 56, 99, 46, 49, 54, 46, 54, 52, 46, 50, 54, 32, 49, 46, 51, 49, 46, 50, 54, 32, 50, 115, 45, 46, 49, 32, 49, 46, 51, 54, 45, 46, 50, 54, 32, 50, 104, 45, 51, 46, 51, 56, 122, 34, 47, 62, 60, 47, 115, 118, 103, 62, 10}} diff --git a/theme/theme.go b/theme/theme.go index 1c5191b484..3babd8d53c 100644 --- a/theme/theme.go +++ b/theme/theme.go @@ -136,7 +136,7 @@ func (t *builtinTheme) TextSize() int { } func loadCustomFont(env, variant string, fallback fyne.Resource) fyne.Resource { - variantPath := strings.Replace(env, "Regular", variant, 0) // n == 0 gives no results. Wrong value? + variantPath := strings.Replace(env, "Regular", variant, -1) res, err := fyne.LoadResourceFromPath(variantPath) if err != nil {