1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4// issue #177
5
6export TestCase := Window {
7 width: 100px;
8 height: 100px;
9
10 callback clicked;
11 clicked => { debug("Hello"); model= []; }
12 property <bool> hover: under.has-hover;
13 property<[int]> model: [1];
14 VerticalLayout {
15 under := TouchArea {
16 HorizontalLayout {
17 for value in model: TouchArea {
18 horizontal-stretch: 5;
19 vertical-stretch: 5;
20 clicked => { root.clicked(); }
21 Rectangle { background: blue; }
22 }
23 }
24 }
25 Rectangle {
26 horizontal-stretch: 0;
27 vertical-stretch: 0;
28 background: yellow;
29 }
30 }
31
32
33}
34
35/*
36
37```cpp
38auto handle = TestCase::create();
39const TestCase &instance = *handle;
40auto vec_model = std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2});
41instance.set_model(vec_model);
42instance.on_clicked([vec_model] { vec_model->erase(vec_model->row_count()-1); });
43slint_testing::send_mouse_click(&instance, 95., 5.);
44assert_eq(instance.get_model()->row_count(), 1);
45assert(instance.get_hover());
46slint_testing::send_mouse_click(&instance, 95., 5.);
47assert_eq(instance.get_model()->row_count(), 0);
48assert(!instance.get_hover());
49```
50
51```rust
52use slint::Model;
53let instance = TestCase::new().unwrap();
54let vec_model = std::rc::Rc::new(slint::VecModel::from(vec![1i32, 2i32]));
55instance.set_model(vec_model.clone().into());
56instance.on_clicked(move || { vec_model.remove(vec_model.row_count() - 1); });
57slint_testing::send_mouse_click(&instance, 95., 5.);
58assert_eq!(instance.get_model().row_count(), 1);
59assert!(instance.get_hover());
60slint_testing::send_mouse_click(&instance, 95., 5.);
61assert_eq!(instance.get_model().row_count(), 0);
62assert!(!instance.get_hover());
63```
64
65```js
66let model = new slintlib.ArrayModel([1, 2]);
67var instance = new slint.TestCase({
68 clicked: function() { model.pop(); }
69});
70instance.model = model;
71slintlib.private_api.send_mouse_click(instance, 5., 5.);
72assert.equal(instance.model.length, 1);
73assert(instance.hover);
74slintlib.private_api.send_mouse_click(instance, 5., 5.);
75assert.equal(instance.model.length, 0);
76assert(!instance.hover);
77```
78*/
79