Switch outline to mask
This commit is contained in:
parent
5a8a14f63d
commit
a5819955f7
|
@ -31,7 +31,6 @@ func (b *profileBtn) CreateRenderer() fyne.WidgetRenderer {
|
|||
func NewProfileBtnRenderer(b *profileBtn) *profileBtnRenderer {
|
||||
r := &profileBtnRenderer{
|
||||
canvas.NewRasterFromImage(image.NewRGBA(image.Rect(0, 0, 10, 10))),
|
||||
canvas.NewCircle(b.OutlineColor),
|
||||
b,
|
||||
}
|
||||
b.ExtendBaseWidget(b)
|
||||
|
@ -55,9 +54,8 @@ func (b *profileBtn) SetProfileImage(i image.Image) {
|
|||
}
|
||||
|
||||
type profileBtnRenderer struct {
|
||||
rast *canvas.Raster
|
||||
background *canvas.Circle
|
||||
w *profileBtn
|
||||
rast *canvas.Raster
|
||||
w *profileBtn
|
||||
}
|
||||
|
||||
func min(x, y int) int {
|
||||
|
@ -78,7 +76,9 @@ func (r *profileBtnRenderer) Render(w, h int) image.Image {
|
|||
if r.w.profileImage != nil {
|
||||
src := r.w.profileImage
|
||||
b := src.Bounds().Size()
|
||||
wh := image.NewUniform(r.w.OutlineColor)
|
||||
dst := image.NewRGBA(image.Rect(0, 0, b.X, b.Y))
|
||||
draw.DrawMask(dst, dst.Bounds(), wh, image.ZP, &circle{image.Point{b.X / 2, b.Y / 2}, (min(b.Y, b.Y) / 2)}, image.ZP, draw.Over)
|
||||
draw.DrawMask(dst, dst.Bounds(), src, image.ZP, &circle{image.Point{b.X / 2, b.Y / 2}, (min(b.Y, b.Y) / 2) - r.w.OutlineWidth}, image.ZP, draw.Over)
|
||||
return dst
|
||||
} else {
|
||||
|
@ -91,7 +91,6 @@ func (r *profileBtnRenderer) MinSize() fyne.Size {
|
|||
}
|
||||
|
||||
func (r *profileBtnRenderer) Layout(size fyne.Size) {
|
||||
r.background.Resize(size)
|
||||
squareSize := fyne.NewSize(minf(size.Width, size.Height), minf(size.Width, size.Height))
|
||||
r.rast.Resize(squareSize)
|
||||
if squareSize.Width < size.Width {
|
||||
|
@ -119,5 +118,5 @@ func (r *profileBtnRenderer) Destroy() {
|
|||
|
||||
func (r *profileBtnRenderer) Objects() []fyne.CanvasObject {
|
||||
r.Refresh()
|
||||
return []fyne.CanvasObject{r.background, r.rast}
|
||||
return []fyne.CanvasObject{r.rast}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue