add laps
This commit is contained in:
41
main.go
41
main.go
@@ -3,6 +3,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
@@ -17,6 +18,7 @@ func main() {
|
|||||||
var timer time.Duration
|
var timer time.Duration
|
||||||
var ticking bool = false
|
var ticking bool = false
|
||||||
var status string = "WORK TIME"
|
var status string = "WORK TIME"
|
||||||
|
var laps int = 0
|
||||||
|
|
||||||
// TODO: GET DEFAULT WORK AND BREAK TIMES FROM FILESYSTEM
|
// TODO: GET DEFAULT WORK AND BREAK TIMES FROM FILESYSTEM
|
||||||
var defaultWorkTime string = "25m"
|
var defaultWorkTime string = "25m"
|
||||||
@@ -35,9 +37,12 @@ func main() {
|
|||||||
breakEntry := widget.NewEntry()
|
breakEntry := widget.NewEntry()
|
||||||
breakEntry.SetText(defaultBreakTime)
|
breakEntry.SetText(defaultBreakTime)
|
||||||
breakEntry.TextStyle.Monospace = true
|
breakEntry.TextStyle.Monospace = true
|
||||||
|
|
||||||
breakEntry.Refresh()
|
breakEntry.Refresh()
|
||||||
|
|
||||||
|
lapsLabel := widget.NewLabel("0 laps")
|
||||||
|
lapsLabel.TextStyle.Bold = true
|
||||||
|
lapsLabel.Alignment = fyne.TextAlignCenter
|
||||||
|
|
||||||
var beginButton *widget.Button
|
var beginButton *widget.Button
|
||||||
beginButton = widget.NewButtonWithIcon("Start", theme.Icon(theme.IconNameMediaPlay), func() {
|
beginButton = widget.NewButtonWithIcon("Start", theme.Icon(theme.IconNameMediaPlay), func() {
|
||||||
go func() {
|
go func() {
|
||||||
@@ -79,11 +84,15 @@ func main() {
|
|||||||
for ticking {
|
for ticking {
|
||||||
cur := time.Since(timeStarted)
|
cur := time.Since(timeStarted)
|
||||||
if status == "WORK TIME" {
|
if status == "WORK TIME" {
|
||||||
workEntry.Disable()
|
fyne.Do(func() {
|
||||||
workEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String())
|
workEntry.Disable()
|
||||||
|
workEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String())
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
breakEntry.Disable()
|
fyne.Do(func() {
|
||||||
breakEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String())
|
breakEntry.Disable()
|
||||||
|
breakEntry.SetText((cur.Round(time.Second) - timer.Round(time.Second)).Abs().String())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if cur >= timer {
|
if cur >= timer {
|
||||||
@@ -107,6 +116,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
timer = timer + cur
|
timer = timer + cur
|
||||||
w.SetTitle(status)
|
w.SetTitle(status)
|
||||||
|
laps++
|
||||||
|
lapsLabel.SetText(fmt.Sprintf("%d laps", laps))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
@@ -130,14 +141,20 @@ func main() {
|
|||||||
|
|
||||||
beginButton.Importance = widget.HighImportance
|
beginButton.Importance = widget.HighImportance
|
||||||
|
|
||||||
w.SetContent(container.NewGridWithColumns(3, workEntry, breakEntry, container.NewVBox(beginButton, widget.NewButtonWithIcon("Skip", theme.Icon(theme.IconNameMediaSkipNext), func() {
|
|
||||||
if status == "WORK TIME" {
|
w.SetContent(container.NewVBox(container.NewGridWithColumns(3, workEntry, breakEntry, container.NewVBox(beginButton, widget.NewButtonWithIcon("Skip", theme.Icon(theme.IconNameMediaSkipNext), func() {
|
||||||
status = "BREAK TIME"
|
if !ticking {
|
||||||
} else {
|
if status == "WORK TIME" {
|
||||||
status = "WORK TIME"
|
status = "BREAK TIME"
|
||||||
|
} else {
|
||||||
|
status = "WORK TIME"
|
||||||
|
laps++
|
||||||
|
lapsLabel.SetText(fmt.Sprintf("%d laps", laps))
|
||||||
|
lapsLabel.Refresh()
|
||||||
|
}
|
||||||
|
w.SetTitle(status)
|
||||||
}
|
}
|
||||||
w.SetTitle(status)
|
}))), lapsLabel))
|
||||||
}))))
|
|
||||||
menu := fyne.NewMainMenu(fyne.NewMenu("root"), fyne.NewMenu("help", fyne.NewMenuItem("valid time arguments", func() {
|
menu := fyne.NewMainMenu(fyne.NewMenu("root"), fyne.NewMenu("help", fyne.NewMenuItem("valid time arguments", func() {
|
||||||
neww := fyne.CurrentApp().NewWindow("Help")
|
neww := fyne.CurrentApp().NewWindow("Help")
|
||||||
neww.Resize(fyne.NewSize(500, 500))
|
neww.Resize(fyne.NewSize(500, 500))
|
||||||
|
|||||||
Reference in New Issue
Block a user