mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
parent
2643a327e8
commit
a9f526491a
25 changed files with 599 additions and 14 deletions
|
@ -778,6 +778,57 @@ export component Example inherits Window {
|
|||
}
|
||||
```
|
||||
|
||||
## `Timer`
|
||||
<!-- FIXME: Timer is not really an element so it doesn't really belong in the `Builtin Elements` section. -->
|
||||
|
||||
Timer is not an actual element visible in the tree, therefore it doesn't have the common properties such as `x`, `y`, `width`, `height`, etc.
|
||||
It doesn't take room in a layout and cannot have any children or be inherited from.
|
||||
|
||||
The Timer pseudo-element is used to schedule a callback at a given interval.
|
||||
The timer is only running when the `running` property is set to `true`. To stop or start the timer, simply set that property to `true` or `false`.
|
||||
It can be also set to a binding.
|
||||
When already running, the timer will be restarted if the `interval` property is changed.
|
||||
|
||||
Note that the default value for `running` is `true`, so if you don't specify it, it will be running.
|
||||
|
||||
### Properties
|
||||
|
||||
- **`interval`** (_in_ _duration_): The interval between timer ticks. (default value: `0ms`)
|
||||
- **`running`** (_in_ _bool_): `true` if the timer is running. (default value: `true`)
|
||||
|
||||
### Callbacks
|
||||
|
||||
- **`triggered()`**: Invoked every time the timer ticks (every `interval`)
|
||||
|
||||
### Example
|
||||
|
||||
This example shows a timer that counts down from 10 to 0 every second:
|
||||
|
||||
```slint
|
||||
import { Button } from "std-widgets.slint";
|
||||
export component Example inherits Window {
|
||||
property <int> value: 10;
|
||||
timer := Timer {
|
||||
interval: 1s;
|
||||
running: true;
|
||||
triggered() => {
|
||||
value -= 1;
|
||||
if (value == 0) {
|
||||
self.running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
Text { text: value; }
|
||||
Button {
|
||||
text: "Reset";
|
||||
clicked() => { value = 10; timer.running = true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## `TouchArea`
|
||||
|
||||
Use `TouchArea` to control what happens when the region it covers is touched or interacted with
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue