Skip to content

Commit

Permalink
Merge pull request #5335 from dweymouth/fix-5323
Browse files Browse the repository at this point in the history
Ensure text and SVG textures re-rasterize when window is dragged to new monitor
  • Loading branch information
dweymouth authored Dec 23, 2024
2 parents eb40d8e + 91a524f commit 03a3827
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
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 @@ -14,6 +14,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 @@ -699,6 +700,10 @@ func (w *window) RescaleContext() {
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
10 changes: 4 additions & 6 deletions 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 @@ -468,18 +469,15 @@ func (w *window) RescaleContext() {
return
}

// if w.fullScreen {
w.width, w.height = w.viewport.GetSize()
scaledFull := fyne.NewSize(
scale.ToFyneCoordinate(w.canvas, w.width),
scale.ToFyneCoordinate(w.canvas, w.height))
w.canvas.Resize(scaledFull)
return
// }

// size := w.canvas.size.Union(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

0 comments on commit 03a3827

Please sign in to comment.