Skip to content

Commit

Permalink
Improve label rendering in top widget
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed May 29, 2021
1 parent 0551d6d commit 7a48fb5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions widget_top.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type TopWidget struct {
func (w *TopWidget) Update(dev *streamdeck.Device) {
var value float64
var label string

switch w.mode {
case "cpu":
cpuUsage, err := cpu.Percent(0, false)
Expand Down Expand Up @@ -57,9 +58,7 @@ func (w *TopWidget) Update(dev *streamdeck.Device) {
}

size := int(dev.Pixels)
pt := (float64(size) / 3.0) * 66.0 / float64(dev.DPI)
ptSmall := (float64(size) / 3.0) * 40.0 / float64(dev.DPI)

margin := size / 18
img := image.NewRGBA(image.Rect(0, 0, size, size))

draw.Draw(img,
Expand All @@ -84,18 +83,19 @@ func (w *TopWidget) Update(dev *streamdeck.Device) {
bounds,
ttfFont,
strconv.FormatInt(int64(value), 10),
pt,
13,
image.Pt(-1, -1))

// draw description
bounds = img.Bounds()
bounds.Min.Y = size - 18
bounds.Min.Y = size - 16
bounds.Max.Y -= margin

drawString(img,
bounds,
ttfFont,
"% "+label,
ptSmall,
-1,
image.Pt(-1, -1))

err = dev.SetImage(w.key, img)
Expand Down

0 comments on commit 7a48fb5

Please sign in to comment.