Skip to content

Commit

Permalink
Spinbox: fix and test the behaviour on mousewheel
Browse files Browse the repository at this point in the history
Scrolling up should increase the value, not decrease it.

The Qt behaviour was changed in slint-ui#5010
  • Loading branch information
ogoffart authored Apr 4, 2024
1 parent 3121922 commit d1da3ba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/compiler/widgets/common/spinbox-base.slint
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export component SpinBoxBase {
enabled: root.enabled;

scroll-event(event) => {
if (event.delta-y < 0) {
if (event.delta-y > 0) {
root.increment();
return accept;
}

if (event.delta-y > 0) {
if (event.delta-y < 0) {
root.decrement();
return accept;
}
Expand Down
41 changes: 37 additions & 4 deletions tests/cases/widgets/spinbox_basic.slint
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ export component TestCase inherits Window {
forward-focus: box;
out property <bool> spinbox-focused <=> box.has_focus;
callback edited <=> box.edited;
in-out property value <=> box.value;
}

/*
```rust
use slint::platform::Key;
use slint::{LogicalPosition, platform::WindowEvent, platform::Key};
use std::cell::RefCell;
use std::rc::Rc;
let instance = TestCase::new().unwrap();
slint_testing::send_mouse_click(&instance, 5., 5.);
assert!(instance.get_spinbox_focused());
let edits = Rc::new(RefCell::new(Vec::new()));
Expand All @@ -35,11 +34,45 @@ instance.on_edited({
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!(edits.borrow().clone(), vec![40]);
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]);
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]);
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_eq!(&*edits.borrow(), &[]);
edits.borrow_mut().clear();
```
*/

0 comments on commit d1da3ba

Please sign in to comment.