2021-08-26 04:18:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/canvas"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/dialog"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
|
|
|
)
|
|
|
|
|
|
|
|
func guiErr(err error, msg string, parent fyne.Window) {
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new label containing message
|
2021-08-26 04:18:24 +00:00
|
|
|
msgLbl := widget.NewLabel(msg)
|
2021-08-26 15:47:17 +00:00
|
|
|
// Text formatting settings
|
2021-08-26 04:18:24 +00:00
|
|
|
msgLbl.Wrapping = fyne.TextWrapWord
|
|
|
|
msgLbl.Alignment = fyne.TextAlignCenter
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new rectangle to set the size of the dialog
|
2021-08-26 04:18:24 +00:00
|
|
|
rect := canvas.NewRectangle(color.Transparent)
|
2021-08-26 15:47:17 +00:00
|
|
|
// Set minimum size of rectangle to 350x0
|
2021-08-26 04:18:24 +00:00
|
|
|
rect.SetMinSize(fyne.NewSize(350, 0))
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new container containing message and rectangle
|
2021-08-26 04:18:24 +00:00
|
|
|
content := container.NewVBox(
|
|
|
|
msgLbl,
|
|
|
|
rect,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new label containing error text
|
2021-08-26 04:18:24 +00:00
|
|
|
errLbl := widget.NewLabel(err.Error())
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create new dropdown containing error label
|
2021-08-26 04:18:24 +00:00
|
|
|
content.Add(widget.NewAccordion(
|
|
|
|
widget.NewAccordionItem("More Details", errLbl),
|
|
|
|
))
|
|
|
|
}
|
2021-08-26 15:47:17 +00:00
|
|
|
// Show error dialog
|
2021-08-26 04:18:24 +00:00
|
|
|
dialog.NewCustom("Error", "Ok", content, parent).Show()
|
|
|
|
}
|