-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timer widget #67
base: master
Are you sure you want to change the base?
Timer widget #67
Conversation
Support timer configuration by time.Duration formats such as 1h10m15s etc. Fixes pause and resume functionality.
if w.data.IsPaused() { | ||
w.data.Clear() | ||
} else if !w.data.HasDeadline() { | ||
w.currIndex = (w.currIndex + 1) % len(w.times) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method? NextTimer()
?
pausedDuration := time.Now().Sub(w.data.pausedTime) | ||
w.data.startTime = w.data.startTime.Add(pausedDuration) | ||
w.data.pausedTime = time.Time{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method? Resume()
?
w.data.startTime = w.data.startTime.Add(pausedDuration) | ||
w.data.pausedTime = time.Time{} | ||
} else { | ||
w.data.startTime = time.Now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method? StartTimer()
if !w.data.HasDeadline() { | ||
str = Timespan(w.times[w.currIndex]).Format(w.formats[i]) | ||
} else { | ||
remainingDuration := time.Until(w.data.startTime.Add(w.times[w.currIndex])) | ||
if remainingDuration < 0 && !w.underflow { | ||
str = Timespan(w.times[w.currIndex]).Format(w.formats[i]) | ||
w.data.Clear() | ||
} else if remainingDuration < 0 && w.underflow { | ||
fontColor = w.underflowColors[i] | ||
str = Timespan(remainingDuration * -1).Format(w.formats[i]) | ||
} else { | ||
str = Timespan(remainingDuration).Format(w.formats[i]) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be a method(s) .. not really happy about how this turned out. Its a bit hard to read.
ie line 123, this is basically rendering the current timer you can start. Ideally we should be telling the types what to do .. now we are kinda asking them for information on how to generate a string to display. Abit of data jealousy.
This is continuation of #66 with a bit of refactor to support customized layouts as done with the Time widget.
Configuration also uses the time.Duration formats to provide timer configurations. See https://pkg.go.dev/time#ParseDuration