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 all commits
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: 0 additions & 8 deletions app/app_debug.go

This file was deleted.

8 changes: 0 additions & 8 deletions app/app_release.go

This file was deleted.

8 changes: 0 additions & 8 deletions app/app_standard.go

This file was deleted.

3 changes: 2 additions & 1 deletion app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

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

Expand Down Expand Up @@ -44,7 +45,7 @@ type settings struct {
}

func (s *settings) BuildType() fyne.BuildType {
return buildMode
return build.Mode
}

func (s *settings) PrimaryColor() string {
Expand Down
3 changes: 2 additions & 1 deletion app/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fyne.io/fyne/v2"
"github.com/stretchr/testify/assert"

"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/test"
"fyne.io/fyne/v2/theme"
)
Expand All @@ -17,7 +18,7 @@ func TestSettingsBuildType(t *testing.T) {
assert.Equal(t, fyne.BuildStandard, set.BuildType()) // during test we should have a normal build

set = &settings{}
assert.Equal(t, buildMode, set.BuildType()) // when testing this package only it could be debug or release
assert.Equal(t, build.Mode, set.BuildType()) // when testing this package only it could be debug or release
}

func TestSettingsLoad(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package build contains information about they type of build currently running.
package build
7 changes: 7 additions & 0 deletions internal/build/driver_notwayland.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !wayland
// +build !wayland

package build

// IsWayland is true when compiling for the wayland windowing system.
const IsWayland = false
7 changes: 7 additions & 0 deletions internal/build/driver_wayland.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build wayland
// +build wayland

package build

// IsWayland is true when compiling for the wayland windowing system.
const IsWayland = true
9 changes: 9 additions & 0 deletions internal/build/mode_debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build debug
// +build debug

package build

import "fyne.io/fyne/v2"

// Mode is the application's build mode.
const Mode = fyne.BuildDebug
9 changes: 9 additions & 0 deletions internal/build/mode_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build release
// +build release

package build

import "fyne.io/fyne/v2"

// Mode is the application's build mode.
const Mode = fyne.BuildRelease
9 changes: 9 additions & 0 deletions internal/build/mode_standard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !debug && !release
// +build !debug,!release

package build

import "fyne.io/fyne/v2"

// Mode is the application's build mode.
const Mode = fyne.BuildStandard
12 changes: 6 additions & 6 deletions internal/driver/glfw/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/internal"
"fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/internal/driver"
"fyne.io/fyne/v2/internal/driver/common"
"fyne.io/fyne/v2/theme"
Expand All @@ -20,10 +21,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 +299,7 @@ func (c *glCanvas) paint(size fyne.Size) {
}
}

if c.debug {
if build.Mode == fyne.BuildDebug {
c.DrawDebugOverlay(node.Obj(), pos, size)
}
}
Expand Down Expand Up @@ -339,6 +340,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
}
6 changes: 0 additions & 6 deletions internal/driver/glfw/driver_notwayland.go

This file was deleted.

6 changes: 0 additions & 6 deletions internal/driver/glfw/driver_wayland.go

This file was deleted.

9 changes: 5 additions & 4 deletions internal/driver/glfw/window_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/internal/driver/common"
"fyne.io/fyne/v2/internal/painter"
"fyne.io/fyne/v2/internal/painter/gl"
Expand Down Expand Up @@ -184,7 +185,7 @@ func (w *window) doCenterOnScreen() {
}

func (w *window) RequestFocus() {
if isWayland || w.view() == nil {
if build.IsWayland || w.view() == nil {
return
}

Expand Down Expand Up @@ -296,7 +297,7 @@ func (w *window) getMonitorForWindow() *glfw.Monitor {
}

func (w *window) detectScale() float32 {
if isWayland { // Wayland controls scale through content scaling
if build.IsWayland { // Wayland controls scale through content scaling
return 1.0
}
monitor := w.getMonitorForWindow()
Expand All @@ -319,7 +320,7 @@ func (w *window) resized(_ *glfw.Window, width, height int) {
}

func (w *window) scaled(_ *glfw.Window, x float32, y float32) {
if !isWayland { // other platforms handle this using older APIs
if !build.IsWayland { // other platforms handle this using older APIs
return
}

Expand Down Expand Up @@ -707,7 +708,7 @@ func (w *window) rescaleOnMain() {

func (w *window) create() {
runOnMain(func() {
if !isWayland {
if !build.IsWayland {
// make the window hidden, we will set it up and then show it later
glfw.WindowHint(glfw.Visible, glfw.False)
}
Expand Down
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
3 changes: 2 additions & 1 deletion internal/driver/mobile/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fyne.io/fyne/v2/internal"
"fyne.io/fyne/v2/internal/animation"
intapp "fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/internal/cache"
"fyne.io/fyne/v2/internal/driver"
"fyne.io/fyne/v2/internal/driver/common"
Expand Down Expand Up @@ -315,7 +316,7 @@ func (d *mobileDriver) paintWindow(window fyne.Window, size fyne.Size) {
}
}

if c.debug {
if build.Mode == fyne.BuildDebug {
c.DrawDebugOverlay(node.Obj(), pos, size)
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/painter/gl/gl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"

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

const floatSize = 4
Expand All @@ -17,7 +18,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 build.Mode != fyne.BuildDebug {
return
}

Expand Down
Loading