Skip to main content

HTMLRenderer

Struct HTMLRenderer 

Source
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

Source

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.

Source

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.

Source

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.

Source

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

Source§

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

Source§

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

Source§

fn window_dimensions(&self) -> Dimensions

Returns the browser viewport size (width, height) in CSS pixels.

Source§

impl Default for HTMLRenderer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl MouseProvider for HTMLRenderer

Source§

fn get_mouse_position(&self) -> Vector2

Returns mouse position in pixel coordinates.
Source§

fn mouse_button_down(&self, n: MouseButton) -> bool

Returns whether the button is currently down.
Source§

fn get_mouse_wheel_move_v(&self) -> Vector2

Returns mouse wheel delta for the current frame. Read more
Source§

impl<M> RenderCompatibleWith<M> for HTMLRenderer

Source§

fn init(&mut self, _layout_manager: &mut M)

No-op: the HTML renderer does not require layout-manager initialization.

Source§

impl RendererTextMeasuringProvider<TextConfig> for HTMLRenderer

Source§

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CotisRenderContext for T

Source§

impl<H, TailTarget, Source, Idx> Embed<RenderTList<H, TailTarget>, There<Idx>> for Source
where TailTarget: IsRenderList, Source: Embed<TailTarget, Idx>,

Source§

fn embed(self) -> RenderTList<H, TailTarget>

Converts self into Target.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more