layouts.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package container // import "fyne.io/fyne/v2/container"
  2. import (
  3. "fyne.io/fyne/v2"
  4. "fyne.io/fyne/v2/internal"
  5. "fyne.io/fyne/v2/layout"
  6. )
  7. // NewAdaptiveGrid creates a new container with the specified objects and using the grid layout.
  8. // When in a horizontal arrangement the rowcols parameter will specify the column count, when in vertical
  9. // it will specify the rows. On mobile this will dynamically refresh when device is rotated.
  10. //
  11. // Since: 1.4
  12. func NewAdaptiveGrid(rowcols int, objects ...fyne.CanvasObject) *fyne.Container {
  13. return New(layout.NewAdaptiveGridLayout(rowcols), objects...)
  14. }
  15. // NewBorder creates a new container with the specified objects and using the border layout.
  16. // The top, bottom, left and right parameters specify the items that should be placed around edges,
  17. // the remaining elements will be in the center. Nil can be used to an edge if it should not be filled.
  18. //
  19. // Since: 1.4
  20. func NewBorder(top, bottom, left, right fyne.CanvasObject, objects ...fyne.CanvasObject) *fyne.Container {
  21. all := objects
  22. if top != nil {
  23. all = append(all, top)
  24. }
  25. if bottom != nil {
  26. all = append(all, bottom)
  27. }
  28. if left != nil {
  29. all = append(all, left)
  30. }
  31. if right != nil {
  32. all = append(all, right)
  33. }
  34. if len(objects) == 1 && objects[0] == nil {
  35. internal.LogHint("Border layout requires only 4 parameters, optional items cannot be nil")
  36. all = all[1:]
  37. }
  38. return New(layout.NewBorderLayout(top, bottom, left, right), all...)
  39. }
  40. // NewCenter creates a new container with the specified objects centered in the available space.
  41. //
  42. // Since: 1.4
  43. func NewCenter(objects ...fyne.CanvasObject) *fyne.Container {
  44. return New(layout.NewCenterLayout(), objects...)
  45. }
  46. // NewGridWithColumns creates a new container with the specified objects and using the grid layout with
  47. // a specified number of columns. The number of rows will depend on how many children are in the container.
  48. //
  49. // Since: 1.4
  50. func NewGridWithColumns(cols int, objects ...fyne.CanvasObject) *fyne.Container {
  51. return New(layout.NewGridLayoutWithColumns(cols), objects...)
  52. }
  53. // NewGridWithRows creates a new container with the specified objects and using the grid layout with
  54. // a specified number of rows. The number of columns will depend on how many children are in the container.
  55. //
  56. // Since: 1.4
  57. func NewGridWithRows(rows int, objects ...fyne.CanvasObject) *fyne.Container {
  58. return New(layout.NewGridLayoutWithRows(rows), objects...)
  59. }
  60. // NewGridWrap creates a new container with the specified objects and using the gridwrap layout.
  61. // Every element will be resized to the size parameter and the content will arrange along a row and flow to a
  62. // new row if the elements don't fit.
  63. //
  64. // Since: 1.4
  65. func NewGridWrap(size fyne.Size, objects ...fyne.CanvasObject) *fyne.Container {
  66. return New(layout.NewGridWrapLayout(size), objects...)
  67. }
  68. // NewHBox creates a new container with the specified objects and using the HBox layout.
  69. // The objects will be placed in the container from left to right and always displayed
  70. // at their horizontal MinSize. Use a different layout if the objects are intended
  71. // to be larger then their horizontal MinSize.
  72. //
  73. // Since: 1.4
  74. func NewHBox(objects ...fyne.CanvasObject) *fyne.Container {
  75. return New(layout.NewHBoxLayout(), objects...)
  76. }
  77. // NewMax creates a new container with the specified objects filling the available space.
  78. //
  79. // Since: 1.4
  80. //
  81. // Deprecated: Use container.NewStack() instead.
  82. func NewMax(objects ...fyne.CanvasObject) *fyne.Container {
  83. return NewStack(objects...)
  84. }
  85. // NewPadded creates a new container with the specified objects inset by standard padding size.
  86. //
  87. // Since: 1.4
  88. func NewPadded(objects ...fyne.CanvasObject) *fyne.Container {
  89. return New(layout.NewPaddedLayout(), objects...)
  90. }
  91. // NewStack returns a new container that stacks objects on top of each other.
  92. // Objects at the end of the container will be stacked on top of objects before.
  93. // Having only a single object has no impact as CanvasObjects will
  94. // fill the available space even without a Stack.
  95. //
  96. // Since: 2.4
  97. func NewStack(objects ...fyne.CanvasObject) *fyne.Container {
  98. return New(layout.NewStackLayout(), objects...)
  99. }
  100. // NewVBox creates a new container with the specified objects and using the VBox layout.
  101. // The objects will be stacked in the container from top to bottom and always displayed
  102. // at their vertical MinSize. Use a different layout if the objects are intended
  103. // to be larger then their vertical MinSize.
  104. //
  105. // Since: 1.4
  106. func NewVBox(objects ...fyne.CanvasObject) *fyne.Container {
  107. return New(layout.NewVBoxLayout(), objects...)
  108. }