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

Ensure text and SVG textures re-rasterize when window is dragged to new monitor #5335

Merged
merged 2 commits into from
Dec 23, 2024
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
14 changes: 14 additions & 0 deletions internal/cache/texture_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func RangeTexturesFor(canvas fyne.Canvas, f func(fyne.CanvasObject)) {
})
}

// DeleteTextTexturesFor deletes all text textures for the given canvas.
func DeleteTextTexturesFor(canvas fyne.Canvas) {
textures.Range(func(key, value any) bool {
if _, ok := key.(FontCacheEntry); ok {
tinfo := value.(*textureInfo)
if tinfo.canvas == canvas {
textures.Delete(key)
tinfo.textFree()
}
}
return true
})
}

// SetTextTexture sets cached texture for a text run.
func SetTextTexture(ent FontCacheEntry, texture TextureType, canvas fyne.Canvas, free func()) {
store(ent, texture, canvas, free)
Expand Down
5 changes: 5 additions & 0 deletions internal/driver/glfw/window_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/internal/cache"
"fyne.io/fyne/v2/internal/painter"
"fyne.io/fyne/v2/internal/painter/gl"
"fyne.io/fyne/v2/internal/scale"
Expand Down Expand Up @@ -703,6 +704,10 @@ func (w *window) rescaleOnMain() {
size := w.canvas.size.Max(w.canvas.MinSize())
newWidth, newHeight := w.screenSize(size)
w.viewport.SetSize(newWidth, newHeight)

// Ensure textures re-rasterize at the new scale
cache.DeleteTextTexturesFor(w.canvas)
w.canvas.content.Refresh()
}

func (w *window) create() {
Expand Down
7 changes: 6 additions & 1 deletion internal/driver/glfw/window_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/internal/cache"
"fyne.io/fyne/v2/internal/painter/gl"
"fyne.io/fyne/v2/internal/scale"

Expand Down Expand Up @@ -474,7 +475,11 @@ func (w *window) rescaleOnMain() {
scale.ToFyneCoordinate(w.canvas, w.width),
scale.ToFyneCoordinate(w.canvas, w.height))
w.canvas.Resize(scaledFull)
return

// Ensure textures re-rasterize at the new scale
cache.DeleteTextTexturesFor(w.canvas)
w.canvas.content.Refresh()
//return
Jacalz marked this conversation as resolved.
Show resolved Hide resolved
// }

// size := w.canvas.size.Union(w.canvas.MinSize())
Expand Down
Loading