Skip to content

Instantly share code, notes, and snippets.

@ALANVF
Last active June 16, 2022 22:59
Show Gist options
  • Save ALANVF/28c7cbd85a143c26dd416dab1c6e5a84 to your computer and use it in GitHub Desktop.
Save ALANVF/28c7cbd85a143c26dd416dab1c6e5a84 to your computer and use it in GitHub Desktop.
Time demo
Red [
Title: "Timer app"
Author: "ALANVF"
Date: 14-Jun-2022
File: %timer.red
Needs: 'View
Purpose: {
Basic timer application
}
]
time: 00:00
rate: 00:00:00.1
running: false
paused: false
monospace: make font! [
name: font-fixed
]
view [
title "Timer"
below center
time-text: text 200 font monospace center "0:00:00.0" on-time [
text: form time: time + rate
time/second: round/to time/second 0.01 ;-- to fix floating-point errors
time-text/text: either time % 1 = 0.0 [ append text ".0" ][ text ]
]
start: button 100 "Start" [
case [
paused [
time-text/rate: rate
start/text: "Pause"
paused: false
]
running [
time-text/rate: none
start/text: "Resume"
paused: true
]
true [
time-text/rate: rate
start/text: "Pause"
reset/text: "Stop"
running: true
]
]
]
reset: button 100 "Reset" [
start/text: "Start"
time-text/rate: none
time: 00:00
paused: false
either running [
running: false
reset/text: "Reset"
][
time-text/text: "0:00:00.0"
]
]
button 100 "Copy to clipboard" [
write-clipboard time-text/text
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment