// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 // FIXME: Ignore the SpinBox test with the Qt style because it doesn't support editing (#4690) //ignore: style-qt import { SpinBox } from "std-widgets.slint"; export component TestCase inherits Window { width: 100px; height: 100px; box := SpinBox { } forward-focus: box; out property spinbox-focused <=> box.has_focus; callback edited <=> box.edited; in-out property value <=> box.value; in property step-size <=> box.step-size; } /* ```rust use slint::{LogicalPosition, platform::WindowEvent, platform::Key}; use std::cell::RefCell; use std::rc::Rc; use i_slint_backend_testing::mock_elapsed_time; let instance = TestCase::new().unwrap(); let edits = Rc::new(RefCell::new(Vec::new())); instance.on_edited({ let edits = edits.clone(); move |val| { edits.borrow_mut().push(val); }}); assert_eq!(instance.get_value(), 0); slint_testing::send_mouse_click(&instance, 5., 5.); assert!(instance.get_spinbox_focused()); slint_testing::send_keyboard_char(&instance, '4', true); slint_testing::send_keyboard_char(&instance, Key::Return.into(), true); assert_eq!(instance.get_value(), 40); assert_eq!(&*edits.borrow(), &[40]); edits.borrow_mut().clear(); // This position happens to work with all styles let position = LogicalPosition::new(40.0, 50.0); // scroll up instance.window().dispatch_event(WindowEvent::PointerScrolled { position , delta_x: 0.0, delta_y: 50.0 }); assert_eq!(instance.get_value(), 41); assert_eq!(&*edits.borrow(), &[41_i32]); edits.borrow_mut().clear(); // scroll down instance.window().dispatch_event(WindowEvent::PointerScrolled { position , delta_x: 0.0, delta_y: -10.0 }); assert_eq!(instance.get_value(), 40); assert_eq!(&*edits.borrow(), &[40_i32]); edits.borrow_mut().clear(); // step size instance.set_step_size(2); instance.window().dispatch_event(WindowEvent::PointerScrolled { position , delta_x: 0.0, delta_y: 50.0 }); assert_eq!(instance.get_value(), 42); assert_eq!(&*edits.borrow(), &[42_i32]); edits.borrow_mut().clear(); instance.window().dispatch_event(WindowEvent::PointerScrolled { position , delta_x: 0.0, delta_y: -10.0 }); assert_eq!(instance.get_value(), 40); assert_eq!(&*edits.borrow(), &[40_i32]); edits.borrow_mut().clear(); instance.set_value(0); // scroll down should do nothing when the value is 0 instance.window().dispatch_event(WindowEvent::PointerScrolled { position , delta_x: 0.0, delta_y: -10.0 }); assert_eq!(instance.get_value(), 0); assert!(edits.borrow().is_empty()); edits.borrow_mut().clear(); instance.set_value(30); mock_elapsed_time(500); let mut spinbox_search = slint_testing::ElementHandle::find_by_element_id(&instance, "TestCase::box"); let spinbox = spinbox_search.next().unwrap(); assert_eq!(spinbox.accessible_value().unwrap(), "30"); edits.borrow_mut().clear(); ``` */