use crate::rendering::{HTMLDrawable, draw_html_render_commands};
use crate::web_functions::primitives::{load_font, wait_for_next_frame};
use cotis::renders::CotisRendererAsync;
use cotis_defaults::element_configs::text_config::TextConfig;
use cotis_utils::font_manager::FontManager;
use cotis_utils::math::Dimensions;
pub type MeasureFunType = fn(&str, &TextConfig) -> Dimensions;
pub type LoopRoutine = Box<dyn FnMut() + Send>;
pub struct HTMLRenderer {
_url: String,
}
impl<HTMLDrawableType: HTMLDrawable> CotisRendererAsync<HTMLDrawableType> for HTMLRenderer {
async fn draw_frame(&mut self, render_commands: impl Iterator<Item = HTMLDrawableType>) {
wait_for_next_frame().await;
draw_html_render_commands(render_commands);
}
}
impl Default for HTMLRenderer {
fn default() -> Self {
Self::new()
}
}
impl HTMLRenderer {
pub fn new() -> Self {
use web_sys::window;
let window = window().expect("no global `window` exists");
let location = window.location();
let origin = location.origin().expect("could not get origin");
Self { _url: origin }
}
pub fn load_font(&mut self, manager: &FontManager<String>, url: &str) {
let id = manager.push_font(url.to_string());
load_font(url, id);
}
pub fn get_custom_element_html(&self, element_id: u64) -> Option<String> {
crate::web_functions::primitives::get_custom_element_html(element_id)
}
pub fn get_custom_element_properties(
&self,
element_id: u64,
selector: Option<&str>,
) -> Option<String> {
crate::web_functions::primitives::get_custom_element_properties(element_id, selector)
}
}