Skip to content

Commit

Permalink
Add test from #6690
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonXLF committed Oct 31, 2024
1 parent 6e0beea commit fbe660a
Showing 1 changed file with 348 additions and 0 deletions.
348 changes: 348 additions & 0 deletions tests/cases/elements/popupwindow_multi.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,348 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// 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();
}
}
Button {
text: "Open two popups";
clicked => {
popup1.show();
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: "close popup1";
clicked => {
result += "C1";
popup1.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 both popups
slint_testing::send_mouse_click(&instance, 380., 10.);
// clicking in P1 doesn nothing
slint_testing::send_mouse_click(&instance, 210., 90.);
assert_eq!(instance.get_result(), "");
// go in the popup1 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());
// clicking in P1
slint_testing::send_mouse_click(&instance, 210., 90.);
assert_eq!(instance.get_result(), "P1");
instance.set_result("".into());
// open P1 combobox
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());
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, 200., 10.);
assert_eq!(instance.get_result(), "");
// open popup1 from popup2
slint_testing::send_mouse_click(&instance, 300., 210. + 40.);
assert_eq!(instance.get_result(), "O1");
instance.set_result("".into());
// open P1 combobox
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(), "");
// but p2 is still open
// Open its combobox
slint_testing::send_mouse_click(&instance, 40., 210.);
// but click outside closes it
slint_testing::send_mouse_click(&instance, 210., 90.);
assert_eq!(instance.get_result(), "");
// "close this" closes p2
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
assert_eq!(instance.get_result(), "C2");
instance.set_result("".into());
slint_testing::send_mouse_click(&instance, 20., 310.);
assert_eq!(instance.get_result(), "Root");
```
```cpp
auto handle = TestCase::create();
TestCase &instance = *handle;
// open both popups
slint_testing::send_mouse_click(&instance, 380., 10.);
// clicking in P1 doesn nothing
slint_testing::send_mouse_click(&instance, 210., 90.);
assert_eq(instance.get_result(), "");
// go in the popup1 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("");
// clicking in P1
slint_testing::send_mouse_click(&instance, 210., 90.);
assert_eq(instance.get_result(), "P1");
instance.set_result("");
// open P1 combobox
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("");
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, 200., 10.);
assert_eq(instance.get_result(), "");
// open popup1 from popup2
slint_testing::send_mouse_click(&instance, 20., 310.);
slint_testing::send_mouse_click(&instance, 300., 210. + 35.);
assert_eq(instance.get_result(), "O1");
instance.set_result("");
// open P1 combobox
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(), "");
// but p2 is still open
// Open its combobox
slint_testing::send_mouse_click(&instance, 40., 210.);
// but click outside closes it
slint_testing::send_mouse_click(&instance, 210., 90.);
assert_eq(instance.get_result(), "");
// "close this" closes p2
slint_testing::send_mouse_click(&instance, 40., 210. + 40.);
assert_eq(instance.get_result(), "C2");
instance.set_result("");
slint_testing::send_mouse_click(&instance, 20., 310.);
assert_eq(instance.get_result(), "Root");
```
*/

0 comments on commit fbe660a

Please sign in to comment.