spacer.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package layout
  2. import "fyne.io/fyne/v2"
  3. // SpacerObject is any object that can be used to space out child objects
  4. type SpacerObject interface {
  5. ExpandVertical() bool
  6. ExpandHorizontal() bool
  7. }
  8. // Spacer is any simple object that can be used in a box layout to space
  9. // out child objects
  10. type Spacer struct {
  11. FixHorizontal bool
  12. FixVertical bool
  13. size fyne.Size
  14. pos fyne.Position
  15. hidden bool
  16. }
  17. // NewSpacer returns a spacer object which can fill vertical and horizontal
  18. // space. This is primarily used with a box layout.
  19. func NewSpacer() fyne.CanvasObject {
  20. return &Spacer{}
  21. }
  22. // ExpandVertical returns whether or not this spacer expands on the vertical axis
  23. func (s *Spacer) ExpandVertical() bool {
  24. return !s.FixVertical
  25. }
  26. // ExpandHorizontal returns whether or not this spacer expands on the horizontal axis
  27. func (s *Spacer) ExpandHorizontal() bool {
  28. return !s.FixHorizontal
  29. }
  30. // Size returns the current size of this Spacer
  31. func (s *Spacer) Size() fyne.Size {
  32. return s.size
  33. }
  34. // Resize sets a new size for the Spacer - this will be called by the layout
  35. func (s *Spacer) Resize(size fyne.Size) {
  36. s.size = size
  37. }
  38. // Position returns the current position of this Spacer
  39. func (s *Spacer) Position() fyne.Position {
  40. return s.pos
  41. }
  42. // Move sets a new position for the Spacer - this will be called by the layout
  43. func (s *Spacer) Move(pos fyne.Position) {
  44. s.pos = pos
  45. }
  46. // MinSize returns a 0 size as a Spacer can shrink to no actual size
  47. func (s *Spacer) MinSize() fyne.Size {
  48. return fyne.NewSize(0, 0)
  49. }
  50. // Visible returns true if this spacer should affect the layout
  51. func (s *Spacer) Visible() bool {
  52. return !s.hidden
  53. }
  54. // Show sets the Spacer to be part of the layout calculations
  55. func (s *Spacer) Show() {
  56. s.hidden = false
  57. }
  58. // Hide removes this Spacer from layout calculations
  59. func (s *Spacer) Hide() {
  60. s.hidden = true
  61. }
  62. // Refresh does nothing for a spacer but is part of the CanvasObject definition
  63. func (s *Spacer) Refresh() {
  64. }