Skip to content

Instantly share code, notes, and snippets.

@Clancey
Last active August 4, 2020 20:58
Show Gist options
  • Save Clancey/d74919885fe9d809188399a9b6ba1bc2 to your computer and use it in GitHub Desktop.
Save Clancey/d74919885fe9d809188399a9b6ba1bc2 to your computer and use it in GitHub Desktop.
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