mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-28 18:52:16 +00:00
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
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
CI / build_and_test (ubuntu-22.04, nightly) (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 (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.85) (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 / ffi_32bit_build (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 / docs (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 #8891
385 lines
10 KiB
Text
385 lines
10 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
|
|
|
|
import { Button } from "std-widgets.slint";
|
|
|
|
|
|
|
|
// reimplemtns ComboBox so it doesn't depend on the style
|
|
// (taken from the printerdemo)
|
|
export component ComboBox inherits Rectangle {
|
|
in-out property <string> value: "aaaaaa";
|
|
in property <[string]> model: ["aaaaaa", "bbbbbb", "cccccc"];
|
|
callback selected(string);
|
|
border-radius: 3px;
|
|
border-width: 2px;
|
|
border-color: yellow;
|
|
height: 35px;
|
|
min-width: label.x + label.width + i.width;
|
|
|
|
label := Text {
|
|
vertical-alignment: center;
|
|
horizontal-alignment: left;
|
|
text <=> root.value;
|
|
height: 100%;
|
|
x: 12px;
|
|
}
|
|
|
|
i := Text {
|
|
width: self.preferred-width;
|
|
x: parent.width - self.width - 5px;
|
|
text: "▼";
|
|
}
|
|
|
|
TouchArea {
|
|
clicked => { popup.show(); }
|
|
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
popup := PopupWindow {
|
|
x:0;
|
|
y: root.height;
|
|
width: root.width;
|
|
|
|
Rectangle {
|
|
background: #eee;
|
|
border-radius: 3px;
|
|
border-width: 2px;
|
|
border-color: yellow;
|
|
}
|
|
|
|
VerticalLayout {
|
|
spacing: 6px;
|
|
padding: 3px;
|
|
|
|
for value in root.model: Rectangle {
|
|
border-radius: 3px;
|
|
background: item-area.has-hover ? #eef : #fff;
|
|
height: 25px;
|
|
|
|
HorizontalLayout {
|
|
Text {
|
|
horizontal-alignment: center;
|
|
vertical-alignment: center;
|
|
text: value;
|
|
color: black;
|
|
}
|
|
}
|
|
|
|
item-area := TouchArea {
|
|
clicked => {
|
|
root.value = value;
|
|
root.selected(value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export component TestCase inherits Window {
|
|
width: 400px;
|
|
height: 400px;
|
|
|
|
in-out property <string> result;
|
|
|
|
TouchArea {
|
|
clicked => { result += "Root"; }
|
|
}
|
|
|
|
|
|
VerticalLayout {
|
|
alignment: start;
|
|
HorizontalLayout {
|
|
Button {
|
|
text: "Open Popup1";
|
|
clicked => {
|
|
popup1.show();
|
|
}
|
|
}
|
|
Button {
|
|
text: "Open Popup2";
|
|
clicked => {
|
|
popup2.show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
popup1 := PopupWindow {
|
|
x: 200px; y: 50px;
|
|
Rectangle {
|
|
border-width: 1px;
|
|
border-color: green;
|
|
background: red;
|
|
}
|
|
VerticalLayout {
|
|
padding: 3px;
|
|
ComboBox {
|
|
model: ["First", "Second", "Third"];
|
|
selected(value) => {
|
|
result += value;
|
|
}
|
|
}
|
|
TouchArea {
|
|
height: 20px;
|
|
clicked => {
|
|
result += "P1";
|
|
}
|
|
}
|
|
}
|
|
close-policy: close-on-click-outside;
|
|
}
|
|
|
|
popup2 := PopupWindow {
|
|
x: 20px; y: 200px;
|
|
width: 350px;
|
|
Rectangle {
|
|
border-width: 1px;
|
|
border-color: pink;
|
|
background: orange;
|
|
}
|
|
|
|
VerticalLayout {
|
|
padding: 3px;
|
|
ComboBox {
|
|
model: ["Aaaa", "Bbbb", "Cccc"];
|
|
selected(value) => {
|
|
result += value;
|
|
}
|
|
}
|
|
|
|
HorizontalLayout {
|
|
Button {
|
|
text: "close this";
|
|
clicked => {
|
|
result += "C2";
|
|
popup2.close();
|
|
}
|
|
}
|
|
|
|
Button {
|
|
text: "open popup1";
|
|
clicked => {
|
|
result += "O1";
|
|
popup1.show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
close-policy: no-auto-close;
|
|
}
|
|
}
|
|
/*
|
|
|
|
```rust
|
|
#[allow(unused)]
|
|
use slint::{platform::WindowEvent, platform::PointerEventButton, LogicalPosition};
|
|
let instance = TestCase::new().unwrap();
|
|
|
|
// open popup1
|
|
slint_testing::send_mouse_click(&instance, 10., 10.);
|
|
|
|
// check P1 is open
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq!(instance.get_result(), "P1");
|
|
instance.set_result("".into());
|
|
|
|
// click outside
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq!(instance.get_result(), "");
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq!(instance.get_result(), "Root");
|
|
instance.set_result("".into());
|
|
|
|
// open popup2
|
|
slint_testing::send_mouse_click(&instance, 210., 10.);
|
|
// go in the popup2 combobox
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
|
|
assert_eq!(instance.get_result(), "Aaaa");
|
|
instance.set_result("".into());
|
|
|
|
// "close this"
|
|
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
|
|
assert_eq!(instance.get_result(), "C2");
|
|
instance.set_result("".into());
|
|
|
|
// open popup1
|
|
slint_testing::send_mouse_click(&instance, 10., 10.);
|
|
|
|
// open P1 combobox and select first
|
|
slint_testing::send_mouse_click(&instance, 210., 60.);
|
|
slint_testing::send_mouse_click(&instance, 210., 60. + 40.);
|
|
assert_eq!(instance.get_result(), "First");
|
|
instance.set_result("".into());
|
|
|
|
// open it again
|
|
slint_testing::send_mouse_click(&instance, 210., 60.);
|
|
|
|
// click outside closes the combobox
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq!(instance.get_result(), "");
|
|
|
|
// but P1 is still open
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq!(instance.get_result(), "P1");
|
|
instance.set_result("".into());
|
|
|
|
// click outside closes P1
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq!(instance.get_result(), "");
|
|
|
|
// open popup2
|
|
slint_testing::send_mouse_click(&instance, 210., 10.);
|
|
assert_eq!(instance.get_result(), "");
|
|
|
|
// open its combobox
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
|
|
// click outside closes it
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq!(instance.get_result(), "");
|
|
|
|
// but P2 is still open, so open its combobox again
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
|
|
assert_eq!(instance.get_result(), "Aaaa");
|
|
instance.set_result("".into());
|
|
|
|
// open popup1 from popup2
|
|
slint_testing::send_mouse_click(&instance, 300., 210. + 40.);
|
|
assert_eq!(instance.get_result(), "O1");
|
|
instance.set_result("".into());
|
|
|
|
// check P1 is open
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq!(instance.get_result(), "P1");
|
|
instance.set_result("".into());
|
|
|
|
// by opening P1, P2 should be automatically closed
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
assert_eq!(instance.get_result(), "");
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
assert_eq!(instance.get_result(), "Root");
|
|
instance.set_result("".into());
|
|
|
|
// open popup1
|
|
slint_testing::send_mouse_click(&instance, 10., 10.);
|
|
|
|
// close popup1 by esc
|
|
slint_testing::send_keyboard_string_sequence(&instance, "\u{001b}");
|
|
|
|
// check P1 is closed
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq!(instance.get_result(), "Root");
|
|
instance.set_result("".into());
|
|
```
|
|
|
|
```cpp
|
|
auto handle = TestCase::create();
|
|
TestCase &instance = *handle;
|
|
|
|
// open popup1
|
|
slint_testing::send_mouse_click(&instance, 10., 10.);
|
|
|
|
// check P1 is open
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq(instance.get_result(), "P1");
|
|
instance.set_result("");
|
|
|
|
// click outside
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq(instance.get_result(), "");
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq(instance.get_result(), "Root");
|
|
instance.set_result("");
|
|
|
|
// open popup2
|
|
slint_testing::send_mouse_click(&instance, 210., 10.);
|
|
// go in the popup2 combobox
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
|
|
assert_eq(instance.get_result(), "Aaaa");
|
|
instance.set_result("");
|
|
|
|
// "close this"
|
|
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
|
|
assert_eq(instance.get_result(), "C2");
|
|
instance.set_result("");
|
|
|
|
// open popup1
|
|
slint_testing::send_mouse_click(&instance, 10., 10.);
|
|
|
|
// open P1 combobox and select first
|
|
slint_testing::send_mouse_click(&instance, 210., 60.);
|
|
slint_testing::send_mouse_click(&instance, 210., 60. + 40.);
|
|
assert_eq(instance.get_result(), "First");
|
|
instance.set_result("");
|
|
|
|
// open it again
|
|
slint_testing::send_mouse_click(&instance, 210., 60.);
|
|
|
|
// click outside closes the combobox
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq(instance.get_result(), "");
|
|
|
|
// but P1 is still open
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq(instance.get_result(), "P1");
|
|
instance.set_result("");
|
|
|
|
// click outside closes P1
|
|
slint_testing::send_mouse_click(&instance, 20., 310.);
|
|
assert_eq(instance.get_result(), "");
|
|
|
|
// open popup2
|
|
slint_testing::send_mouse_click(&instance, 210., 10.);
|
|
assert_eq(instance.get_result(), "");
|
|
|
|
// open its combobox
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
|
|
// click outside closes it
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq(instance.get_result(), "");
|
|
|
|
// but P2 is still open, so open its combobox again
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
|
|
assert_eq(instance.get_result(), "Aaaa");
|
|
instance.set_result("");
|
|
|
|
// open popup1 from popup2
|
|
slint_testing::send_mouse_click(&instance, 300., 210. + 40.);
|
|
assert_eq(instance.get_result(), "O1");
|
|
instance.set_result("");
|
|
|
|
// check P1 is open
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq(instance.get_result(), "P1");
|
|
instance.set_result("");
|
|
|
|
// by opening P1, P2 should be automatically closed
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
assert_eq(instance.get_result(), "");
|
|
slint_testing::send_mouse_click(&instance, 40., 210.);
|
|
assert_eq(instance.get_result(), "Root");
|
|
instance.set_result("");
|
|
|
|
// open popup1
|
|
slint_testing::send_mouse_click(&instance, 10., 10.);
|
|
|
|
// close popup1 by esc
|
|
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::Escape);
|
|
|
|
// check P1 is closed
|
|
slint_testing::send_mouse_click(&instance, 210., 90.);
|
|
assert_eq(instance.get_result(), "Root");
|
|
instance.set_result("");
|
|
```
|
|
|
|
*/
|