giu
giu copied to clipboard
use a loop in layout (or explain how this can be done)
Related problem
g.Layout{ for key, record := range records { g.Selectable(record.Name).OnClick(func() { fmt.Println(key) }), } },
Your request
The widget page only show "hard" ways of doing stuff, but for this, I want to see how this kind of things can be done.
Alternative solution
No response
Additional context
No response
@MarcelXia you need to use giu.Custom(func() {/*your for loop*/})
@MarcelXia You can use the ...
operator to unpack a slice into individual variables.
First create a slice of unpackable giu elements, in your case, []*g.SelectableWidget
var selectables []*g.Selectable{}
for key, record := range records {
selectables = append(selectables, g.Selectable(record.Name).OnClick(func() { fmt.Println(key) }))
}
Then add the unpacked slice in the giu element like this
g.Layout{
selectables...
}
Yah and one more thing. Be aware of the fact that if the records variable is a map the iteration order will be different each frame!
@MarcelXia any updates here?
Inactive for longer time & code demo above so closing; feel free to ping me for any details or re-opening.