Clickable (not disablable)
This commit is contained in:
parent
ec64972517
commit
20d8a06508
|
@ -2,28 +2,32 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
|
||||
"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() {
|
||||
a := app.New()
|
||||
w := a.NewWindow("ProfileBtn")
|
||||
w = a.NewWindow("ProfileBtn")
|
||||
b := profilebtn.NewProfileBtn()
|
||||
i, s, err := image.Decode(bytes.NewReader(resourceProfilepicdoesnotexistJpg.StaticContent))
|
||||
fmt.Println(s)
|
||||
i, _, err := image.Decode(bytes.NewReader(resourceProfilepicdoesnotexistJpg.StaticContent))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(i.Bounds())
|
||||
b.SetProfileImage(i)
|
||||
b.OutlineWidth = 5
|
||||
b2 := profilebtn.NewProfileBtn()
|
||||
|
@ -31,6 +35,7 @@ func main() {
|
|||
b2.OutlineWidth = 3
|
||||
b3 := profilebtn.NewProfileBtn()
|
||||
b3.OutlineColor = color.RGBA{0x4f, 0, 0xfc, 0xff}
|
||||
b3.OnTapped = Pressed
|
||||
b3.SetMinSize(fyne.NewSize(40, 40))
|
||||
b3.Refresh()
|
||||
w.SetContent(container.NewBorder(container.NewHBox(b2, b3), nil, nil, nil, b))
|
||||
|
|
|
@ -12,8 +12,10 @@ import (
|
|||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
var _ fyne.Focusable = (*profileBtn)(nil)
|
||||
|
||||
type profileBtn struct {
|
||||
widget.BaseWidget
|
||||
widget.DisableableWidget
|
||||
|
||||
OutlineWidth int
|
||||
OutlineColor color.Color
|
||||
|
@ -21,12 +23,54 @@ type profileBtn struct {
|
|||
profileImage image.Image
|
||||
minSizeOverridden bool
|
||||
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) {
|
||||
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 {
|
||||
return NewProfileBtnRenderer(b)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue