Just treat resources as image holders for now
This commit is contained in:
parent
a5819955f7
commit
beb6159a23
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
"image/color"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
|
@ -25,7 +26,12 @@ func main() {
|
||||||
fmt.Println(i.Bounds())
|
fmt.Println(i.Bounds())
|
||||||
b.SetProfileImage(i)
|
b.SetProfileImage(i)
|
||||||
b.OutlineWidth = 5
|
b.OutlineWidth = 5
|
||||||
w.SetContent(container.NewBorder(nil, nil, nil, nil, b))
|
b2 := profilebtn.NewProfileBtn()
|
||||||
|
b2.SetProfileResource(resourceProfilepicdoesnotexistJpg)
|
||||||
|
b2.OutlineWidth = 3
|
||||||
|
b3 := profilebtn.NewProfileBtn()
|
||||||
|
b3.OutlineColor = color.RGBA{0x4f, 0, 0xfc, 0xff}
|
||||||
|
w.SetContent(container.NewBorder(container.NewHBox(b2, b3), nil, nil, nil, b))
|
||||||
w.Resize(fyne.NewSize(640, 480))
|
w.Resize(fyne.NewSize(640, 480))
|
||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
|
@ -1,6 +1,7 @@
|
||||||
package profilebtn
|
package profilebtn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
|
@ -42,11 +43,21 @@ func NewProfileBtn() *profileBtn {
|
||||||
w.ExtendBaseWidget(w)
|
w.ExtendBaseWidget(w)
|
||||||
w.OutlineWidth = 0
|
w.OutlineWidth = 0
|
||||||
w.OutlineColor = color.White
|
w.OutlineColor = color.White
|
||||||
|
w.SetProfileResource(nil)
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *profileBtn) SetProfileResource(r fyne.Resource) {
|
func (b *profileBtn) SetProfileResource(r fyne.Resource) {
|
||||||
b.profileImage = canvas.NewImageFromResource(r).Image
|
if r != nil {
|
||||||
|
i, _, err := image.Decode(bytes.NewReader(r.Content()))
|
||||||
|
if err == nil {
|
||||||
|
b.profileImage = i
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t, _, _ := image.Decode(bytes.NewReader(resourceProfileBtnPng.StaticContent))
|
||||||
|
b.profileImage = t
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *profileBtn) SetProfileImage(i image.Image) {
|
func (b *profileBtn) SetProfileImage(i image.Image) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue