const WIDTH: u32 = 600;
const HEIGHT: u32 = 400;
struct RenderState {
pixels: Pixels<'static>,
window: Arc<Window>,
pixmap: Pixmap,
}
impl RenderState {
fn new(event_loop: &ActiveEventLoop) -> Result<Self, Box<dyn Error>> {
let window = Arc::new(
event_loop.create_window(
Window::default_attributes()
.with_inner_size(LogicalSize::new(WIDTH as f64, HEIGHT as f64))
.with_title("Kakoune Client"),
)?,
);
let st = SurfaceTexture::new(
WIDTH,
HEIGHT,
// We need to use unsafe here because otherwise we can't have self-referencial structs
unsafe { std::mem::transmute::<*const Window, &'static Window>(Arc::as_ptr(&window)) },
);
let pixels = Pixels::new(WIDTH, HEIGHT, st)?;
let pixmap = Pixmap::new(WIDTH, HEIGHT).ok_or("Failed to create tiny-skia pixmap")?;
Ok(Self {
pixels,
pixmap,
window,
})
}
}