Skip to content

Commit bcf0103

Browse files
committed
Support setting an image on a ButtonWidget after initialization
1 parent 70b919e commit bcf0103

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

‎widget_button.go‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,34 @@ func NewButtonWidget(bw *BaseWidget, opts WidgetConfig) (*ButtonWidget, error) {
4343
color: color,
4444
flatten: flatten,
4545
}
46-
4746
if icon != "" {
48-
path, err := expandPath(w.base, icon)
49-
if err != nil {
50-
return nil, err
51-
}
52-
w.icon, err = loadImage(path)
53-
if err != nil {
54-
return nil, err
55-
}
56-
if w.icon != nil && w.flatten {
57-
w.icon = flattenImage(w.icon, w.color)
58-
}
47+
w.LoadImage(icon)
5948
}
6049

6150
return w, nil
6251
}
6352

53+
func (w *ButtonWidget) LoadImage(path string) error {
54+
path, err := expandPath(w.base, path)
55+
if err != nil {
56+
return err
57+
}
58+
icon, err := loadImage(path)
59+
if err != nil {
60+
return err
61+
}
62+
63+
w.SetImage(icon)
64+
return nil
65+
}
66+
67+
func (w *ButtonWidget) SetImage(img image.Image) {
68+
w.icon = img
69+
if w.flatten {
70+
w.icon = flattenImage(w.icon, w.color)
71+
}
72+
}
73+
6474
// Update renders the widget.
6575
func (w *ButtonWidget) Update(dev *streamdeck.Device) error {
6676
size := int(dev.Pixels)

0 commit comments

Comments
 (0)
⌂ 换网址