pub struct TestingPlatform<const W: usize = 320, const H: usize = 240, P: PixelFormat = Rgb565> {
pub framebuffer: [[P; W]; H],
pub total_frames_rendered: u32,
/* private fields */
}Expand description
确定性无头测试平台(支持泛型像素格式 P,默认 320x240 Rgb565)。
同时作为 #![no_std] 固定分辨率移动端(MobilePlatform)与
WebAssembly <canvas>(WebPlatform)的统一底层实现。
Fields§
§framebuffer: [[P; W]; H]§total_frames_rendered: u32Implementations§
Source§impl<const W: usize, const H: usize, P: PixelFormat> TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P: PixelFormat> TestingPlatform<W, H, P>
pub const fn new() -> Self
Sourcepub fn send_event(&mut self, event: InputEvent)
pub fn send_event(&mut self, event: InputEvent)
注入一条模拟输入事件。
Sourcepub fn send_click(&mut self, x: i16, y: i16)
pub fn send_click(&mut self, x: i16, y: i16)
模拟在 (x, y) 处按下并抬起完成一次点击。
Sourcepub fn on_pointer_down(&mut self, x: i16, y: i16)
pub fn on_pointer_down(&mut self, x: i16, y: i16)
注入浏览器/桌面 pointerdown 事件。
Sourcepub fn on_pointer_move(&mut self, x: i16, y: i16)
pub fn on_pointer_move(&mut self, x: i16, y: i16)
注入浏览器/桌面 pointermove 事件(自动合并连续移动事件)。
Sourcepub fn on_pointer_up(&mut self, x: i16, y: i16)
pub fn on_pointer_up(&mut self, x: i16, y: i16)
注入浏览器/桌面 pointerup 事件。
Sourcepub fn on_pointer_cancel(&mut self)
pub fn on_pointer_cancel(&mut self)
注入浏览器/桌面 pointercancel 事件。
Sourcepub fn on_key_down(&mut self, key: KeyCode)
pub fn on_key_down(&mut self, key: KeyCode)
注入键盘按下事件。
Sourcepub fn on_popstate_back(&mut self)
pub fn on_popstate_back(&mut self)
注入浏览器 popstate 后退事件。
Sourcepub fn on_touch(&mut self, touch_id: u32, phase: TouchPhase, x: i16, y: i16)
pub fn on_touch(&mut self, touch_id: u32, phase: TouchPhase, x: i16, y: i16)
注入移动端单指/多指触控事件(自动锁定主触控点 primary_touch_id 并合并高频 Moved 事件)。
Sourcepub fn set_orientation(&mut self, orientation: DeviceOrientation)
pub fn set_orientation(&mut self, orientation: DeviceOrientation)
切换移动设备屏幕朝向并同步更新默认异形屏安全区域。
Sourcepub fn set_safe_area(&mut self, insets: SafeAreaInsets)
pub fn set_safe_area(&mut self, insets: SafeAreaInsets)
更新异形屏安全区域内边距。
Sourcepub fn handle_back(&mut self, engine: &mut VeloxEngine) -> bool
pub fn handle_back(&mut self, engine: &mut VeloxEngine) -> bool
触发系统返回导航(Android 返回键 / 边缘右滑返回),返回是否被当前页面消费。
Sourcepub fn last_dirty_regions(&self) -> &[Region]
pub fn last_dirty_regions(&self) -> &[Region]
获取最近一帧合并计算的脏矩形切片(Region 格式)。
Sourcepub fn dirty_rects(&self) -> &[CDirtyRect]
pub fn dirty_rects(&self) -> &[CDirtyRect]
获取最近一帧合并计算的脏矩形切片(FFI 兼容 CDirtyRect 格式)。
Trait Implementations§
Source§impl<const W: usize, const H: usize, P: PixelFormat> Default for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P: PixelFormat> Default for TestingPlatform<W, H, P>
Source§impl<const W: usize, const H: usize, P: PixelFormat> Platform for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P: PixelFormat> Platform for TestingPlatform<W, H, P>
Source§fn duration_since_start(&self) -> Duration
fn duration_since_start(&self) -> Duration
返回自平台启动以来的单调递增时长(桌面端默认由
Instant 提供)。Source§fn step_platform(
&mut self,
engine: &mut VeloxEngine,
dt_ms: u16,
) -> PlatformControlFlow
fn step_platform( &mut self, engine: &mut VeloxEngine, dt_ms: u16, ) -> PlatformControlFlow
单步执行一次平台事件采集、状态更新与按需脏区刷屏,返回下一次循环的
PlatformControlFlow 调度策略。Source§fn run_event_loop(self, engine: VeloxEngine)where
Self: Sized,
fn run_event_loop(self, engine: VeloxEngine)where
Self: Sized,
启动平台主事件循环,接管
VeloxEngine 直至收到 PlatformControlFlow::Exit。Source§impl<const W: usize, const H: usize, P: PixelFormat> PlatformSurface for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P: PixelFormat> PlatformSurface for TestingPlatform<W, H, P>
Source§fn surface_size(&self) -> (i16, i16)
fn surface_size(&self) -> (i16, i16)
获取当前显示表面的逻辑宽高
(width, height)。Source§fn flush_frame_dt(
&mut self,
engine: &mut VeloxEngine,
dt_ms: u16,
) -> FlushReport
fn flush_frame_dt( &mut self, engine: &mut VeloxEngine, dt_ms: u16, ) -> FlushReport
按给定时间步长
dt_ms(毫秒)推进一帧 VeloxEngine 并刷新所有脏区到显示设备。Source§fn flush_frame(&mut self, engine: &mut VeloxEngine) -> FlushReport
fn flush_frame(&mut self, engine: &mut VeloxEngine) -> FlushReport
以默认 60FPS(
16ms)步长执行一帧刷新。Auto Trait Implementations§
impl<const W: usize, const H: usize, P> Forget for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> Freeze for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> Move for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> RefUnwindSafe for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> Send for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> Sync for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> Unpin for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> UnsafeUnpin for TestingPlatform<W, H, P>
impl<const W: usize, const H: usize, P> UnwindSafe for TestingPlatform<W, H, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
当
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
根据
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。