Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove constant debug field from canvas #4402

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/debug_disabled.go
Original file line number Diff line number Diff line change
@@ -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
dweymouth marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions internal/debug_enabled.go
Original file line number Diff line number Diff line change
@@ -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
11 changes: 5 additions & 6 deletions internal/driver/glfw/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -298,7 +298,7 @@ func (c *glCanvas) paint(size fyne.Size) {
}
}

if c.debug {
if internal.BuildTypeIsDebug {
c.DrawDebugOverlay(node.Obj(), pos, size)
}
}
Expand Down Expand Up @@ -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
}
5 changes: 2 additions & 3 deletions internal/driver/mobile/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/mobile/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/painter/gl/gl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"runtime"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal"
)

const floatSize = 4
Expand All @@ -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
}

Expand Down
Loading