@@ -20,11 +20,12 @@ type TextButton struct {
20
20
updateHandler func (streamdeck.Button )
21
21
btnIndex int
22
22
actionHandler streamdeck.ButtonActionHandler
23
+ margin int
23
24
}
24
25
25
26
// GetImageForButton is the interface implemention to get the button's image as an image.Image
26
27
func (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 )
28
29
return img
29
30
}
30
31
@@ -80,19 +81,36 @@ func (btn *TextButton) Pressed() {
80
81
// background. The text will be set on a single line, and auto-sized to fill the button as best
81
82
// as possible.
82
83
func NewTextButton (label string ) * TextButton {
83
- btn := NewTextButtonWithColours (label , color .White , color .Black )
84
+ btn := NewTextButtonWithColoursAndMargin (label , color .White , color .Black , 6 )
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 )
84
93
return btn
85
94
}
86
95
87
96
// NewTextButtonWithColours creates a new TextButton with the specified text on it, in the specified
88
97
// text and background colours. The text will be set on a single line, and auto-sized to fill the
89
98
// button as best as possible.
90
99
func 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 , 6 )
92
101
return btn
93
102
}
94
103
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 {
96
114
97
115
size := float64 (18 )
98
116
@@ -104,7 +122,7 @@ func getImageWithText(text string, textColour color.Color, backgroundColour colo
104
122
width := 0
105
123
for size = 1 ; size < 60 ; size ++ {
106
124
width = getTextWidth (text , size )
107
- if width >= btnSize {
125
+ if width >= btnSize - ( margin * 2 ) {
108
126
size = size - 1
109
127
break
110
128
}
0 commit comments