MinSizable

This commit is contained in:
Martyn 2021-12-24 12:40:19 +00:00
parent beb6159a23
commit ec64972517
2 changed files with 18 additions and 1 deletions

View File

@ -31,6 +31,8 @@ func main() {
b2.OutlineWidth = 3
b3 := profilebtn.NewProfileBtn()
b3.OutlineColor = color.RGBA{0x4f, 0, 0xfc, 0xff}
b3.SetMinSize(fyne.NewSize(40, 40))
b3.Refresh()
w.SetContent(container.NewBorder(container.NewHBox(b2, b3), nil, nil, nil, b))
w.Resize(fyne.NewSize(640, 480))
w.ShowAndRun()

View File

@ -18,7 +18,9 @@ type profileBtn struct {
OutlineWidth int
OutlineColor color.Color
profileImage image.Image
profileImage image.Image
minSizeOverridden bool
minSizeRequested fyne.Size
}
func (b *profileBtn) Resize(s fyne.Size) {
@ -44,6 +46,7 @@ func NewProfileBtn() *profileBtn {
w.OutlineWidth = 0
w.OutlineColor = color.White
w.SetProfileResource(nil)
w.minSizeOverridden = false
return w
}
@ -60,6 +63,15 @@ func (b *profileBtn) SetProfileResource(r fyne.Resource) {
}
func (b *profileBtn) SetMinSize(s fyne.Size) {
if s.Height > 0 && s.Width > 0 {
b.minSizeRequested = s
b.minSizeOverridden = true
return
}
b.minSizeOverridden = false
}
func (b *profileBtn) SetProfileImage(i image.Image) {
b.profileImage = i
}
@ -98,6 +110,9 @@ func (r *profileBtnRenderer) Render(w, h int) image.Image {
}
func (r *profileBtnRenderer) MinSize() fyne.Size {
if r.w.minSizeOverridden {
return r.w.minSizeRequested
}
return fyne.NewSize(theme.Padding()*4, theme.Padding()*4)
}