Skip to content

Commit

Permalink
Small code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jun 10, 2021
1 parent f8ddd41 commit 3d415b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

var (
// DefaultColor is the standard color for text rendering.
DefaultColor = color.RGBA{255, 255, 255, 255}
)

Expand Down Expand Up @@ -174,7 +175,7 @@ func loadThemeImage(theme string, img string) (image.Image, error) {

func flattenImage(img image.Image, clr color.Color) image.Image {
bounds := img.Bounds()
flatten := image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
flatten := image.NewRGBA(bounds)
draw.Draw(flatten, flatten.Bounds(), img, image.Point{}, draw.Src)
alphaThreshold := uint32(20000)

Expand All @@ -188,6 +189,7 @@ func flattenImage(img image.Image, clr color.Color) image.Image {
}
}
}

return flatten
}

Expand Down
6 changes: 5 additions & 1 deletion widget_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ func NewButtonWidget(bw *BaseWidget, opts WidgetConfig) (*ButtonWidget, error) {
flatten: flatten,
}
if icon != "" {
w.LoadImage(icon)
if err := w.LoadImage(icon); err != nil {
return nil, err
}
}

return w, nil
}

// LoadImage loads an image from disk.
func (w *ButtonWidget) LoadImage(path string) error {
path, err := expandPath(w.base, path)
if err != nil {
Expand All @@ -64,6 +67,7 @@ func (w *ButtonWidget) LoadImage(path string) error {
return nil
}

// SetImage updates the widget's icon.
func (w *ButtonWidget) SetImage(img image.Image) {
w.icon = img
if w.flatten {
Expand Down
7 changes: 2 additions & 5 deletions widget_weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"embed"
"fmt"
"image"
"image/color"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -38,10 +37,8 @@ func weatherImage(name string) image.Image {
type WeatherWidget struct {
*ButtonWidget

data WeatherData
color color.Color
theme string
flatten bool
data WeatherData
theme string
}

// WeatherData handles fetches and parsing weather data.
Expand Down

0 comments on commit 3d415b0

Please sign in to comment.