Skip to content

Commit

Permalink
Merge pull request #1150 from andydotxyz/fix/1114
Browse files Browse the repository at this point in the history
Fix resize flicker, at last :)
  • Loading branch information
andydotxyz committed Jun 30, 2020
2 parents fce4b1f + f7e1114 commit 102ff9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 7 additions & 0 deletions canvas/raster.go
Expand Up @@ -28,6 +28,13 @@ func (r *Raster) Alpha() float64 {
return 1.0 - r.Translucency
}

// Resize on a raster image causes the new size to be set and then calls Refresh.
// This causes the underlying data to be recalculated and a new output to be drawn.
func (r *Raster) Resize(s fyne.Size) {
r.baseObject.Resize(s)
Refresh(r)
}

// Refresh causes this object to be redrawn in it's current state
func (r *Raster) Refresh() {
Refresh(r)
Expand Down
22 changes: 16 additions & 6 deletions internal/driver/glfw/window.go
Expand Up @@ -501,7 +501,17 @@ func (w *window) resized(_ *glfw.Window, width, height int) {
w.width = internal.ScaleInt(w.canvas, canvasSize.Width)
w.height = internal.ScaleInt(w.canvas, canvasSize.Height)
}
w.canvas.Resize(canvasSize)

d, ok := fyne.CurrentApp().Driver().(*gLDriver)
if !ok || !w.visible { // don't wait to redraw in this way if we are running on test or not yet drawn
w.canvas.Resize(canvasSize)
return
}

runOnDraw(w, func() {
w.canvas.Resize(canvasSize)
d.repaintWindow(w)
})
}

func (w *window) frameSized(viewport *glfw.Window, width, height int) {
Expand All @@ -514,7 +524,7 @@ func (w *window) frameSized(viewport *glfw.Window, width, height int) {
w.canvas.Refresh(w.canvas.Content()) // apply texture scale
}

func (w *window) refresh(viewport *glfw.Window) {
func (w *window) refresh(_ *glfw.Window) {
refreshWindow(w)
}

Expand Down Expand Up @@ -867,7 +877,7 @@ func keyToName(code glfw.Key, scancode int) fyne.KeyName {
return ret
}

func (w *window) keyPressed(viewport *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
func (w *window) keyPressed(_ *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
keyName := keyToName(key, scancode)
if keyName == "" {
return
Expand Down Expand Up @@ -997,7 +1007,7 @@ func desktopModifier(mods glfw.ModifierKey) desktop.Modifier {
// Unicode character is input.
//
// Characters do not map 1:1 to physical keys, as a key may produce zero, one or more characters.
func (w *window) charInput(viewport *glfw.Window, char rune) {
func (w *window) charInput(_ *glfw.Window, char rune) {
if w.canvas.Focused() == nil && w.canvas.onTypedRune == nil {
return
}
Expand All @@ -1010,7 +1020,7 @@ func (w *window) charInput(viewport *glfw.Window, char rune) {
}
}

func (w *window) focused(viewport *glfw.Window, focused bool) {
func (w *window) focused(_ *glfw.Window, focused bool) {
if w.canvas.focused == nil {
return
}
Expand Down Expand Up @@ -1051,7 +1061,7 @@ func (w *window) rescaleOnMain() {
return
}

size := w.canvas.size.Union(w.canvas.MinSize())
size := w.canvas.size.Max(w.canvas.MinSize())
newWidth, newHeight := w.screenSize(size)
w.viewport.SetSize(newWidth, newHeight)
}
Expand Down

0 comments on commit 102ff9e

Please sign in to comment.