Skip to content

Commit 19fce65

Browse files
committed
Some fixes from the feedback from go lint
1 parent a7b3bab commit 19fce65

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

buttons/colour.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import (
88
streamdeck "github.com/magicmonkey/go-streamdeck"
99
)
1010

11+
// ColourButton represents a button which is a solid block of a single colour
1112
type ColourButton struct {
1213
colour color.Color
1314
updateHandler func(streamdeck.Button)
1415
btnIndex int
1516
actionHandler streamdeck.ButtonActionHandler
1617
}
1718

19+
// GetImageForButton is the interface implemention to get the button's image as an image.Image
1820
func (btn *ColourButton) GetImageForButton() image.Image {
1921
ButtonSize := 96
2022
img := image.NewRGBA(image.Rect(0, 0, ButtonSize, ButtonSize))
@@ -23,33 +25,43 @@ func (btn *ColourButton) GetImageForButton() image.Image {
2325
return img
2426
}
2527

28+
// SetButtonIndex is the interface implemention to set which button on the Streamdeck this is
2629
func (btn *ColourButton) SetButtonIndex(btnIndex int) {
2730
btn.btnIndex = btnIndex
2831
}
2932

33+
// GetButtonIndex is the interface implemention to get which button on the Streamdeck this is
3034
func (btn *ColourButton) GetButtonIndex() int {
3135
return btn.btnIndex
3236
}
3337

38+
// SetColour allows the colour for the button to be changed on the fly
3439
func (btn *ColourButton) SetColour(colour color.Color) {
3540
btn.colour = colour
3641
btn.updateHandler(btn)
3742
}
3843

44+
// RegisterUpdateHandler is the interface implemention to let the engine give this button a callback to
45+
// use to request that the button image is updated on the Streamdeck.
3946
func (btn *ColourButton) RegisterUpdateHandler(f func(streamdeck.Button)) {
4047
btn.updateHandler = f
4148
}
4249

50+
// SetActionHandler allows a ButtonActionHandler implementation to be
51+
// set on this button, so that something can happen when the button is pressed.
4352
func (btn *ColourButton) SetActionHandler(a streamdeck.ButtonActionHandler) {
4453
btn.actionHandler = a
4554
}
4655

56+
// Pressed is the interface implementation for letting the engine notify that the button has been
57+
// pressed. This hands-off to the specified ButtonActionHandler if it has been set.
4758
func (btn *ColourButton) Pressed() {
4859
if btn.actionHandler != nil {
4960
btn.actionHandler.Pressed(btn)
5061
}
5162
}
5263

64+
// NewColourButton creates a new ColourButton of the specified colour
5365
func NewColourButton(colour color.Color) *ColourButton {
5466
btn := &ColourButton{colour: colour}
5567
return btn

buttons/imagefile.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
streamdeck "github.com/magicmonkey/go-streamdeck"
99
)
1010

11+
// ImageFileButton represents a button with an image on it, where the image is loaded
12+
// from a file.
1113
type ImageFileButton struct {
1214
filePath string
1315
img image.Image
@@ -16,18 +18,22 @@ type ImageFileButton struct {
1618
actionHandler streamdeck.ButtonActionHandler
1719
}
1820

21+
// GetImageForButton is the interface implemention to get the button's image as an image.Image
1922
func (btn *ImageFileButton) GetImageForButton() image.Image {
2023
return btn.img
2124
}
2225

26+
// SetButtonIndex is the interface implemention to set which button on the Streamdeck this is
2327
func (btn *ImageFileButton) SetButtonIndex(btnIndex int) {
2428
btn.btnIndex = btnIndex
2529
}
2630

31+
// GetButtonIndex is the interface implemention to get which button on the Streamdeck this is
2732
func (btn *ImageFileButton) GetButtonIndex() int {
2833
return btn.btnIndex
2934
}
3035

36+
// SetFilePath allows the image file to be changed on the fly
3137
func (btn *ImageFileButton) SetFilePath(filePath string) error {
3238
btn.filePath = filePath
3339
err := btn.loadImage()
@@ -60,20 +66,27 @@ func (btn *ImageFileButton) loadImage() error {
6066
return nil
6167
}
6268

69+
// RegisterUpdateHandler is the interface implemention to let the engine give this button a callback to
70+
// use to request that the button image is updated on the Streamdeck.
6371
func (btn *ImageFileButton) RegisterUpdateHandler(f func(streamdeck.Button)) {
6472
btn.updateHandler = f
6573
}
6674

75+
// SetActionHandler allows a ButtonActionHandler implementation to be
76+
// set on this button, so that something can happen when the button is pressed.
6777
func (btn *ImageFileButton) SetActionHandler(a streamdeck.ButtonActionHandler) {
6878
btn.actionHandler = a
6979
}
7080

81+
// Pressed is the interface implementation for letting the engine notify that the button has been
82+
// pressed. This hands-off to the specified ButtonActionHandler if it has been set.
7183
func (btn *ImageFileButton) Pressed() {
7284
if btn.actionHandler != nil {
7385
btn.actionHandler.Pressed(btn)
7486
}
7587
}
7688

89+
// NewImageFileButton creates a new ImageFileButton with the specified image on it
7790
func NewImageFileButton(filePath string) (*ImageFileButton, error) {
7891
btn := &ImageFileButton{filePath: filePath}
7992
err := btn.loadImage()

buttons/text.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
streamdeck "github.com/magicmonkey/go-streamdeck"
1313
)
1414

15+
// TextButton represents a button with text on it
1516
type TextButton struct {
1617
label string
1718
textColour color.Color
@@ -21,53 +22,71 @@ type TextButton struct {
2122
actionHandler streamdeck.ButtonActionHandler
2223
}
2324

25+
// GetImageForButton is the interface implemention to get the button's image as an image.Image
2426
func (btn *TextButton) GetImageForButton() image.Image {
2527
img := getImageWithText(btn.label, btn.textColour, btn.backgroundColour)
2628
return img
2729
}
2830

31+
// SetButtonIndex is the interface implemention to set which button on the Streamdeck this is
2932
func (btn *TextButton) SetButtonIndex(btnIndex int) {
3033
btn.btnIndex = btnIndex
3134
}
3235

36+
// GetButtonIndex is the interface implemention to get which button on the Streamdeck this is
3337
func (btn *TextButton) GetButtonIndex() int {
3438
return btn.btnIndex
3539
}
3640

41+
// SetText allows the text on the button to be changed on the fly
3742
func (btn *TextButton) SetText(label string) {
3843
btn.label = label
3944
btn.updateHandler(btn)
4045
}
4146

47+
// SetTextColour allows the colour of the text on the button to be changed on the fly
4248
func (btn *TextButton) SetTextColour(textColour color.Color) {
4349
btn.textColour = textColour
4450
btn.updateHandler(btn)
4551
}
4652

53+
// SetBackgroundColor allows the background colour on the button to be changed on the fly
4754
func (btn *TextButton) SetBackgroundColor(backgroundColour color.Color) {
4855
btn.backgroundColour = backgroundColour
4956
btn.updateHandler(btn)
5057
}
5158

59+
// RegisterUpdateHandler is the interface implemention to let the engine give this button a callback to
60+
// use to request that the button image is updated on the Streamdeck.
5261
func (btn *TextButton) RegisterUpdateHandler(f func(streamdeck.Button)) {
5362
btn.updateHandler = f
5463
}
5564

65+
// SetActionHandler allows a ButtonActionHandler implementation to be
66+
// set on this button, so that something can happen when the button is pressed.
5667
func (btn *TextButton) SetActionHandler(a streamdeck.ButtonActionHandler) {
5768
btn.actionHandler = a
5869
}
5970

71+
// Pressed is the interface implementation for letting the engine notify that the button has been
72+
// pressed. This hands-off to the specified ButtonActionHandler if it has been set.
6073
func (btn *TextButton) Pressed() {
6174
if btn.actionHandler != nil {
6275
btn.actionHandler.Pressed(btn)
6376
}
6477
}
6578

79+
// NewTextButton creates a new TextButton with the specified text on it, in white on a black
80+
// background. The text will be set on a single line, and auto-sized to fill the button as best
81+
// as possible.
6682
func NewTextButton(label string) *TextButton {
6783
btn := NewTextButtonWithColours(label, color.White, color.Black)
6884
return btn
6985
}
7086

87+
// NewTextButtonWithColours creates a new TextButton with the specified text on it, in the specified
88+
// text and background colours. The text will be set on a single line, and auto-sized to fill the
89+
// button as best as possible.
7190
func NewTextButtonWithColours(label string, textColour color.Color, backgroundColour color.Color) *TextButton {
7291
btn := &TextButton{label: label, textColour: textColour, backgroundColour: backgroundColour}
7392
return btn
@@ -92,17 +111,17 @@ func getImageWithText(text string, textColour color.Color, backgroundColour colo
92111
}
93112
}
94113

95-
src_img := image.NewUniform(textColour)
114+
srcImg := image.NewUniform(textColour)
96115

97-
dst_img := image.NewRGBA(image.Rect(0, 0, ButtonSize, ButtonSize))
98-
draw.Draw(dst_img, dst_img.Bounds(), image.NewUniform(backgroundColour), image.Point{0, 0}, draw.Src)
116+
dstImg := image.NewRGBA(image.Rect(0, 0, ButtonSize, ButtonSize))
117+
draw.Draw(dstImg, dstImg.Bounds(), image.NewUniform(backgroundColour), image.Point{0, 0}, draw.Src)
99118

100119
c := freetype.NewContext()
101120
c.SetFont(myfont)
102-
c.SetDst(dst_img)
103-
c.SetSrc(src_img)
121+
c.SetDst(dstImg)
122+
c.SetSrc(srcImg)
104123
c.SetFontSize(size)
105-
c.SetClip(dst_img.Bounds())
124+
c.SetClip(dstImg.Bounds())
106125

107126
x := int((96 - width) / 2) // Horizontally centre text
108127
y := int(50 + (size / 3)) // Fudged vertical centre, erm, very "heuristic"
@@ -115,14 +134,14 @@ func getImageWithText(text string, textColour color.Color, backgroundColour colo
115134
fmt.Println(textWidth)
116135
117136
f := &font.Drawer{
118-
Dst: dst_img,
137+
Dst: dstImg,
119138
Src: src_img,
120139
Face: basicfont.Face7x13,
121140
Dot: fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)},
122141
}
123142
f.DrawString(text)
124143
*/
125-
return dst_img
144+
return dstImg
126145
}
127146

128147
func getTextWidth(text string, size float64) int {

0 commit comments

Comments
 (0)