New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List does not render contents when forwarding to a container #1934
Comments
Hello :), if you want to hold different widgets, you could return just list := widget.NewList(
func() int {
return len(l)
},
func() fyne.CanvasObject {
return container.NewVBox(
widget.NewLabel(""),
widget.NewLabel("Other text"),
)
},
func(id widget.ListItemID, obj fyne.CanvasObject) {
c := obj.(*fyne.Container)
c.Objects[0].(*widget.Label).SetText(l[id])
c.Objects[1].(*widget.Label).SetText("Other text " + l[id])
},
) If you want to create custom widgets, you need to implement fyne.Widget or extend widget.BaseWidget or extend an existing widget. You can find more information in the docs: |
@fpabl0 is correct here, containers do not support embedding in that way - only widgets can be extended. |
Yes, I alluded to that solution in my original question. That's terrible, especially as the number of widgets goes up.
I guess though why doesn't it work? The returned object is implementing the interface, seems like that should be good enough? Seems very unexpected. |
A container is merely for containing items, the widgets are the smart elements.
Container is not an interface, it is a concrete type. |
I don't understand why I can't extend a container (or easily embed it into a widget as far as I can tell), that seems like an oversight. Being able to build complex widgets that are groups of widgets seems like a pretty basic UI thing. |
Widgets are a super set of containers. They provide that functionality but also more. Maybe #709 is relevant? |
Describe the bug:
I'd like to include more complex widgets in a list. I tried using interface composition to make my type pretend to be a container, but that didn't work. Then I implemented the CanvasObject interface, forwarding everything to an internal container, and that also didn't work.
If I return just the container from the create callback for the list, it works fine. However, then I need to type assert for each of the objects in the container in the update function. It would be much more convenient if I only needed to do a single type assert that gave me my custom type.
I'm new to fyne so it's possible that this isn't the right way to create a custom widget.
To Reproduce:
Steps to reproduce the behaviour:
Screenshots:
Example code:
Interface composition version
Forwarding version
Device (please complete the following information):
The text was updated successfully, but these errors were encountered: