Check required height when auto resizing font
This commit is contained in:
parent
95cc760dea
commit
4d44a01b29
2 changed files with 13 additions and 6 deletions
12
button.go
12
button.go
|
@ -114,9 +114,14 @@ func (b *Button) SetFont(fnt *sfnt.Font, size int) {
|
|||
}
|
||||
|
||||
func (b *Button) resizeFont() {
|
||||
w := b.rect.Dx() - b.field.Padding()*2
|
||||
if w == 0 {
|
||||
w, h := b.rect.Dx()-b.field.Padding()*2, b.rect.Dy()-b.field.Padding()*2
|
||||
if w == 0 || h == 0 {
|
||||
if b.textAutoSize == b.textSize {
|
||||
return
|
||||
}
|
||||
b.textAutoSize = b.textSize
|
||||
ff := FontFace(b.textFont, b.textSize)
|
||||
b.field.SetFont(ff, fontMutex)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -124,7 +129,8 @@ func (b *Button) resizeFont() {
|
|||
var ff font.Face
|
||||
for autoSize = b.textSize; autoSize > 0; autoSize-- {
|
||||
ff = FontFace(b.textFont, autoSize)
|
||||
if BoundString(ff, b.field.Text()).Dx() <= w {
|
||||
bounds := BoundString(ff, b.field.Text())
|
||||
if bounds.Dx() <= w && bounds.Dy() <= h {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
7
text.go
7
text.go
|
@ -166,8 +166,8 @@ func (t *Text) resizeFont() {
|
|||
return
|
||||
}
|
||||
|
||||
w := t.rect.Dx() - t.field.Padding()*2
|
||||
if w == 0 {
|
||||
w, h := t.rect.Dx()-t.field.Padding()*2, t.rect.Dy()-t.field.Padding()*2
|
||||
if w == 0 || h == 0 {
|
||||
if t.textAutoSize == t.textSize {
|
||||
return
|
||||
}
|
||||
|
@ -181,7 +181,8 @@ func (t *Text) resizeFont() {
|
|||
var ff font.Face
|
||||
for autoSize = t.textSize; autoSize > 0; autoSize-- {
|
||||
ff = FontFace(t.textFont, autoSize)
|
||||
if BoundString(ff, t.field.Text()).Dx() <= w {
|
||||
bounds := BoundString(ff, t.field.Text())
|
||||
if bounds.Dx() <= w && bounds.Dy() <= h {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue