I wish a modal that pops up ,that will not let users interact with the app until questions on the modal are answered. Usually the back ground is greyed out as what I am used to in C# forms.
I wrote the following code experimenting with ShowModalPopUp and ShowPopUp, where both produce pop up windows. But widget.ShowModalPopUp produces a normal pop up, not a modal one, that holds focus and greys the background. Google search = "modal popup form" to see what I am expecting.
package main
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Pop up demo")
w.Resize(fyne.NewSize(600, 600))
//-------------------------------
//func ShowModalPopUp(content fyne.CanvasObject, canvas fyne.Canvas)
//func ShowPopUp(content fyne.CanvasObject, canvas fyne.Canvas)
//https://developer.fyne.io/api/v2.4/widget/
hello := widget.NewLabel("Demo Fyne show popup vs show modal popup")
w.SetContent(container.NewVBox(
hello,
widget.NewButton("pop demo!", func() {
hello.SetText("Show me a popup")
myWindowPop := a.NewWindow("CanvasPop")
myCanvasPop := myWindowPop.Canvas()
red := color.NRGBA{R: 180, G: 0, B: 0, A: 255}
rectPop := canvas.NewRectangle(&red)
rectPop.SetMinSize(fyne.NewSize(200, 200))
myCanvasPop.SetContent(rectPop)
widget.ShowPopUp(rectPop, myCanvasPop) // show popup
myWindowPop.Resize(fyne.NewSize(300, 300))
myWindowPop.Show()
}),
widget.NewButton("Modal demo", func() {
hello.SetText("show me a ModalPopup")
myWindow := a.NewWindow("CanvasModal")
myCanvas := myWindow.Canvas()
blue := color.NRGBA{R: 0, G: 0, B: 180, A: 255}
rect := canvas.NewRectangle(&blue)
rect.SetMinSize(fyne.NewSize(200, 200))
myCanvas.SetContent(rect)
widget.ShowModalPopUp(rect, myCanvas) // show modal popup
myWindow.Resize(fyne.NewSize(300, 300))
myWindow.Show()
}),
))
w.ShowAndRun()
}
Modal popups should work as you describe. You may be interested in the dialog package which provides standard modal dialogs. Either way if the modal show didn’t work then dialogs wouldn’t work?
I suspect the issue is that you’re creating new windows for the modals. But to be a modal it must be on the same window as the content you want it to cover.