@@ -20,11 +20,12 @@ type TextButton struct {
2020 updateHandler func (streamdeck.Button )
2121 btnIndex int
2222 actionHandler streamdeck.ButtonActionHandler
23+ margin int
2324}
2425
2526// GetImageForButton is the interface implemention to get the button's image as an image.Image
2627func (btn * TextButton ) GetImageForButton (btnSize int ) image.Image {
27- img := getImageWithText (btn .label , btn .textColour , btn .backgroundColour , btnSize )
28+ img := getImageWithText (btn .label , btn .textColour , btn .backgroundColour , btnSize , btn . margin )
2829 return img
2930}
3031
@@ -80,19 +81,36 @@ func (btn *TextButton) Pressed() {
8081// background. The text will be set on a single line, and auto-sized to fill the button as best
8182// as possible.
8283func NewTextButton (label string ) * TextButton {
83- btn := NewTextButtonWithColours (label , color .White , color .Black )
84+ btn := NewTextButtonWithColoursAndMargin (label , color .White , color .Black , 4 )
85+ return btn
86+ }
87+
88+ // NewTextButtonWithMargin creates a new TextButton with the specified text on it, in white on a
89+ // black background. The text will be set on a single line, and auto-sized to fill the button as
90+ // best as possible, taking into account the margin on each side.
91+ func NewTextButtonWithMargin (label string , margin int ) * TextButton {
92+ btn := NewTextButtonWithColoursAndMargin (label , color .White , color .Black , margin )
8493 return btn
8594}
8695
8796// NewTextButtonWithColours creates a new TextButton with the specified text on it, in the specified
8897// text and background colours. The text will be set on a single line, and auto-sized to fill the
8998// button as best as possible.
9099func NewTextButtonWithColours (label string , textColour color.Color , backgroundColour color.Color ) * TextButton {
91- btn := & TextButton { label : label , textColour : textColour , backgroundColour : backgroundColour }
100+ btn := NewTextButtonWithColoursAndMargin ( label , textColour , backgroundColour , 4 )
92101 return btn
93102}
94103
95- func getImageWithText (text string , textColour color.Color , backgroundColour color.Color , btnSize int ) image.Image {
104+ // NewTextButtonWithColoursAndMargin creates a new TextButton with the specified text on it, in the
105+ // specified text and background colours. The text will be set on a single line, and auto-sized to
106+ // fill the button as best as possible, taking into account the margin on each side.
107+ func NewTextButtonWithColoursAndMargin (label string , textColour color.Color , backgroundColour color.Color , margin int ) * TextButton {
108+ btn := & TextButton {label : label , textColour : textColour , backgroundColour : backgroundColour , margin : margin }
109+ return btn
110+ }
111+
112+
113+ func getImageWithText (text string , textColour color.Color , backgroundColour color.Color , btnSize int , margin int ) image.Image {
96114
97115 size := float64 (18 )
98116
@@ -104,7 +122,7 @@ func getImageWithText(text string, textColour color.Color, backgroundColour colo
104122 width := 0
105123 for size = 1 ; size < 60 ; size ++ {
106124 width = getTextWidth (text , size )
107- if width >= btnSize {
125+ if width >= btnSize - ( margin * 2 ) {
108126 size = size - 1
109127 break
110128 }
0 commit comments