testwindow.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package test
  2. import (
  3. "fyne.io/fyne/v2"
  4. )
  5. type testWindow struct {
  6. title string
  7. fullScreen bool
  8. fixedSize bool
  9. focused bool
  10. onClosed func()
  11. onCloseIntercepted func()
  12. canvas *testCanvas
  13. clipboard fyne.Clipboard
  14. driver *testDriver
  15. menu *fyne.MainMenu
  16. }
  17. // NewWindow creates and registers a new window for test purposes
  18. func NewWindow(content fyne.CanvasObject) fyne.Window {
  19. window := fyne.CurrentApp().NewWindow("")
  20. window.SetContent(content)
  21. return window
  22. }
  23. func (w *testWindow) Canvas() fyne.Canvas {
  24. return w.canvas
  25. }
  26. func (w *testWindow) CenterOnScreen() {
  27. // no-op
  28. }
  29. func (w *testWindow) Clipboard() fyne.Clipboard {
  30. return w.clipboard
  31. }
  32. func (w *testWindow) Close() {
  33. if w.onClosed != nil {
  34. w.onClosed()
  35. }
  36. w.focused = false
  37. w.driver.removeWindow(w)
  38. }
  39. func (w *testWindow) Content() fyne.CanvasObject {
  40. return w.Canvas().Content()
  41. }
  42. func (w *testWindow) FixedSize() bool {
  43. return w.fixedSize
  44. }
  45. func (w *testWindow) FullScreen() bool {
  46. return w.fullScreen
  47. }
  48. func (w *testWindow) Hide() {
  49. w.focused = false
  50. }
  51. func (w *testWindow) Icon() fyne.Resource {
  52. return fyne.CurrentApp().Icon()
  53. }
  54. func (w *testWindow) MainMenu() *fyne.MainMenu {
  55. return w.menu
  56. }
  57. func (w *testWindow) Padded() bool {
  58. return w.canvas.Padded()
  59. }
  60. func (w *testWindow) RequestFocus() {
  61. for _, win := range w.driver.AllWindows() {
  62. win.(*testWindow).focused = false
  63. }
  64. w.focused = true
  65. }
  66. func (w *testWindow) Resize(size fyne.Size) {
  67. w.canvas.Resize(size)
  68. }
  69. func (w *testWindow) SetContent(obj fyne.CanvasObject) {
  70. w.Canvas().SetContent(obj)
  71. }
  72. func (w *testWindow) SetFixedSize(fixed bool) {
  73. w.fixedSize = fixed
  74. }
  75. func (w *testWindow) SetIcon(_ fyne.Resource) {
  76. // no-op
  77. }
  78. func (w *testWindow) SetFullScreen(fullScreen bool) {
  79. w.fullScreen = fullScreen
  80. }
  81. func (w *testWindow) SetMainMenu(menu *fyne.MainMenu) {
  82. w.menu = menu
  83. }
  84. func (w *testWindow) SetMaster() {
  85. // no-op
  86. }
  87. func (w *testWindow) SetOnClosed(closed func()) {
  88. w.onClosed = closed
  89. }
  90. func (w *testWindow) SetCloseIntercept(callback func()) {
  91. w.onCloseIntercepted = callback
  92. }
  93. func (w *testWindow) SetOnDropped(dropped func(fyne.Position, []fyne.URI)) {
  94. }
  95. func (w *testWindow) SetPadded(padded bool) {
  96. w.canvas.SetPadded(padded)
  97. }
  98. func (w *testWindow) SetTitle(title string) {
  99. w.title = title
  100. }
  101. func (w *testWindow) Show() {
  102. w.RequestFocus()
  103. }
  104. func (w *testWindow) ShowAndRun() {
  105. w.Show()
  106. }
  107. func (w *testWindow) Title() string {
  108. return w.title
  109. }