canvasobject.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package fyne
  2. // CanvasObject describes any graphical object that can be added to a canvas.
  3. // Objects have a size and position that can be controlled through this API.
  4. // MinSize is used to determine the minimum size which this object should be displayed.
  5. // An object will be visible by default but can be hidden with Hide() and re-shown with Show().
  6. //
  7. // Note: If this object is controlled as part of a Layout you should not call
  8. // Resize(Size) or Move(Position).
  9. type CanvasObject interface {
  10. // geometry
  11. // MinSize returns the minimum size this object needs to be drawn.
  12. MinSize() Size
  13. // Move moves this object to the given position relative to its parent.
  14. // This should only be called if your object is not in a container with a layout manager.
  15. Move(Position)
  16. // Position returns the current position of the object relative to its parent.
  17. Position() Position
  18. // Resize resizes this object to the given size.
  19. // This should only be called if your object is not in a container with a layout manager.
  20. Resize(Size)
  21. // Size returns the current size of this object.
  22. Size() Size
  23. // visibility
  24. // Hide hides this object.
  25. Hide()
  26. // Visible returns whether this object is visible or not.
  27. Visible() bool
  28. // Show shows this object.
  29. Show()
  30. // Refresh must be called if this object should be redrawn because its inner state changed.
  31. Refresh()
  32. }
  33. // Disableable describes any CanvasObject that can be disabled.
  34. // This is primarily used with objects that also implement the Tappable interface.
  35. type Disableable interface {
  36. Enable()
  37. Disable()
  38. Disabled() bool
  39. }
  40. // DoubleTappable describes any CanvasObject that can also be double tapped.
  41. type DoubleTappable interface {
  42. DoubleTapped(*PointEvent)
  43. }
  44. // Draggable indicates that a CanvasObject can be dragged.
  45. // This is used for any item that the user has indicated should be moved across the screen.
  46. type Draggable interface {
  47. Dragged(*DragEvent)
  48. DragEnd()
  49. }
  50. // Focusable describes any CanvasObject that can respond to being focused.
  51. // It will receive the FocusGained and FocusLost events appropriately.
  52. // When focused it will also have TypedRune called as text is input and
  53. // TypedKey called when other keys are pressed.
  54. //
  55. // Note: You must not change canvas state (including overlays or focus) in FocusGained or FocusLost
  56. // or you would end up with a dead-lock.
  57. type Focusable interface {
  58. // FocusGained is a hook called by the focus handling logic after this object gained the focus.
  59. FocusGained()
  60. // FocusLost is a hook called by the focus handling logic after this object lost the focus.
  61. FocusLost()
  62. // TypedRune is a hook called by the input handling logic on text input events if this object is focused.
  63. TypedRune(rune)
  64. // TypedKey is a hook called by the input handling logic on key events if this object is focused.
  65. TypedKey(*KeyEvent)
  66. }
  67. // Scrollable describes any CanvasObject that can also be scrolled.
  68. // This is mostly used to implement the widget.ScrollContainer.
  69. type Scrollable interface {
  70. Scrolled(*ScrollEvent)
  71. }
  72. // SecondaryTappable describes a CanvasObject that can be right-clicked or long-tapped.
  73. type SecondaryTappable interface {
  74. TappedSecondary(*PointEvent)
  75. }
  76. // Shortcutable describes any CanvasObject that can respond to shortcut commands (quit, cut, copy, and paste).
  77. type Shortcutable interface {
  78. TypedShortcut(Shortcut)
  79. }
  80. // Tabbable describes any object that needs to accept the Tab key presses.
  81. //
  82. // Since: 2.1
  83. type Tabbable interface {
  84. // AcceptsTab() is a hook called by the key press handling logic.
  85. // If it returns true then the Tab key events will be sent using TypedKey.
  86. AcceptsTab() bool
  87. }
  88. // Tappable describes any CanvasObject that can also be tapped.
  89. // This should be implemented by buttons etc that wish to handle pointer interactions.
  90. type Tappable interface {
  91. Tapped(*PointEvent)
  92. }