Skip to content

Commit

Permalink
Add support for big clock widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
zMoooooritz authored and muesli committed May 29, 2021
1 parent 9328b84 commit aca4e2c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
5 changes: 4 additions & 1 deletion widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func NewWidget(index uint8, id string, action *ActionConfig, actionHold *ActionC
}

case "clock":
return &ClockWidget{bw}
return &ClockWidget{
BaseWidget: bw,
mode: config["mode"],
}

case "date":
return &DateWidget{bw}
Expand Down
53 changes: 38 additions & 15 deletions widget_clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type ClockWidget struct {
BaseWidget
mode string
}

func (w *ClockWidget) Update(dev *streamdeck.Device) {
Expand All @@ -18,27 +19,49 @@ func (w *ClockWidget) Update(dev *streamdeck.Device) {
img := image.NewRGBA(image.Rect(0, 0, size, size))
height := size - (margin * 2)
pt := (float64(height) / 3.0) * 72.0 / float64(dev.DPI)
ptfull := float64(height) * 72.0 / float64(dev.DPI)

t := time.Now()
hour := t.Format("15")
min := t.Format("04")
sec := t.Format("05")

drawString(img, image.Rectangle{image.Pt(0, margin), image.Pt(size, margin+(height/3))},
ttfBoldFont,
hour,
pt,
image.Pt(-1, -1))
drawString(img, image.Rectangle{image.Pt(0, (height/3)+margin), image.Pt(size, margin+(height/3)*2)},
ttfFont,
min,
pt,
image.Pt(-1, -1))
drawString(img, image.Rectangle{image.Pt(0, (height/3)*2+margin), image.Pt(size, margin+height)},
ttfThinFont,
sec,
pt,
image.Pt(-1, -1))
switch w.mode {
case "hour":
drawString(img, image.Rect(0, 0, size, size),
ttfBoldFont,
hour,
ptfull,
image.Pt(-1, -1))
case "min":
drawString(img, image.Rect(0, 0, size, size),
ttfFont,
min,
ptfull,
image.Pt(-1, -1))
case "sec":
drawString(img, image.Rect(0, 0, size, size),
ttfThinFont,
sec,
ptfull,
image.Pt(-1, -1))
default:
drawString(img, image.Rectangle{image.Pt(0, margin), image.Pt(size, margin+(height/3))},
ttfBoldFont,
hour,
pt,
image.Pt(-1, -1))
drawString(img, image.Rectangle{image.Pt(0, (height/3)+margin), image.Pt(size, margin+(height/3)*2)},
ttfFont,
min,
pt,
image.Pt(-1, -1))
drawString(img, image.Rectangle{image.Pt(0, (height/3)*2+margin), image.Pt(size, margin+height)},
ttfThinFont,
sec,
pt,
image.Pt(-1, -1))
}

err := dev.SetImage(w.key, img)
if err != nil {
Expand Down

0 comments on commit aca4e2c

Please sign in to comment.