forked from AparokshaUI/adwaita-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdleDemo.swift
48 lines (41 loc) · 1.02 KB
/
IdleDemo.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// IdleDemo.swift
// Adwaita
//
// Created by david-swift on 05.05.24.
//
// swiftlint:disable missing_docs
import Adwaita
struct IdleDemo: View {
@State private var progress = 0.0
@State private var activeProcess = false
let max = 500.0
let delayFactor = 5_000.0
let maxWidth = 300
var view: Body {
ProgressBar(value: progress, total: max)
.vexpand()
.valign(.center)
.frame(maxWidth: maxWidth)
Button("Play") {
activeProcess = true
progress = 0
Task {
Idle(delay: .init(delayFactor / max)) {
progress += 1
let done = progress == max
if done {
activeProcess = false
}
return !done
}
}
}
.padding()
.pill()
.hexpand()
.halign(.center)
.insensitive(activeProcess)
}
}
// swiftlint:enable missing_docs