Files
qbz/crates/vendor/i-slint-core-1.16.1/tests.rs
T
vicrodh 7401d2c3fd fix(text): always draw the first line under overflow: elide
Vendor i-slint-core 1.16.1 with a one-rule patch in sharedparley's
line culling: with overflow: elide, every line whose bottom edge
exceeded max_height was dropped — INCLUDING the first one, eliding the
text to literally nothing. CJK fallback fonts report line metrics
taller than snug fixed-height boxes (Hiragino at 14px measures ~21px
inside TrackRow's 20px title line), so on macOS every CJK track title
rendered blank while Latin titles fit; Linux survived because Noto's
metrics fit the box. Root-caused with a headless render matrix on the
Mac Mini: the verbatim TrackRow structure reproduced the blank title,
removing elide rendered it, and the patched core renders all variants.
The first line still receives the ellipsis treatment as the last
visible line.

This is the real #543 mechanism. The earlier femtovg render_glyph
retry (3a1c367d) addressed a different, hypothesized layer and stays
as harmless defense in depth.

Fixes #543

cc
2026-07-05 18:53:02 -06:00

150 lines
5.3 KiB
Rust

// 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
//! Functions useful for testing
#![warn(missing_docs)]
#![allow(unsafe_code)]
use crate::api::LogicalPosition;
use crate::input::key_codes::Key;
use crate::platform::WindowEvent;
/// Slint animations do not use real time, but use a mocked time.
/// Normally, the event loop update the time of the animation using
/// real time, but in tests, it is more convenient to use the fake time.
/// This function will add some milliseconds to the fake time
#[unsafe(no_mangle)]
pub extern "C" fn slint_mock_elapsed_time(time_in_ms: u64) {
let tick = crate::animations::CURRENT_ANIMATION_DRIVER.with(|driver| {
let mut tick = driver.current_tick();
tick += core::time::Duration::from_millis(time_in_ms);
driver.update_animations(tick);
tick
});
crate::timers::TimerList::maybe_activate_timers(tick);
crate::properties::ChangeTracker::run_change_handlers();
}
/// Return the current mocked time.
#[unsafe(no_mangle)]
pub extern "C" fn slint_get_mocked_time() -> u64 {
crate::animations::CURRENT_ANIMATION_DRIVER.with(|driver| driver.current_tick()).as_millis()
}
/// Simulate a click on a position within the component and releasing after some time.
/// The time until the release is hardcoded to 50ms
#[unsafe(no_mangle)]
pub extern "C" fn slint_send_mouse_click(
x: f32,
y: f32,
window_adapter: &crate::window::WindowAdapterRc,
) {
let position = LogicalPosition::new(x, y);
let button = crate::items::PointerEventButton::Left;
window_adapter.window().dispatch_event(WindowEvent::PointerMoved { position });
window_adapter.window().dispatch_event(WindowEvent::PointerPressed { position, button });
slint_mock_elapsed_time(50);
window_adapter.window().dispatch_event(WindowEvent::PointerReleased { position, button });
}
/// Simulate a single key event with the given text (pressed or released).
///
/// Unlike [`slint_send_keyboard_char`], this dispatches a single [`WindowEvent`]
/// with the complete text. This is important for multi-codepoint grapheme clusters
/// (e.g. NFD-encoded `é` = `e` + `\u{0301}`).
#[unsafe(no_mangle)]
pub extern "C" fn slint_send_keyboard_key_text(
text: &crate::SharedString,
pressed: bool,
window_adapter: &crate::window::WindowAdapterRc,
) {
window_adapter.window().dispatch_event(if pressed {
WindowEvent::KeyPressed { text: text.clone() }
} else {
WindowEvent::KeyReleased { text: text.clone() }
})
}
/// Simulate a character input event (pressed or released).
///
/// Each character in the string is dispatched as a separate [`WindowEvent`].
/// This is useful for modifier keys where each special character code
/// represents an independent key press.
#[unsafe(no_mangle)]
pub extern "C" fn slint_send_keyboard_char(
string: &crate::SharedString,
pressed: bool,
window_adapter: &crate::window::WindowAdapterRc,
) {
for ch in string.chars() {
slint_send_keyboard_key_text(&ch.into(), pressed, window_adapter);
}
}
/// Simulate a character input event.
#[unsafe(no_mangle)]
pub extern "C" fn send_keyboard_string_sequence(
sequence: &crate::SharedString,
window_adapter: &crate::window::WindowAdapterRc,
) {
for ch in sequence.chars() {
if ch.is_ascii_uppercase() {
window_adapter
.window()
.dispatch_event(WindowEvent::KeyPressed { text: Key::Shift.into() });
}
let text: crate::SharedString = ch.into();
window_adapter.window().dispatch_event(WindowEvent::KeyPressed { text: text.clone() });
window_adapter.window().dispatch_event(WindowEvent::KeyReleased { text });
if ch.is_ascii_uppercase() {
window_adapter
.window()
.dispatch_event(WindowEvent::KeyReleased { text: Key::Shift.into() });
}
}
}
/// implementation details for debug_log()
#[doc(hidden)]
pub fn debug_log_impl(args: core::fmt::Arguments) {
crate::context::GLOBAL_CONTEXT.with(|p| match p.get() {
Some(ctx) => ctx.platform().debug_log(args),
None => default_debug_log(args),
});
}
#[doc(hidden)]
pub fn default_debug_log(_arguments: core::fmt::Arguments) {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
use wasm_bindgen::prelude::*;
use std::string::ToString;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
pub fn log(s: &str);
}
log(&_arguments.to_string());
} else if #[cfg(feature = "std")] {
use std::io::Write;
// We were seeing intermittent, albeit very rare, crashes due to `eprintln` panicking
// if the write to stderr fails. Since this is just for debug printing, it's safe
// to silently drop this if we can't write (since it wouldn't be written to stderr
// anyway)
let _ = writeln!(std::io::stderr(), "{_arguments}");
}
}
}
#[macro_export]
/// This macro allows producing debug output that will appear on stderr in regular builds
/// and in the console log for wasm builds.
macro_rules! debug_log {
($($t:tt)*) => ($crate::tests::debug_log_impl(format_args!($($t)*)))
}