Skip to content

Commit

Permalink
Support setting an image on a ButtonWidget after initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jun 10, 2021
1 parent 70b919e commit bcf0103
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions widget_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,34 @@ func NewButtonWidget(bw *BaseWidget, opts WidgetConfig) (*ButtonWidget, error) {
color: color,
flatten: flatten,
}

if icon != "" {
path, err := expandPath(w.base, icon)
if err != nil {
return nil, err
}
w.icon, err = loadImage(path)
if err != nil {
return nil, err
}
if w.icon != nil && w.flatten {
w.icon = flattenImage(w.icon, w.color)
}
w.LoadImage(icon)
}

return w, nil
}

func (w *ButtonWidget) LoadImage(path string) error {
path, err := expandPath(w.base, path)
if err != nil {
return err
}
icon, err := loadImage(path)
if err != nil {
return err
}

w.SetImage(icon)
return nil
}

func (w *ButtonWidget) SetImage(img image.Image) {
w.icon = img
if w.flatten {
w.icon = flattenImage(w.icon, w.color)
}
}

// Update renders the widget.
func (w *ButtonWidget) Update(dev *streamdeck.Device) error {
size := int(dev.Pixels)
Expand Down

0 comments on commit bcf0103

Please sign in to comment.