use crate::{Result, gfx};
use wgame_input::CanvasInput;
pub trait WindowHost {
type Frame<'a>: ContentFrame
where
Self: 'a;
fn graphics(&self) -> &gfx::Graphics;
fn wait_for_update(
&mut self,
_timeout: Option<std::time::Duration>,
) -> impl Future<Output = ()> {
async {}
}
fn next_frame(&mut self) -> impl Future<Output = Result<Option<Self::Frame<'_>>>>;
}
pub trait ContentFrame: gfx::Target {
fn visible(&self) -> bool {
true
}
fn input(&self) -> &CanvasInput;
fn scale_factor(&self) -> f64;
fn resized(&self) -> Option<(u32, u32)>;
fn logical_size(&self) -> (f64, f64) {
let (width, height) = self.size();
(
width as f64 / self.scale_factor(),
height as f64 / self.scale_factor(),
)
}
fn logical_camera(&mut self) -> gfx::Camera {
let (width, height) = self.logical_size();
gfx::Camera::new(
self.state(),
glam::camera::lh::proj::directx::orthographic(
0.0,
width as f32,
height as f32,
0.0,
-1.0,
1.0,
),
)
}
fn present(self);
fn discard(self);
}