fyne

fyne: setting dialog width larger than minsize


I am new to Go; newer to Fyne. I want to create a modal dialog box that prompts the user for a URL and has an OK and a Cancel button. I'm finding that when I do this, the dialog is set to the minimum width for the layout in the dialog, resulting in a text entry box that is so narrow its contents cannot be seen onscreen. How do I fix this?

In the parent I want to do something like:

url, ok := GetURLModal(defaultURL, thisWindow)
if ok {
  //do something with the url
}

The function I've written is probably not ideal but appears to work:

func GetURLModal(defaultURL string, parentWindow fyne.Window) (string, bool) {
    bOK := false
    url := ""

    urlLabel := widget.NewLabel("Enter the URL:")
    urlEntry := widget.NewEntry()
    urlEntry.SetText(defaultURL)
    dlgContent := container.New(layout.NewFormLayout(), urlLabel, urlEntry)
    

    dialog.ShowCustomConfirm("URL Entry", "OK", "Cancel", dlgContent, func(b bool) {
        bOK = b
        url = urlEntry.Text
    }, parentWindow)

    return url, bOK
}

How can I en-widen my dialog so I can see the URL in the entry box?


Solution

  • There is a Resize method on Dialog (just like on Window). So use NewCustomConfirm to get the instance, then you can resize and show it.