use fenestra_core::{App, InputEvent, KeyInput, Theme};
use image::RgbaImage;
#[derive(Debug, Clone, PartialEq)]
pub enum SyntheticEvent {
MouseMove {
x: f32,
y: f32,
},
MouseDown,
MouseUp,
RightDown,
RightUp,
FileDrop(std::path::PathBuf),
Key(KeyInput),
Text(String),
Wheel {
dy: f32,
},
Tab,
ShiftTab,
}
impl From<&SyntheticEvent> for InputEvent {
fn from(ev: &SyntheticEvent) -> Self {
match ev {
SyntheticEvent::MouseMove { x, y } => Self::PointerMove { x: *x, y: *y },
SyntheticEvent::MouseDown => Self::PointerDown,
SyntheticEvent::MouseUp => Self::PointerUp,
SyntheticEvent::RightDown => Self::RightDown,
SyntheticEvent::RightUp => Self::RightUp,
SyntheticEvent::FileDrop(p) => Self::FileDrop(p.clone()),
SyntheticEvent::Key(k) => Self::Key(*k),
SyntheticEvent::Text(s) => Self::Text(s.clone()),
SyntheticEvent::Wheel { dy } => Self::Wheel { dy: *dy },
SyntheticEvent::Tab => Self::Tab,
SyntheticEvent::ShiftTab => Self::ShiftTab,
}
}
}
pub fn render_app<A: App>(
app: &mut A,
events: &[SyntheticEvent],
size: (u32, u32),
theme: &Theme,
) -> RgbaImage
where
A::Msg: Send,
{
let mut harness = crate::Harness::new(&mut *app, theme.clone(), size);
for ev in events {
harness.input(ev.into());
}
harness.render()
}