I am struggling to get scrolling behaviour working. The code has two rectangles and a diagonal line just to give some larger container continence to wrap inside a scroll container which should produce the desired scrolling behaviour when user resize the window ? Go1.21.3 , fyne cli version: v2.3.5, win11. I am not getting any scroll bars. I have tried many variations for hours.
I wish to produce a very long bar chart ( multiple lines and rectangles) which the user will need to scroll along. Scrolling is a standard use case applicable to many GUI’s. https://developer.fyne.io/api/v2.4/container/scroll.html is a bit dry on examples.
package main
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
)
func main() {
myApp := app.New()
w := myApp.NewWindow("Rectangle")
rect := canvas.NewRectangle(color.White) // just a white rectangle
rect.StrokeColor = color.Opaque
rect.Resize(fyne.NewSize(150, 150))
rect2 := canvas.NewRectangle(color.Gray{}) // just a gray rectangle
rect2.Resize(fyne.NewSize(150, 150))
rect2.Move(fyne.NewPos(150, 150))
line := canvas.NewLine(color.RGBA{255, 0, 0, 255}) // just a red line diagonal
line.StrokeWidth = 5
line.Position1 = fyne.NewPos(0, 0)
line.Position2 = fyne.NewPos(300, 300)
// Create a fixed-size container for the content
content := container.NewWithoutLayout(rect2, line, rect) //place objects into content
content.Resize(fyne.NewSize(300, 300)) // Set a fixed size
// Create a scrollable container placing the content into it (content is bigger than container)
scrollContainer := container.NewVScroll(content) // NewScroll , NewVScroll , try different /
w.SetContent(scrollContainer)
w.ShowAndRun()
}
The scroll container uses the content MinSize to figure out what space is going to have to scroll I think. And your container without layout doesn’t have a minimum size configured (the layout would normally take care of that for you).