Skip to content

Commit

Permalink
Embed and inherit ButtonWidget's options in Weather- & RecentWindowWi…
Browse files Browse the repository at this point in the history
…dget
  • Loading branch information
muesli committed Jun 10, 2021
1 parent bcf0103 commit f8ddd41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
20 changes: 11 additions & 9 deletions widget_recent_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ func NewRecentWindowWidget(bw *BaseWidget, opts WidgetConfig) (*RecentWindowWidg
var showTitle bool
_ = ConfigValue(opts.Config["showTitle"], &showTitle)

widget, err := NewButtonWidget(bw, opts)
if err != nil {
return nil, err
}

return &RecentWindowWidget{
BaseWidget: bw,
window: uint8(window),
showTitle: showTitle,
ButtonWidget: widget,
window: uint8(window),
showTitle: showTitle,
}, nil
}

Expand Down Expand Up @@ -60,12 +65,9 @@ func (w *RecentWindowWidget) Update(dev *streamdeck.Device) error {
}
}

bw := ButtonWidget{
BaseWidget: w.BaseWidget,
icon: recentWindows[w.window].Icon,
label: name,
}
return bw.Update(dev)
w.label = name
w.SetImage(recentWindows[w.window].Icon)
return w.ButtonWidget.Update(dev)
}

return w.render(dev, img)
Expand Down
34 changes: 11 additions & 23 deletions widget_weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,27 @@ func (w *WeatherData) Fetch() {
}

// NewWeatherWidget returns a new WeatherWidget.
func NewWeatherWidget(bw BaseWidget, opts WidgetConfig) *WeatherWidget {
func NewWeatherWidget(bw *BaseWidget, opts WidgetConfig) (*WeatherWidget, error) {
bw.setInterval(opts.Interval, 60000)

var location, unit, theme string
_ = ConfigValue(opts.Config["location"], &location)
_ = ConfigValue(opts.Config["unit"], &unit)
_ = ConfigValue(opts.Config["theme"], &theme)
var color color.Color
_ = ConfigValue(opts.Config["color"], &color)
var flatten bool
_ = ConfigValue(opts.Config["flatten"], &flatten)

if color == nil {
color = DefaultColor
widget, err := NewButtonWidget(bw, opts)
if err != nil {
return nil, err
}

return &WeatherWidget{
BaseWidget: bw,
ButtonWidget: widget,
data: WeatherData{
location: location,
unit: unit,
},
color: color,
theme: theme,
flatten: flatten,
}
theme: theme,
}, nil
}

// Update renders the widget.
Expand Down Expand Up @@ -216,17 +211,10 @@ func (w *WeatherWidget) Update(dev *streamdeck.Device) error {
weatherIcon = weatherImage(imagePath)
}

if w.flatten {
weatherIcon = flattenImage(weatherIcon, w.color)
}
bw := ButtonWidget{
BaseWidget: w.BaseWidget,
color: w.color,
icon: weatherIcon,
label: temp,
flatten: w.flatten,
}
return bw.Update(dev)
w.label = temp
w.SetImage(weatherIcon)

return w.ButtonWidget.Update(dev)
}

func formatUnit(unit string) string {
Expand Down

0 comments on commit f8ddd41

Please sign in to comment.