Skip to content

Commit 3d415b0

Browse files
committed
Small code cleanups
1 parent f8ddd41 commit 3d415b0

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

widget.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
var (
19+
// DefaultColor is the standard color for text rendering.
1920
DefaultColor = color.RGBA{255, 255, 255, 255}
2021
)
2122

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

175176
func flattenImage(img image.Image, clr color.Color) image.Image {
176177
bounds := img.Bounds()
177-
flatten := image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
178+
flatten := image.NewRGBA(bounds)
178179
draw.Draw(flatten, flatten.Bounds(), img, image.Point{}, draw.Src)
179180
alphaThreshold := uint32(20000)
180181

@@ -188,6 +189,7 @@ func flattenImage(img image.Image, clr color.Color) image.Image {
188189
}
189190
}
190191
}
192+
191193
return flatten
192194
}
193195

widget_button.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ func NewButtonWidget(bw *BaseWidget, opts WidgetConfig) (*ButtonWidget, error) {
4444
flatten: flatten,
4545
}
4646
if icon != "" {
47-
w.LoadImage(icon)
47+
if err := w.LoadImage(icon); err != nil {
48+
return nil, err
49+
}
4850
}
4951

5052
return w, nil
5153
}
5254

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

70+
// SetImage updates the widget's icon.
6771
func (w *ButtonWidget) SetImage(img image.Image) {
6872
w.icon = img
6973
if w.flatten {

widget_weather.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"embed"
66
"fmt"
77
"image"
8-
"image/color"
98
"io/ioutil"
109
"log"
1110
"net/http"
@@ -38,10 +37,8 @@ func weatherImage(name string) image.Image {
3837
type WeatherWidget struct {
3938
*ButtonWidget
4039

41-
data WeatherData
42-
color color.Color
43-
theme string
44-
flatten bool
40+
data WeatherData
41+
theme string
4542
}
4643

4744
// WeatherData handles fetches and parsing weather data.

0 commit comments

Comments
 (0)