Last active
August 4, 2020 20:58
-
-
Save Clancey/d74919885fe9d809188399a9b6ba1bc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CounterView : View | |
{ | |
readonly State<int> count = 0; | |
readonly State<int> step = 1; | |
readonly State<bool> timerOn = false; | |
void init() | |
{ | |
count.Value = 1; | |
step.Value = 0; | |
timerOn.Value = false; | |
} | |
[Body] | |
View body ()=> new VStack | |
{ | |
new Text($"{count}"), | |
new Button("Increment",()=> count.Value += step), | |
new Button("Decrement",()=>count.Value -= step), | |
new HStack | |
{ | |
new Text("Timer"), | |
new Toggle(timerOn,(value)=> { | |
timerOn.Value = value; | |
tickTimer(); | |
}) | |
}, | |
new Slider(step.Value,through:10,onEditingChanged: (value) => step.Value = (int)value), | |
new Text(()=> $"Step Size: {step}"), | |
new Button("Reset", ()=> init()) | |
}; | |
async void tickTimer() | |
{ | |
if (!timerOn) | |
return; | |
await Task.Delay(200); | |
count.Value += step; | |
tickTimer(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment