Skip to content

Commit

Permalink
Add grid wrap to demo app to show it off
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 27, 2023
1 parent 45a6d34 commit d4dcf33
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
38 changes: 38 additions & 0 deletions cmd/fyne_demo/tutorials/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,44 @@ func collectionScreen(_ fyne.Window) fyne.CanvasObject {
return container.NewCenter(content)
}

func makeGridWrapTab(_ fyne.Window) fyne.CanvasObject {
data := make([]string, 1000)
for i := range data {
data[i] = "Test Item " + strconv.Itoa(i)
}

icon := widget.NewIcon(nil)
label := widget.NewLabel("Select An Item From The List")
vbox := container.NewVBox(icon, label)

grid := widget.NewGridWrap(
func() int {
return len(data)
},
func() fyne.CanvasObject {
text := widget.NewLabel("Template Object")
text.Alignment = fyne.TextAlignCenter
return container.NewVBox(container.NewPadded(widget.NewIcon(theme.DocumentIcon())), text)
},
func(id widget.ListItemID, item fyne.CanvasObject) {
item.(*fyne.Container).Objects[1].(*widget.Label).SetText(data[id])
},
)
grid.OnSelected = func(id widget.ListItemID) {
label.SetText(data[id])
icon.SetResource(theme.DocumentIcon())
}
grid.OnUnselected = func(id widget.ListItemID) {
label.SetText("Select An Item From The List")
icon.SetResource(nil)
}
grid.Select(15)

split := container.NewHSplit(grid, container.NewCenter(vbox))
split.Offset = 0.6
return split
}

func makeListTab(_ fyne.Window) fyne.CanvasObject {
data := make([]string, 1000)
for i := range data {
Expand Down
7 changes: 6 additions & 1 deletion cmd/fyne_demo/tutorials/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ var (
makeTreeTab,
true,
},
"gridwrap": {"GridWrap",
"A grid based arrangement of cached elements that wraps rows to fit.",
makeGridWrapTab,
true,
},
"dialogs": {"Dialogs",
"Work with dialogs.",
dialogScreen,
Expand All @@ -175,7 +180,7 @@ var (
// TutorialIndex defines how our tutorials should be laid out in the index tree
TutorialIndex = map[string][]string{
"": {"welcome", "canvas", "animations", "icons", "widgets", "collections", "containers", "dialogs", "windows", "binding", "advanced"},
"collections": {"list", "table", "tree"},
"collections": {"list", "table", "tree", "gridwrap"},
"containers": {"apptabs", "border", "box", "center", "doctabs", "grid", "scroll", "split"},
"widgets": {"accordion", "button", "card", "entry", "form", "input", "progress", "text", "toolbar"},
}
Expand Down

0 comments on commit d4dcf33

Please sign in to comment.