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
canvas.Image should be Tappable #697
Comments
The canvas primitives (things in the canvas package) like Image are just for drawing - interaction is not supported at that level. To be Tappable an item would need to be a widget. It is possible that we are missing a helper construct like widget.NewSimpleWidget(fyne.CanvasObject) but I don’t know if that would help here? |
If that works how I think it works, then it can produce exactly what I want (A Tappable image I could update every time it is Tapped). I confess that I still have not figured out what Solitaire is doing to act like a Tappable Image, so this would be extremely helpful. |
I created a new issue and will close this in preference to that feature request: #709 |
I strangely made this (by error) and it worked.... image := canvas.NewImageFromImage(i) // this is an image.Image
image.FillMode = canvas.ImageFillContain
// This button will be placed "over" the image using a Padded box
openButton := widget.NewButton("", func(){
fmt.Println("Image clicked...")
})
// this encapsulate the image and the button
box := container.NewPadded(image, openButton) I'm not sure to understand why it works, but it works... |
NewPadded lays all elements out inside a container with a padding inset. NewMax would do the same with no gap around the edge. You have created a button with no content above your image. |
Ho ! I Should test ! |
type ImageButton struct {
*canvas.Image
OnTapped func()
}
func NewImageButtonFromFile(file string, onTapped func()) *ImageButton {
return &ImageButton{canvas.NewImageFromFile(file), onTapped}
}
func (b *ImageButton) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(b.Image)
}
func (b *ImageButton) Tapped(ev *fyne.PointEvent) {
b.OnTapped()
} it works!!! |
Is your feature request related to a problem? Please describe:
canvas.Image.Tapped could be set for each image and this would make games easier to make.
Is it possible to construct a solution with the existing API?
I can see from the Solitaire example that a tappable gameboard is possible yet more complicated than desired.
Describe the solution you'd like to see:
I want code like this to work:
func main() {
a := app.New()
win := a.NewWindow("Blooms")
board := canvas.NewImageFromFile("board.png")
board.Tapped = func(event *fyne.PointEvent) { fmt.Println("tap", event) }
win.SetContent(board)
win.ShowAndRun()
}
The text was updated successfully, but these errors were encountered: