slint/tests/cases/widgets/scrollview.slint
Joshua Goins e820fe3a34
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, 1.88) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, 1.88) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_test_driver (macos-14) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.88) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / material-components (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
Add new widget test for ScrollView, test the scrolled callback
As brought up in 7d038eb9e2, the bug
I was fixing should really have a test for it - so I added one.
Testing the scrolled callback is a bit odd to handle because not
only does each style have a different scroll handle but it's a bit
dubious when/how many scrolled callback emissions there should be.

I was able to find a sweet spot for both of these problems, and
although the test case is a bit vague it does catch when a style
doesn't emit the callback.
2025-10-08 17:05:49 +02:00

75 lines
2.2 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { ScrollView } from "std-widgets.slint";
export component TestCase inherits Window {
width: 100px;
height: 100px;
box := ScrollView {
viewport-width: 500px;
viewport-height: 500px;
}
callback scrolled <=> box.scrolled;
in-out property <length> viewport-x <=> box.viewport-x;
in-out property <length> viewport-y <=> box.viewport-y;
}
/*
```rust
use slint::{LogicalPosition, platform::WindowEvent};
use std::cell::RefCell;
use std::rc::Rc;
let instance = TestCase::new().unwrap();
let scrolled_emitted = Rc::new(RefCell::new(false));
instance.on_scrolled({
let scrolled_emitted = scrolled_emitted.clone();
move || {
*scrolled_emitted.borrow_mut() = true;
}});
assert_eq!(*scrolled_emitted.borrow(), false);
let position = LogicalPosition::new(15.0, 95.0);
// Scroll horizontally by pressing on the handle
let button = slint::platform::PointerEventButton::Left;
instance.window().dispatch_event(WindowEvent::PointerPressed { position, button });
// then drag it
let position = LogicalPosition::new(50.0, 95.0);
instance.window().dispatch_event(WindowEvent::PointerMoved { position });
instance.window().dispatch_event(WindowEvent::PointerReleased { position, button });
assert_eq!(*scrolled_emitted.borrow(), true);
assert!(instance.get_viewport_x() != 0.0);
assert_eq!(instance.get_viewport_y(), 0.0);
*scrolled_emitted.borrow_mut() = false;
// Scroll vertically by pressing on the handle
let position = LogicalPosition::new(95.0, 15.0);
let button = slint::platform::PointerEventButton::Left;
instance.window().dispatch_event(WindowEvent::PointerPressed { position, button });
// ...then drag it
let position = LogicalPosition::new(95.0, 50.0);
instance.window().dispatch_event(WindowEvent::PointerMoved { position });
instance.window().dispatch_event(WindowEvent::PointerReleased { position, button });
assert_eq!(*scrolled_emitted.borrow(), true);
assert!(instance.get_viewport_x() != 0.0);
assert!(instance.get_viewport_y() != 0.0);
*scrolled_emitted.borrow_mut() = false;
```
*/