153 lines
3.4 KiB
Go
153 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"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/layout"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
// RunGUI initializes the Main Window UI where users can configure an error message visually.
|
|
func RunGUI() {
|
|
a := app.New()
|
|
w := a.NewWindow("Error Message Generator")
|
|
MainWindow = w
|
|
|
|
w.SetIcon(icons[DefaultIcon])
|
|
w.SetOnClosed(func() {
|
|
a.Quit()
|
|
})
|
|
w.CenterOnScreen()
|
|
|
|
// Create a Dialog template that the UI components will modify.
|
|
var d = Dialog{
|
|
Icon: icons[DefaultIcon],
|
|
Buttons: []*Button{},
|
|
}
|
|
|
|
// Preview of the selected icon.
|
|
currentIcon := canvas.NewImageFromResource(d.Icon)
|
|
currentIcon.FillMode = canvas.ImageFillOriginal
|
|
currentIcon.SetMinSize(fyne.NewSize(32, 32))
|
|
|
|
// The icon picker row.
|
|
labelIcon := canvas.NewText("Icon:", color.Black)
|
|
selectIcon := widget.NewSelect(iconNames, func(v string) {
|
|
d.Icon = icons[v]
|
|
currentIcon.Resource = d.Icon
|
|
currentIcon.Refresh()
|
|
})
|
|
selectIcon.SetSelected(DefaultIcon)
|
|
iconRow := container.New(layout.NewHBoxLayout(), currentIcon, selectIcon)
|
|
|
|
labelTitle := canvas.NewText("Title:", color.Black)
|
|
entryTitle := widget.NewEntry()
|
|
entryTitle.SetPlaceHolder("Error message title")
|
|
entryTitle.OnChanged = func(v string) {
|
|
d.Title = v
|
|
}
|
|
|
|
labelMessage := canvas.NewText("Message:", color.Black)
|
|
entryMessage := widget.NewEntry()
|
|
entryMessage.MultiLine = true
|
|
entryMessage.SetPlaceHolder("Message contents")
|
|
entryMessage.OnChanged = func(v string) {
|
|
d.Message = v
|
|
}
|
|
|
|
// The three buttons.
|
|
var buttons = []fyne.CanvasObject{}
|
|
for i := 0; i < 3; i++ {
|
|
// Our dialog button.
|
|
b := &Button{}
|
|
d.Buttons = append(d.Buttons, b)
|
|
|
|
labelButton := canvas.NewText(fmt.Sprintf("Button %d", i+1), color.Black)
|
|
entryButton := widget.NewEntry()
|
|
entryButton.OnChanged = func(v string) {
|
|
b.Label = v
|
|
}
|
|
entryButton.SetPlaceHolder("Button")
|
|
|
|
checkDisabled := widget.NewCheck("Disabled", func(v bool) {
|
|
b.Disabled = v
|
|
})
|
|
|
|
buttonColumn := container.New(
|
|
layout.NewVBoxLayout(),
|
|
labelButton,
|
|
entryButton,
|
|
checkDisabled,
|
|
)
|
|
buttons = append(buttons, buttonColumn)
|
|
|
|
if i < 2 {
|
|
buttons = append(buttons, layout.NewSpacer())
|
|
}
|
|
}
|
|
buttonRow := container.New(layout.NewHBoxLayout(), buttons...)
|
|
|
|
// The "Go!" buttons.
|
|
buttonGo := widget.NewButton(" Go! ", func() {
|
|
d.Show(nil)
|
|
})
|
|
buttonGo.Importance = widget.HighImportance
|
|
buttonHideAndGo := widget.NewButton(" Hide & Go! ", func() {
|
|
w.Hide()
|
|
d.Show(nil)
|
|
})
|
|
buttonAbout := widget.NewButton(" About ", func() {
|
|
Dialog{
|
|
Title: "About ErrorGen",
|
|
Icon: icons["radiation"],
|
|
Message: fmt.Sprintf(`Error Message Generator v%s
|
|
|
|
Created by Noah Petherbridge in 2023, inspired by and including
|
|
classic icons from the Atom Smasher Error Message Generator website.`, Version),
|
|
Buttons: []*Button{
|
|
{
|
|
Label: " Ok ",
|
|
},
|
|
{
|
|
Label: " Website ",
|
|
OpenURL: Website,
|
|
},
|
|
},
|
|
}.Show(nil)
|
|
})
|
|
buttonAbout.Importance = widget.DangerImportance
|
|
goRow := container.New(
|
|
layout.NewHBoxLayout(),
|
|
layout.NewSpacer(),
|
|
buttonGo,
|
|
layout.NewSpacer(),
|
|
buttonHideAndGo,
|
|
layout.NewSpacer(),
|
|
buttonAbout,
|
|
layout.NewSpacer(),
|
|
)
|
|
|
|
vbox := container.New(
|
|
layout.NewVBoxLayout(),
|
|
labelIcon,
|
|
iconRow,
|
|
labelTitle,
|
|
entryTitle,
|
|
labelMessage,
|
|
entryMessage,
|
|
buttonRow,
|
|
goRow,
|
|
)
|
|
|
|
w.SetContent(vbox)
|
|
|
|
// If we were sent to show a dialog via CLI, hide the main window.
|
|
w.ShowAndRun()
|
|
|
|
}
|