1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4struct Structure {
5 value: int,
6}
7
8component AlignedValue {
9 in property <int> alignment: 1;
10 in-out property <int> aligned-value;
11 pure function align(value: int) -> int {
12 (value / alignment) * alignment
13 }
14 public function set-value(new-value: int) {
15 aligned-value = align(Math.max(0, new-value));
16 }
17}
18
19export component TestCase inherits Window {
20 in-out property <Structure> range: { value: 42 };
21 checked-range := AlignedValue {
22 aligned-value: range.value;
23 }
24
25 init => {
26 checked-range.set_value(78);
27 }
28
29 out property <bool> test: checked-range.aligned-value == 78;
30}
31
32/*
33```cpp
34auto handle = TestCase::create();
35const TestCase &instance = *handle;
36assert(instance.get_test());
37```
38
39```rust
40let instance = TestCase::new().unwrap();
41assert!(instance.get_test());
42```
43*/
44