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
Add a "SimpleWidget" or "StaticRenderer" so I can make canvas primitives interactive #709
Comments
suggest:index 9d021e03..ab37f920 100644
--- a/internal/painter/gl/draw.go
+++ b/internal/painter/gl/draw.go
@@ -153,5 +153,9 @@ func (p *glPainter) drawObject(o fyne.CanvasObject, pos fyne.Position, frame fyn
p.drawGradient(obj, p.newGlRadialGradientTexture, pos, frame)
case fyne.Widget:
p.drawWidget(obj, pos, frame)
+ default:
+ if obj, ok := o.(interface{ superCanvas() fyne.CanvasObject }); ok {
+ p.drawObject(obj.superCanvas(), pos, frame)
+ }
}
} cmd/fyne_demo/main.go// Package main loads a very basic Hello World graphical application.
package main
import (
"fmt"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/driver/desktop"
"fyne.io/fyne/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Hello")
hello := widget.NewLabel("Hello Fyne!")
w.SetContent(widget.NewVBox(
hello,
//widget.NewButton("Hi!", func() {
NewCustomButton("Hi!", func() {
hello.SetText("Welcome :)")
}),
))
w.ShowAndRun()
}
type CustomButton struct {
*widget.Button
}
func (button *CustomButton) superCanvas() fyne.CanvasObject {
return button.Button
}
// MouseIn is called when a desktop pointer enters the widget
func (button *CustomButton) MouseIn(ev *desktop.MouseEvent) {
fmt.Println("mouse in...", ev)
button.Button.MouseIn(ev)
}
func NewCustomButton(text string, fn func()) *CustomButton {
return &CustomButton{
Button: widget.NewButton(text, fn),
}
} |
The example you posted above is already supported - in your constructor function call |
Hey @andydotxyz, I'm still looking for a solution to this. I'd simply like to create a custom image widget that I can regularly update. For the record, it would be a map tile that I would update based on the desired coordinates. Anyone can help ? |
I don't think that what you described required a custom widget @alkanna - if you have a |
I was looking into being able to inject additional sprites onto that image and draw them over it as I see fit |
Then perhaps |
Making this public would address fyne-io#709.
Easiest usage is to return NewSimpleRenderer(myObj) from CreateRenderer Fixes fyne-io#709
This is now on |
Is your feature request related to a problem? Please describe:
The amount of code required to make a simple widget is high, especially if I just want to wrap an existing CanvasObject.
Is it possible to construct a solution with the existing API?
Yes, but it's a lot of code.
Describe the solution you'd like to see:
Something like the following would allow me to make a tappable image:
The text was updated successfully, but these errors were encountered: