From d4dcf33d1e55daf9f54ede392a5e952888a6de24 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Thu, 27 Jul 2023 14:04:41 -0400 Subject: [PATCH] Add grid wrap to demo app to show it off --- cmd/fyne_demo/tutorials/collection.go | 38 +++++++++++++++++++++++++++ cmd/fyne_demo/tutorials/data.go | 7 ++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/cmd/fyne_demo/tutorials/collection.go b/cmd/fyne_demo/tutorials/collection.go index c9caa1f640..cb9572250b 100644 --- a/cmd/fyne_demo/tutorials/collection.go +++ b/cmd/fyne_demo/tutorials/collection.go @@ -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 { diff --git a/cmd/fyne_demo/tutorials/data.go b/cmd/fyne_demo/tutorials/data.go index 96de1cc111..e146883ee3 100644 --- a/cmd/fyne_demo/tutorials/data.go +++ b/cmd/fyne_demo/tutorials/data.go @@ -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, @@ -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"}, }