Skip to content

Commit 3be0c67

Browse files
committed
Fixed font-size estimation
In one of the commits that added support for the mini, and further commits, a new 'btnSize' parameter was introduced. This however was not reflected in the algorithm that determines the size. Without this fix, the text was always too wide (90px is more than the 72px my stream deck has), and also no longer virtually centered. This commit should address both these issues. I've only tested this with the v2.
1 parent 4780578 commit 3be0c67

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

buttons/text.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func getImageWithText(text string, textColour color.Color, backgroundColour colo
104104
width := 0
105105
for size = 1; size < 60; size++ {
106106
width = getTextWidth(text, size)
107-
if width > 90 {
107+
if width > btnSize {
108108
size = size - 1
109109
break
110110
}
@@ -123,7 +123,7 @@ func getImageWithText(text string, textColour color.Color, backgroundColour colo
123123
c.SetClip(dstImg.Bounds())
124124

125125
x := int((btnSize - width) / 2) // Horizontally centre text
126-
y := int(50 + (size / 3)) // Fudged vertical centre, erm, very "heuristic"
126+
y := int(btnSize / 2) + int(size / 3) // Fudged vertical centre, erm, very "heuristic"
127127

128128
pt := freetype.Pt(x, y)
129129
c.DrawString(text, pt)

0 commit comments

Comments
 (0)