layout.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package screens
  2. import (
  3. "image/color"
  4. "fyne.io/fyne"
  5. "fyne.io/fyne/canvas"
  6. "fyne.io/fyne/layout"
  7. "fyne.io/fyne/widget"
  8. )
  9. func makeCell() fyne.CanvasObject {
  10. rect := canvas.NewRectangle(&color.RGBA{128, 128, 128, 255})
  11. rect.SetMinSize(fyne.NewSize(30, 30))
  12. return rect
  13. }
  14. func makeBorderLayout() *fyne.Container {
  15. top := makeCell()
  16. bottom := makeCell()
  17. left := makeCell()
  18. right := makeCell()
  19. middle := widget.NewLabelWithStyle("BorderLayout", fyne.TextAlignCenter, fyne.TextStyle{})
  20. borderLayout := layout.NewBorderLayout(top, bottom, left, right)
  21. return fyne.NewContainerWithLayout(borderLayout,
  22. top, bottom, left, right, middle)
  23. }
  24. func makeBoxLayout() *fyne.Container {
  25. top := makeCell()
  26. bottom := makeCell()
  27. middle := widget.NewLabel("BoxLayout")
  28. center := makeCell()
  29. right := makeCell()
  30. col := fyne.NewContainerWithLayout(layout.NewVBoxLayout(),
  31. top, middle, bottom)
  32. return fyne.NewContainerWithLayout(layout.NewHBoxLayout(),
  33. col, center, right)
  34. }
  35. func makeFixedGridLayout() *fyne.Container {
  36. box1 := makeCell()
  37. box2 := widget.NewLabel("FixedGrid")
  38. box3 := makeCell()
  39. box4 := makeCell()
  40. return fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(75, 75)),
  41. box1, box2, box3, box4)
  42. }
  43. func makeGridLayout() *fyne.Container {
  44. box1 := makeCell()
  45. box2 := widget.NewLabel("Grid")
  46. box3 := makeCell()
  47. box4 := makeCell()
  48. return fyne.NewContainerWithLayout(layout.NewGridLayout(2),
  49. box1, box2, box3, box4)
  50. }
  51. // LayoutPanel loads a panel that shows the layouts available for a container
  52. func LayoutPanel() fyne.CanvasObject {
  53. return widget.NewTabContainer(
  54. widget.NewTabItem("Border", makeBorderLayout()),
  55. widget.NewTabItem("Box", makeBoxLayout()),
  56. widget.NewTabItem("Fixed Grid", makeFixedGridLayout()),
  57. widget.NewTabItem("Grid", makeGridLayout()),
  58. )
  59. }