diff --git a/internal/debug_disabled.go b/internal/debug_disabled.go new file mode 100644 index 0000000000..b970163114 --- /dev/null +++ b/internal/debug_disabled.go @@ -0,0 +1,8 @@ +//go:build !debug +// +build !debug + +package internal + +// BuildTypeIsDebug is true if built with -tags debug. This value exists as a constant +// so the Go compiler can deadcode eliminate reflect from non-debug builds. +const BuildTypeIsDebug = false diff --git a/internal/debug_enabled.go b/internal/debug_enabled.go new file mode 100644 index 0000000000..916413ed58 --- /dev/null +++ b/internal/debug_enabled.go @@ -0,0 +1,8 @@ +//go:build debug +// +build debug + +package internal + +// BuildTypeIsDebug is true if built with -tags debug. This value exists as a constant +// so the Go compiler can deadcode eliminate reflect from non-debug builds. +const BuildTypeIsDebug = true diff --git a/internal/driver/glfw/canvas.go b/internal/driver/glfw/canvas.go index fbd294de54..66862493b9 100644 --- a/internal/driver/glfw/canvas.go +++ b/internal/driver/glfw/canvas.go @@ -20,10 +20,10 @@ var _ fyne.Canvas = (*glCanvas)(nil) type glCanvas struct { common.Canvas - content fyne.CanvasObject - menu fyne.CanvasObject - padded, debug bool - size fyne.Size + content fyne.CanvasObject + menu fyne.CanvasObject + padded bool + size fyne.Size onTypedRune func(rune) onTypedKey func(*fyne.KeyEvent) @@ -298,7 +298,7 @@ func (c *glCanvas) paint(size fyne.Size) { } } - if c.debug { + if internal.BuildTypeIsDebug { c.DrawDebugOverlay(node.Obj(), pos, size) } } @@ -339,6 +339,5 @@ func newCanvas() *glCanvas { c := &glCanvas{scale: 1.0, texScale: 1.0, padded: true} c.Initialize(c, c.overlayChanged) c.setContent(&canvas.Rectangle{FillColor: theme.BackgroundColor()}) - c.debug = fyne.CurrentApp().Settings().BuildType() == fyne.BuildDebug return c } diff --git a/internal/driver/mobile/canvas.go b/internal/driver/mobile/canvas.go index ec2375ba3b..35c20f58bc 100644 --- a/internal/driver/mobile/canvas.go +++ b/internal/driver/mobile/canvas.go @@ -30,8 +30,8 @@ type mobileCanvas struct { scale float32 size fyne.Size - touched map[int]mobile.Touchable - padded, debug bool + touched map[int]mobile.Touchable + padded bool onTypedRune func(rune) onTypedKey func(event *fyne.KeyEvent) @@ -50,7 +50,6 @@ type mobileCanvas struct { // NewCanvas creates a new gomobile mobileCanvas. This is a mobileCanvas that will render on a mobile device using OpenGL. func NewCanvas() fyne.Canvas { ret := &mobileCanvas{padded: true} - ret.debug = fyne.CurrentApp().Settings().BuildType() == fyne.BuildDebug ret.scale = fyne.CurrentDevice().SystemScaleForWindow(nil) // we don't need a window parameter on mobile ret.touched = make(map[int]mobile.Touchable) ret.lastTapDownPos = make(map[int]fyne.Position) diff --git a/internal/driver/mobile/driver.go b/internal/driver/mobile/driver.go index 5e06cffbdc..2114838dd5 100644 --- a/internal/driver/mobile/driver.go +++ b/internal/driver/mobile/driver.go @@ -315,7 +315,7 @@ func (d *mobileDriver) paintWindow(window fyne.Window, size fyne.Size) { } } - if c.debug { + if internal.BuildTypeIsDebug { c.DrawDebugOverlay(node.Obj(), pos, size) } } diff --git a/internal/painter/gl/gl.go b/internal/painter/gl/gl.go index 65fea635db..65dad1b786 100644 --- a/internal/painter/gl/gl.go +++ b/internal/painter/gl/gl.go @@ -6,7 +6,7 @@ import ( "log" "runtime" - "fyne.io/fyne/v2" + "fyne.io/fyne/v2/internal" ) const floatSize = 4 @@ -17,7 +17,7 @@ const max16bit = float32(255 * 255) // Receives a function as parameter, to lazily get the error code only when // needed, avoiding unneeded overhead. func logGLError(getError func() uint32) { - if fyne.CurrentApp().Settings().BuildType() != fyne.BuildDebug { + if !internal.BuildTypeIsDebug { return }