Skip to content

Commit

Permalink
Add center layout and make scrolling longer
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Apr 26, 2020
1 parent 4840d64 commit 8b25720
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions cmd/fyne_demo/screens/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func ContainerScreen() fyne.CanvasObject {
// layouts
widget.NewTabItem("Border", makeBorderLayout()),
widget.NewTabItem("Box", makeBoxLayout()),
widget.NewTabItem("Center", makeCenterLayout()),
widget.NewTabItem("Grid", makeGridLayout()),
)
}
Expand Down Expand Up @@ -49,12 +50,31 @@ func makeBoxLayout() *fyne.Container {
col, center, right)
}

func makeButtonList(count int) []fyne.CanvasObject {
var items []fyne.CanvasObject
for i := 1; i <= count; i++ {
index := i // capture
items = append(items, widget.NewButton(fmt.Sprintf("Button %d", index), func() {
fmt.Println("Tapped", index)
}))
}

return items
}

func makeCell() fyne.CanvasObject {
rect := canvas.NewRectangle(&color.RGBA{128, 128, 128, 255})
rect.SetMinSize(fyne.NewSize(30, 30))
return rect
}

func makeCenterLayout() *fyne.Container {
middle := widget.NewButton("CenterLayout", func() {})

return fyne.NewContainerWithLayout(layout.NewCenterLayout(),
middle)
}

func makeGridLayout() *fyne.Container {
box1 := makeCell()
box2 := widget.NewLabel("Grid")
Expand All @@ -66,21 +86,11 @@ func makeGridLayout() *fyne.Container {
}

func makeScrollTab() fyne.CanvasObject {
list := widget.NewHBox()
list2 := widget.NewVBox()

for i := 1; i <= 20; i++ {
index := i // capture
list.Append(widget.NewButton(fmt.Sprintf("Button %d", index), func() {
fmt.Println("Tapped", index)
}))
list2.Append(widget.NewButton(fmt.Sprintf("Button %d", index), func() {
fmt.Println("Tapped", index)
}))
}
hlist := makeButtonList(20)
vlist := makeButtonList(50)

horiz := widget.NewHScrollContainer(list)
vert := widget.NewVScrollContainer(list2)
horiz := widget.NewHScrollContainer(widget.NewHBox(hlist...))
vert := widget.NewVScrollContainer(widget.NewVBox(vlist...))

return fyne.NewContainerWithLayout(layout.NewAdaptiveGridLayout(2),
fyne.NewContainerWithLayout(layout.NewBorderLayout(horiz, nil, nil, nil), horiz, vert),
Expand Down

0 comments on commit 8b25720

Please sign in to comment.