Clickable (not disablable)
This commit is contained in:
parent
ec64972517
commit
20d8a06508
|
@ -2,28 +2,32 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/dialog"
|
||||||
|
|
||||||
"git.martyn.berlin/martyn/fyne-widgets/pkg/profilebtn"
|
"git.martyn.berlin/martyn/fyne-widgets/pkg/profilebtn"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var w fyne.Window
|
||||||
|
|
||||||
|
func Pressed() {
|
||||||
|
i := dialog.NewInformation("You clicked!", "You clicked the button", w)
|
||||||
|
i.Show()
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := app.New()
|
a := app.New()
|
||||||
w := a.NewWindow("ProfileBtn")
|
w = a.NewWindow("ProfileBtn")
|
||||||
b := profilebtn.NewProfileBtn()
|
b := profilebtn.NewProfileBtn()
|
||||||
i, s, err := image.Decode(bytes.NewReader(resourceProfilepicdoesnotexistJpg.StaticContent))
|
i, _, err := image.Decode(bytes.NewReader(resourceProfilepicdoesnotexistJpg.StaticContent))
|
||||||
fmt.Println(s)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println(i.Bounds())
|
|
||||||
b.SetProfileImage(i)
|
b.SetProfileImage(i)
|
||||||
b.OutlineWidth = 5
|
b.OutlineWidth = 5
|
||||||
b2 := profilebtn.NewProfileBtn()
|
b2 := profilebtn.NewProfileBtn()
|
||||||
|
@ -31,6 +35,7 @@ func main() {
|
||||||
b2.OutlineWidth = 3
|
b2.OutlineWidth = 3
|
||||||
b3 := profilebtn.NewProfileBtn()
|
b3 := profilebtn.NewProfileBtn()
|
||||||
b3.OutlineColor = color.RGBA{0x4f, 0, 0xfc, 0xff}
|
b3.OutlineColor = color.RGBA{0x4f, 0, 0xfc, 0xff}
|
||||||
|
b3.OnTapped = Pressed
|
||||||
b3.SetMinSize(fyne.NewSize(40, 40))
|
b3.SetMinSize(fyne.NewSize(40, 40))
|
||||||
b3.Refresh()
|
b3.Refresh()
|
||||||
w.SetContent(container.NewBorder(container.NewHBox(b2, b3), nil, nil, nil, b))
|
w.SetContent(container.NewBorder(container.NewHBox(b2, b3), nil, nil, nil, b))
|
||||||
|
|
|
@ -12,8 +12,10 @@ import (
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ fyne.Focusable = (*profileBtn)(nil)
|
||||||
|
|
||||||
type profileBtn struct {
|
type profileBtn struct {
|
||||||
widget.BaseWidget
|
widget.DisableableWidget
|
||||||
|
|
||||||
OutlineWidth int
|
OutlineWidth int
|
||||||
OutlineColor color.Color
|
OutlineColor color.Color
|
||||||
|
@ -21,12 +23,54 @@ type profileBtn struct {
|
||||||
profileImage image.Image
|
profileImage image.Image
|
||||||
minSizeOverridden bool
|
minSizeOverridden bool
|
||||||
minSizeRequested fyne.Size
|
minSizeRequested fyne.Size
|
||||||
|
|
||||||
|
OnTapped func() `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// FocusGained is a hook called by the focus handling logic after this object gained the focus.
|
||||||
|
func (b *profileBtn) FocusGained() {
|
||||||
|
// b.focused = true
|
||||||
|
b.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FocusLost is a hook called by the focus handling logic after this object lost the focus.
|
||||||
|
func (b *profileBtn) FocusLost() {
|
||||||
|
// b.focused = false
|
||||||
|
b.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypedRune is a hook called by the input handling logic on text input events if this object is focused.
|
||||||
|
func (b *profileBtn) TypedRune(rune) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypedKey is a hook called by the input handling logic on key events if this object is focused.
|
||||||
|
func (b *profileBtn) TypedKey(ev *fyne.KeyEvent) {
|
||||||
|
if ev.Name == fyne.KeySpace {
|
||||||
|
b.Tapped(nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *profileBtn) Resize(s fyne.Size) {
|
func (b *profileBtn) Resize(s fyne.Size) {
|
||||||
b.BaseWidget.Resize(s)
|
b.BaseWidget.Resize(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *profileBtn) Disabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *profileBtn) Tapped(*fyne.PointEvent) {
|
||||||
|
if b.Disabled() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//b.tapAnimation()
|
||||||
|
b.Refresh()
|
||||||
|
|
||||||
|
if b.OnTapped != nil {
|
||||||
|
b.OnTapped()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *profileBtn) CreateRenderer() fyne.WidgetRenderer {
|
func (b *profileBtn) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return NewProfileBtnRenderer(b)
|
return NewProfileBtnRenderer(b)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue