Skip to content

Commit

Permalink
fix file dialog resize method, ensure popup overlays are refreshed wh…
Browse files Browse the repository at this point in the history
…en windows is created and resized, fixes fyne-io#1692 when fyne-io#1931 is landed
  • Loading branch information
fpabl0 committed Feb 9, 2021
1 parent 6193bd8 commit a7abe93
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
30 changes: 16 additions & 14 deletions dialog/file.go
Expand Up @@ -476,21 +476,23 @@ func (f *FileDialog) Resize(size fyne.Size) {
if f.dialog == nil {
return
}
maxSize := f.dialog.win.Size()
minSize := f.dialog.win.MinSize()
newWidth := size.Width
if size.Width > maxSize.Width {
newWidth = maxSize.Width
} else if size.Width < minSize.Width {
newWidth = minSize.Width
}
newHeight := size.Height
if size.Height > maxSize.Height {
newHeight = maxSize.Height
} else if size.Height < minSize.Height {
newHeight = minSize.Height
}
f.dialog.win.Resize(fyne.NewSize(newWidth, newHeight))
f.dialog.win.Resize(minSize.Max(size))
// maxSize := f.dialog.win.Size()
// minSize := f.dialog.win.MinSize()
// newWidth := size.Width
// if size.Width > maxSize.Width {
// newWidth = maxSize.Width
// } else if size.Width < minSize.Width {
// newWidth = minSize.Width
// }
// newHeight := size.Height
// if size.Height > maxSize.Height {
// newHeight = maxSize.Height
// } else if size.Height < minSize.Height {
// newHeight = minSize.Height
// }
// f.dialog.win.Resize(fyne.NewSize(newWidth, newHeight))
}

// Hide hides the file dialog.
Expand Down
3 changes: 2 additions & 1 deletion internal/driver/glfw/canvas.go
Expand Up @@ -178,7 +178,8 @@ func (c *glCanvas) Resize(size fyne.Size) {
if p, ok := overlay.(*widget.PopUp); ok {
// TODO: remove this when #707 is being addressed.
// “Notifies” the PopUp of the canvas size change.
p.Resize(p.Content.Size().Add(fyne.NewSize(theme.Padding()*2, theme.Padding()*2)))
// fmt.Printf("%#v ,canvas resize: %v\n", p, p.Content.Size())
p.Refresh()
} else {
overlay.Resize(size)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/driver/glfw/window.go
Expand Up @@ -402,6 +402,14 @@ func (w *window) doShow() {
if w.canvas.Content() != nil {
w.canvas.Content().Show()
}

// Refresh popup overlays
for _, overlay := range w.canvas.Overlays().List() {
if _, ok := overlay.(*widget.PopUp); !ok {
continue
}
overlay.Refresh()
}
}

func (w *window) Hide() {
Expand Down
4 changes: 3 additions & 1 deletion widget/popup.go
Expand Up @@ -47,8 +47,10 @@ func (p *PopUp) Move(pos fyne.Position) {
//
// Implements: fyne.Widget
func (p *PopUp) Resize(size fyne.Size) {
canvasSize := p.Canvas.Size()
p.innerSize = size
p.BaseWidget.Resize(p.Canvas.Size())
p.Content.Resize(p.innerSize.Subtract(fyne.NewSize(theme.Padding()*2, theme.Padding()*2)))
p.BaseWidget.Resize(canvasSize)
// The canvas size might not have changed and therefore the Resize won't trigger a layout.
// Until we have a widget.Relayout() or similar, the renderer's refresh will do the re-layout.
p.Refresh()
Expand Down

0 comments on commit a7abe93

Please sign in to comment.