pub struct HTMLRenderer { /* private fields */ }Expand description
Async HTML/CSS renderer for Cotis applications running in the browser.
Implements CotisRendererAsync and Cotis context traits (see crate::cotis_traits).
Holds the page origin (window.location.origin) for resolving relative asset URLs.
§WASM
Requires a browser environment with a global window object. Construct after
init_wasm() and before starting the async frame loop.
§Example
use cotis_web::renderer::HTMLRenderer;
let mut renderer = HTMLRenderer::new();
// Wire into CotisApp, then compute_frame_async in a loop.Implementations§
Source§impl HTMLRenderer
impl HTMLRenderer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a renderer bound to the current page origin.
Reads window.location.origin (e.g. "https://example.com:8080") for asset URL
resolution.
§Panics
Panics if there is no global window or if location.origin() is unavailable.
Sourcepub fn load_font(&mut self, manager: &FontManager<String>, url: &str)
pub fn load_font(&mut self, manager: &FontManager<String>, url: &str)
Registers a font URL with the browser and assigns it an id in manager.
Pushes url into manager, then calls the JS loadFont helper so CSS
font-family: font{id} (used by text drawables) resolves correctly.
§WASM
Font loading is asynchronous in the browser; allow a frame or two before relying on measured text dimensions.
Sourcepub fn get_custom_element_html(&self, element_id: u64) -> Option<String>
pub fn get_custom_element_html(&self, element_id: u64) -> Option<String>
Returns the innerHTML of the custom host element for the given render command id.
The element id in the DOM is cotis-{element_id}. Returns None if no such element
exists in the current document.
§WASM
Queries the live DOM; call after the frame that created or updated the element.
Sourcepub fn get_custom_element_properties(
&self,
element_id: u64,
selector: Option<&str>,
) -> Option<String>
pub fn get_custom_element_properties( &self, element_id: u64, selector: Option<&str>, ) -> Option<String>
Returns JSON describing properties of a custom host element or a descendant.
Use selector to target a child, e.g. Some(r#"input[name="username"]"#) to read an
input’s value. With None, the JS helper auto-picks the first form-like element or
the host itself.
Parse the returned string with serde_json to access fields like value,
placeholder, checked, etc.
§WASM
Queries the live DOM; call after the frame that created or updated the element.
§Example
let renderer = HTMLRenderer::new();
if let Some(json) = renderer.get_custom_element_properties(42, Some("input")) {
let props: serde_json::Value = serde_json::from_str(&json).unwrap();
let value = props["value"].as_str();
}Trait Implementations§
Source§impl CotisFrameContext for HTMLRenderer
impl CotisFrameContext for HTMLRenderer
Source§fn get_delta_time(&self) -> f32
fn get_delta_time(&self) -> f32
Returns elapsed time since the previous frame, in seconds.
Sourced from JS get_delta_time_ms() (milliseconds) and converted to seconds.
Source§impl<HTMLDrawableType: HTMLDrawable> CotisRendererAsync<HTMLDrawableType> for HTMLRenderer
impl<HTMLDrawableType: HTMLDrawable> CotisRendererAsync<HTMLDrawableType> for HTMLRenderer
Source§async fn draw_frame(
&mut self,
render_commands: impl Iterator<Item = HTMLDrawableType>,
)
async fn draw_frame( &mut self, render_commands: impl Iterator<Item = HTMLDrawableType>, )
Draw one frame: wait for the next animation frame, then update the DOM.
Calls the JS waitForNextFrame helper, then runs each command through
HTMLCanvas and
draw_html_render_commands.
Unused cotis-{id} elements from previous frames are removed in
HTMLCanvas::finish.
§WASM
Requires an initialized DOM root (see bundled renderer.js / init_html_root).
Source§impl CotisWindowContext for HTMLRenderer
impl CotisWindowContext for HTMLRenderer
Source§fn window_dimensions(&self) -> Dimensions
fn window_dimensions(&self) -> Dimensions
Returns the browser viewport size (width, height) in CSS pixels.
Source§impl Default for HTMLRenderer
impl Default for HTMLRenderer
Source§impl MouseProvider for HTMLRenderer
impl MouseProvider for HTMLRenderer
Source§fn get_mouse_position(&self) -> Vector2
fn get_mouse_position(&self) -> Vector2
Source§fn get_mouse_wheel_move_v(&self) -> Vector2
fn get_mouse_wheel_move_v(&self) -> Vector2
Source§impl<M> RenderCompatibleWith<M> for HTMLRenderer
impl<M> RenderCompatibleWith<M> for HTMLRenderer
Source§impl RendererTextMeasuringProvider<TextConfig> for HTMLRenderer
impl RendererTextMeasuringProvider<TextConfig> for HTMLRenderer
Source§fn provide_measurer(&mut self) -> Box<dyn Fn(&str, &TextConfig) -> Dimensions>
fn provide_measurer(&mut self) -> Box<dyn Fn(&str, &TextConfig) -> Dimensions>
Returns a measurer that uses off-screen DOM layout in renderer.js.
Respects TextConfig font id, size, line height, and letter spacing.
Auto Trait Implementations§
impl Freeze for HTMLRenderer
impl RefUnwindSafe for HTMLRenderer
impl Send for HTMLRenderer
impl Sync for HTMLRenderer
impl Unpin for HTMLRenderer
impl UnsafeUnpin for HTMLRenderer
impl UnwindSafe for HTMLRenderer
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
impl<T> CotisRenderContext for Twhere
T: CotisWindowContext + CotisFrameContext,
Source§impl<H, TailTarget, Source, Idx> Embed<RenderTList<H, TailTarget>, There<Idx>> for Sourcewhere
TailTarget: IsRenderList,
Source: Embed<TailTarget, Idx>,
impl<H, TailTarget, Source, Idx> Embed<RenderTList<H, TailTarget>, There<Idx>> for Sourcewhere
TailTarget: IsRenderList,
Source: Embed<TailTarget, Idx>,
Source§fn embed(self) -> RenderTList<H, TailTarget>
fn embed(self) -> RenderTList<H, TailTarget>
self into Target.