| 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 | |
| 4 | // issue #177 |
| 5 | |
| 6 | export 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 |
| 38 | auto handle = TestCase::create(); |
| 39 | const TestCase &instance = *handle; |
| 40 | auto vec_model = std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2}); |
| 41 | instance.set_model(vec_model); |
| 42 | instance.on_clicked([vec_model] { vec_model->erase(vec_model->row_count()-1); }); |
| 43 | slint_testing::send_mouse_click(&instance, 95., 5.); |
| 44 | assert_eq(instance.get_model()->row_count(), 1); |
| 45 | assert(instance.get_hover()); |
| 46 | slint_testing::send_mouse_click(&instance, 95., 5.); |
| 47 | assert_eq(instance.get_model()->row_count(), 0); |
| 48 | assert(!instance.get_hover()); |
| 49 | ``` |
| 50 | |
| 51 | ```rust |
| 52 | use slint::Model; |
| 53 | let instance = TestCase::new().unwrap(); |
| 54 | let vec_model = std::rc::Rc::new(slint::VecModel::from(vec![1i32, 2i32])); |
| 55 | instance.set_model(vec_model.clone().into()); |
| 56 | instance.on_clicked(move || { vec_model.remove(vec_model.row_count() - 1); }); |
| 57 | slint_testing::send_mouse_click(&instance, 95., 5.); |
| 58 | assert_eq!(instance.get_model().row_count(), 1); |
| 59 | assert!(instance.get_hover()); |
| 60 | slint_testing::send_mouse_click(&instance, 95., 5.); |
| 61 | assert_eq!(instance.get_model().row_count(), 0); |
| 62 | assert!(!instance.get_hover()); |
| 63 | ``` |
| 64 | |
| 65 | ```js |
| 66 | let model = new slintlib.ArrayModel([1, 2]); |
| 67 | var instance = new slint.TestCase({ |
| 68 | clicked: function() { model.pop(); } |
| 69 | }); |
| 70 | instance.model = model; |
| 71 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
| 72 | assert.equal(instance.model.length, 1); |
| 73 | assert(instance.hover); |
| 74 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
| 75 | assert.equal(instance.model.length, 0); |
| 76 | assert(!instance.hover); |
| 77 | ``` |
| 78 | */ |
| 79 | |