diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-01-29 01:36:21 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-01-29 01:36:21 (GMT) |
commit | 5a0b63e6bf45b1b66566bbc7094e4a473816e507 (patch) | |
tree | 23aec781ff9547ceb30bc3fd545da78cbb365b6b | |
parent | c8e6a5570cf122e47f54a1922fecb563e697aa37 (diff) |
play time clock can now count down as well
-rw-r--r-- | src/rhlibrary/player_widget.go | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/rhlibrary/player_widget.go b/src/rhlibrary/player_widget.go index b86d236..f0e4583 100644 --- a/src/rhlibrary/player_widget.go +++ b/src/rhlibrary/player_widget.go @@ -182,34 +182,56 @@ func addScrubber(grid *gtk.Grid, p *player.PlayerChan) (err error) { return } +func getPlayTimeString(duration, pos time.Duration, countdown bool) string { + t := time.Unix(0, 0).UTC() + if countdown { + return t.Add(duration).Add(-1 * pos).Format("-15:04:05.0") + } + return t.Add(pos).Format(" 15:04:05.0") +} + func addPlayTime(grid *gtk.Grid, p *player.PlayerChan) (err error) { - var label *gtk.Label - if label, err = gtk.LabelNew("00:00:00.0"); err != nil { + var btn *gtk.Button + if btn, err = gtk.ButtonNew(); err != nil { return err } - p.AddUpdateHandler(func(_ time.Duration, pos time.Duration, _ player.Meter, _ interface{}) bool { + countdown := false + duration := time.Duration(0) + pos := time.Duration(0) + p.AddUpdateHandler(func(d time.Duration, p time.Duration, _ player.Meter, _ interface{}) bool { glib.IdleAdd(func() { - t := time.Unix(0, 0).UTC().Add(pos) - label.SetText(t.Format("15:04:05.0")) + duration = d + pos = p + btn.SetLabel(getPlayTimeString(duration, pos, countdown)) }) return true }, nil) + btn.SetSizeRequest(150, 40) + btn.SetRelief(gtk.RELIEF_NONE) + btn.SetFocusOnClick(false) + btn.SetLabel(getPlayTimeString(duration, pos, countdown)) + + btn.Connect("clicked", func(_ *gtk.Button) { + countdown = !countdown + btn.SetLabel(getPlayTimeString(duration, pos, countdown)) + }) + var cp *gtk.CssProvider if cp, err = gtk.CssProviderNew(); err != nil { return } - if err = cp.LoadFromData(".label { font-weight: bold; font-size: 15pt; padding: 3px 12px 3px 2px; }"); err != nil { + if err = cp.LoadFromData(".button { font-weight: bold; font-size: 12pt; }"); err != nil { return } var sc *gtk.StyleContext - if sc, err = label.GetStyleContext(); err != nil { + if sc, err = btn.GetStyleContext(); err != nil { return } sc.AddProvider(cp, 600) // TOOD: hardcoded value - grid.Attach(label, 3, 1, 1, 1) + grid.Attach(btn, 3, 1, 1, 1) return } |