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 Popups are resized in newly created window and when window is resized, fixes #1692 #1932

Merged
merged 9 commits into from Feb 26, 2021
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()
fpabl0 marked this conversation as resolved.
Show resolved Hide resolved
// 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