slint/examples/7guis/timer.slint
Florian Blasius 520df46998
Update examples to new syntax (#2067)
* run slint-updater on examples
* manual syntax updates
2023-01-16 12:11:25 +00:00

57 lines
1.7 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
import { LineEdit, Button, Slider, HorizontalBox, VerticalBox } from "std-widgets.slint";
component MainWindow inherits Window {
in-out property <duration> total-time: slider.value * 1s;
in-out property <duration> elapsed-time;
callback tick(duration);
tick(passed-time) => {
root.elapsed-time += passed-time;
root.elapsed-time = min(root.elapsed-time, root.total-time);
}
VerticalBox {
HorizontalBox {
padding-left: 0;
Text { text: "Elapsed Time:"; }
Rectangle {
min-width: 200px;
max-height: 30px;
background: gray;
Rectangle {
x:0;
height: 100%;
width: parent.width * (root.elapsed-time/root.total-time);
background: lightblue;
}
}
}
Text{
text: (root.total-time / 1s) + "s";
}
HorizontalBox {
padding-left: 0;
Text {
text: "Duration:";
vertical-alignment: center;
}
slider := Slider {
maximum: 30s / 1s;
value: 10s / 1s;
changed(new-duration) => {
root.total-time = new-duration * 1s;
root.elapsed-time = min(root.elapsed-time, root.total-time);
}
}
}
Button {
text: "Reset";
clicked => {
root.elapsed-time = 0
}
}
}
}