Skip to content

Commit

Permalink
Simplify initialization of time & top widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jun 8, 2021
1 parent ec4edf8 commit 6f28df5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ func NewWidget(base string, kc KeyConfig, bg image.Image) (Widget, error) {
kc.Widget.Config = make(map[string]interface{})
kc.Widget.Config["format"] = "%H;%i;%s"
kc.Widget.Config["font"] = "bold;regular;thin"
return NewTimeWidget(*bw, kc.Widget)
return NewTimeWidget(*bw, kc.Widget), nil

case "date":
kc.Widget.Config = make(map[string]interface{})
kc.Widget.Config["format"] = "%l;%d;%M"
kc.Widget.Config["font"] = "regular;bold;regular"
return NewTimeWidget(*bw, kc.Widget)
return NewTimeWidget(*bw, kc.Widget), nil

case "time":
return NewTimeWidget(*bw, kc.Widget)
return NewTimeWidget(*bw, kc.Widget), nil

case "recentWindow":
return NewRecentWindowWidget(*bw, kc.Widget)

case "top":
return NewTopWidget(*bw, kc.Widget)
return NewTopWidget(*bw, kc.Widget), nil
}

// unknown widget ID
Expand Down
9 changes: 5 additions & 4 deletions widget_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ type TimeWidget struct {
font string
}

func NewTimeWidget(bw BaseWidget, opts WidgetConfig) (*TimeWidget, error) {
// NewTimeWidget returns a new TimeWidget.
func NewTimeWidget(bw BaseWidget, opts WidgetConfig) *TimeWidget {
bw.setInterval(opts.Interval, 500)

var format, font string
ConfigValue(opts.Config["format"], &format)
ConfigValue(opts.Config["font"], &font)
_ = ConfigValue(opts.Config["format"], &format)
_ = ConfigValue(opts.Config["font"], &font)

return &TimeWidget{
BaseWidget: bw,
format: format,
font: font,
}, nil
}
}

// Update renders the widget.
Expand Down
10 changes: 6 additions & 4 deletions widget_top.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ import (
// TopWidget is a widget displaying the current CPU/MEM usage as a bar.
type TopWidget struct {
BaseWidget

mode string
fillColor string

lastValue float64
}

func NewTopWidget(bw BaseWidget, opts WidgetConfig) (*TopWidget, error) {
// NewTopWidget returns a new TopWidget.
func NewTopWidget(bw BaseWidget, opts WidgetConfig) *TopWidget {
bw.setInterval(opts.Interval, 500)

var mode, fillColor string
ConfigValue(opts.Config["mode"], &mode)
ConfigValue(opts.Config["fillColor"], &fillColor)
_ = ConfigValue(opts.Config["mode"], &mode)
_ = ConfigValue(opts.Config["fillColor"], &fillColor)

return &TopWidget{
BaseWidget: bw,
mode: mode,
fillColor: fillColor,
}, nil
}
}

// Update renders the widget.
Expand Down

0 comments on commit 6f28df5

Please sign in to comment.