mirror of
https://github.com/slint-ui/slint.git
synced 2025-12-23 09:19:32 +00:00
Some checks are pending
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.82) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.82) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.82) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
Fixes #8723
128 lines
3 KiB
Text
128 lines
3 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
|
|
component BackgroundExpr inherits Rectangle {
|
|
in property <bool> cond;
|
|
// conversion from color to brush do a Cast expression and this should work even when there is a return
|
|
background: {
|
|
if (cond) {
|
|
return blue;
|
|
}
|
|
red
|
|
}
|
|
}
|
|
component BackgroundExpr2 inherits Rectangle {
|
|
in property <int> val;
|
|
in property <bool> cond1;
|
|
pure callback foo();
|
|
background: {
|
|
if (val > 20) {
|
|
if (val > 50) {
|
|
return green;
|
|
} else if val > 40 {
|
|
return yellow;
|
|
} else {
|
|
return blue;
|
|
};
|
|
return black;
|
|
}
|
|
if val > 10 {
|
|
return pink;
|
|
} else {
|
|
foo();
|
|
}
|
|
if val > 1 {
|
|
red
|
|
} else {
|
|
orange
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
export global Issue8485 {
|
|
|
|
pure public function format_nullable_duration( has-value: bool, precision: int) -> string {
|
|
if has-value {
|
|
return "";
|
|
} else {
|
|
if precision == 1 {
|
|
return "aaa";
|
|
}
|
|
if precision == 2 {
|
|
return "bbb";
|
|
}
|
|
return "-";
|
|
}
|
|
}
|
|
}
|
|
|
|
export global Issue8723 {
|
|
pure callback key-pressed(KeyEvent) -> EventResult;
|
|
key-pressed(event) => {
|
|
if (true) {
|
|
if (false) {
|
|
return accept;
|
|
}
|
|
return accept;
|
|
}
|
|
if (event.text == Key.LeftArrow) {
|
|
return accept;
|
|
}
|
|
return reject;
|
|
}
|
|
|
|
public pure function xxx(cond1: bool, cond2: bool, cond3: bool) -> string {
|
|
if (cond1) {
|
|
if (cond2) {
|
|
return "A";
|
|
}
|
|
return "B";
|
|
}
|
|
if (cond3) {
|
|
return "C";
|
|
}
|
|
return "D";
|
|
}
|
|
|
|
out property <bool> test: xxx(true, true, true) == "A" && xxx(true, false, true) == "B" && xxx(false, true, true) == "C" && xxx(false, false, false) == "D";
|
|
|
|
}
|
|
|
|
|
|
export component TestCase {
|
|
|
|
bkg1 := BackgroundExpr { cond: true; }
|
|
bkg2 := BackgroundExpr { cond: false; }
|
|
bkg3 := BackgroundExpr2 { val: 0; }
|
|
bkg4 := BackgroundExpr2 { val: 11; }
|
|
bkg5 := BackgroundExpr2 { val: 21; }
|
|
|
|
|
|
out property <bool> test:
|
|
{
|
|
return bkg1.background == Colors.blue && bkg2.background == Colors.red
|
|
&& bkg3.background == Colors.orange && bkg4.background == Colors.pink && bkg5.background == Colors.blue
|
|
&& Issue8485.format_nullable_duration(false, 2) == "bbb"
|
|
&& Issue8723.key-pressed({text: Key.LeftArrow}) == EventResult.accept && Issue8723.test;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
```cpp
|
|
auto handle = TestCase::create();
|
|
const TestCase &instance = *handle;
|
|
assert(instance.get_test());
|
|
```
|
|
|
|
```rust
|
|
let instance = TestCase::new().unwrap();
|
|
assert!(instance.get_test());
|
|
```
|
|
|
|
*/
|