window.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package screens
  2. import (
  3. "errors"
  4. "fmt"
  5. "time"
  6. "fyne.io/fyne"
  7. "fyne.io/fyne/dialog"
  8. "fyne.io/fyne/layout"
  9. "fyne.io/fyne/widget"
  10. )
  11. func confirmCallback(response bool) {
  12. fmt.Println("Responded with", response)
  13. }
  14. // DialogScreen loads a panel that lists the dialog windows that can be tested.
  15. func DialogScreen(win fyne.Window) fyne.CanvasObject {
  16. dialogs := widget.NewGroup("Dialogs",
  17. widget.NewButton("Info", func() {
  18. dialog.ShowInformation("Information", "You should know this thing...", win)
  19. }),
  20. widget.NewButton("Error", func() {
  21. err := errors.New("A dummy error message")
  22. dialog.ShowError(err, win)
  23. }),
  24. widget.NewButton("Confirm", func() {
  25. cnf := dialog.NewConfirm("Confirmation", "Are you enjoying this demo?", confirmCallback, win)
  26. cnf.SetDismissText("Nah")
  27. cnf.SetConfirmText("Oh Yes!")
  28. cnf.Show()
  29. }),
  30. widget.NewButton("Progress", func() {
  31. prog := dialog.NewProgress("MyProgress", "Nearly there...", win)
  32. go func() {
  33. num := 0.0
  34. for num < 1.0 {
  35. time.Sleep(50 * time.Millisecond)
  36. prog.SetValue(num)
  37. num += 0.01
  38. }
  39. prog.SetValue(1)
  40. prog.Hide()
  41. }()
  42. prog.Show()
  43. }),
  44. widget.NewButton("Custom", func() {
  45. content := widget.NewEntry()
  46. content.SetPlaceHolder("Type something here")
  47. content.OnChanged = func(text string) {
  48. fmt.Println("Entered", text)
  49. }
  50. dialog.ShowCustom("Custom dialog", "Done", content, win)
  51. }),
  52. )
  53. windows := widget.NewVBox(dialogs, widget.NewGroup("Windows",
  54. widget.NewButton("New window", func() {
  55. w := fyne.CurrentApp().NewWindow("Hello")
  56. w.SetContent(widget.NewLabel("Hello World!"))
  57. w.Show()
  58. }),
  59. widget.NewButton("Fixed size window", func() {
  60. w := fyne.CurrentApp().NewWindow("Fixed")
  61. w.SetContent(fyne.NewContainerWithLayout(layout.NewCenterLayout(), widget.NewLabel("Hello World!")))
  62. w.Resize(fyne.NewSize(240, 180))
  63. w.SetFixedSize(true)
  64. w.Show()
  65. }),
  66. widget.NewButton("Centered window", func() {
  67. w := fyne.CurrentApp().NewWindow("Central")
  68. w.SetContent(fyne.NewContainerWithLayout(layout.NewCenterLayout(), widget.NewLabel("Hello World!")))
  69. w.CenterOnScreen()
  70. w.Show()
  71. })))
  72. return fyne.NewContainerWithLayout(layout.NewAdaptiveGridLayout(2), windows, LayoutPanel())
  73. }