I'm trying to resize this (list) because it's showing only one row, and the second to see it need to scroll down I want to show multiple rows this is the code:-
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
type CustomList struct {
Header fyne.CanvasObject
List *widget.List
}
a := app.New()
// Create a new window
w := a.NewWindow("Resources Manager")
// Create a list with five columns
list = widget.NewList(
func() int {
return len(clientInfos)
},
func() fyne.CanvasObject {
return container.NewHBox(widget.NewIcon(nil), widget.NewLabel(""))
},
func(index int, obj fyne.CanvasObject) {
c := obj.(*fyne.Container)
icon := c.Objects[0].(*widget.Icon)
label := c.Objects[1].(*widget.Label)
// load the image resource
img, err := fyne.LoadResourceFromPath(clientInfos[index].Country)
if err != nil {
fmt.Println("Failed to load image", err)
return
}
// set image to icon and text to label
icon.SetResource(img)
label.SetText(fmt.Sprintf("%s | %s | %s | %s | %s",
clientInfos[index].AppName,
clientInfos[index].Version,
clientInfos[index].kerenl,
clientInfos[index].Price,
clientInfos[index].Size,
))
label.TextStyle = fyne.TextStyle{Bold: true, Italic: false, Monospace: true}
},
)
list.OnSelected = func(id int) {
selectedID = id
}
customList := &CustomList{
Header: widget.NewLabel("Icon | AppName | kerenl | Price | Size | Status"),
List: list,
}
customList.List.Resize(fyne.Size{Height: 434})
// Create a container for the buttons
buttonContainer := container.NewVBox()
buttonContainer.Add(widget.NewButton("Install", func() {
// Handle button click
}))
buttonContainer.Add(widget.NewButton("download", func() {
// Handle button click
}))
buttonContainer.Add(widget.NewButton("Upgrade", func() {
// Handle button click
}))
buttonContainer.Add(widget.NewButton("Refresh", func() {
list.Refresh()
// Handle button click
}))
buttonContainer.Resize(fyne.NewSize(230, 300))
vbox := container.NewVBox(
customList.Header,
customList.List,
)
vbox.Resize(fyne.NewSize(600, 320))
horizontalSplit := container.NewHSplit(vbox, buttonContainer)
horizontalSplit.SetOffset(0.8)
content := container.NewVBox(horizontalSplit, textArea)
w.SetContent(content)
w.Resize(fyne.NewSize(800, 270))
w.ShowAndRun()
also is there any other Golang library for gui's? because it seems that most of them are outdated right? however, i really need something easier to build a GUI with like
In fyne a widget is put in a container, and that container will normally have a layout. If you have this setup then your manual calls to Resize
will be overridden by the layout chosen.
The use of VBox is doing exactly that, as it’s algorithm wants to make every item as short as possible.
Use Border instead, with the header at the top and the list taking up remaining space.
Objects in Fyne always fill the space given to them, but for it to do what you want it’s important to pick the right container/layout. https://developer.fyne.io/explore/layouts