pub struct Engine { /* private fields */ }Expand description
A page: a DOM document, its stylesheets, and (later) its resolved layout.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn set_base_url(&mut self, url: impl Into<String>)
pub fn set_base_url(&mut self, url: impl Into<String>)
The URL the document’s references resolve against (its own URL).
Sourcepub fn set_loader(&mut self, loader: impl Loader + Send + Sync + 'static)
pub fn set_loader(&mut self, loader: impl Loader + Send + Sync + 'static)
Load subresources through loader from now on. Without one, nothing
is loaded: an engine reaches the filesystem or the network only
when its host says so.
Sourcepub fn completions(&self) -> &Completions
pub fn completions(&self) -> &Completions
The queue loads finish into: set a waker on it to hear when to call
Engine::poll_resources.
Sourcepub fn load_resources(&mut self) -> usize
pub fn load_resources(&mut self) -> usize
Start loading each <img src> not yet requested, resolved against
the base URL; returns how many loads started. Call it after parsing
and after DOM edits that may add images.
Sourcepub fn poll_resources(&mut self) -> bool
pub fn poll_resources(&mut self) -> bool
Take in the loads that finished; true when an image arrived, so
layout changed. A load that failed or isn’t an image keeps its
element’s alt text, and isn’t retried.
Source§impl Engine
impl Engine
Sourcepub fn from_html(html: &str) -> Self
pub fn from_html(html: &str) -> Self
Parse html into a fresh engine, collecting its stylesheets.
Sourcepub fn stylesheets(&self) -> &[Stylesheet]
pub fn stylesheets(&self) -> &[Stylesheet]
The stylesheets collected from the document’s <style> elements.
Sourcepub fn refresh_stylesheets(&mut self)
pub fn refresh_stylesheets(&mut self)
Re-scan the document’s <style> elements for stylesheets.
Sourcepub fn restyle(
&mut self,
styles: &mut Styles,
viewport: Size,
interaction: Interaction,
) -> usize
pub fn restyle( &mut self, styles: &mut Styles, viewport: Size, interaction: Interaction, ) -> usize
Bring styles up to date with the document, its stylesheets,
viewport and interaction, restyling only what changed since the
last call. Returns how many times an element was styled.
Start from Styles::default: the first call computes everything.
After that, edits made through Document::mutate restyle only the
subtrees they can reach, and a hover, focus or press moving restyles
the nodes it moved between. An edit to a <style> element, a new
viewport, or raw writes through Document::tree_mut restyle
everything.
Sourcepub fn font_faces(&self) -> Vec<FontFace>
pub fn font_faces(&self) -> Vec<FontFace>
The @font-face descriptors collected from the stylesheets, in source
order.
A host loads each src (noonoo-net covers file: and data:),
parses the bytes with noonoo-ttf’s Font, and registers the face
with a FontSet; see the noonoo CLI’s --paint for the pattern.
Sourcepub fn compute_styles(&self) -> Styles
pub fn compute_styles(&self) -> Styles
Compute every element’s style: cascade the collected stylesheets over the
user-agent sheet and any inline style attributes.
Viewport-relative units resolve against
noonoo_style::Viewport::DEFAULT; Engine::compute_styles_for uses a
real viewport instead.
Sourcepub fn compute_styles_for(&self, viewport: Size) -> Styles
pub fn compute_styles_for(&self, viewport: Size) -> Styles
Compute every element’s style against viewport, so vw/vh and
calc(100vw - 2rem) resolve correctly.
Sourcepub fn compute_styles_in(
&self,
viewport: Size,
interaction: Interaction,
) -> Styles
pub fn compute_styles_in( &self, viewport: Size, interaction: Interaction, ) -> Styles
Compute every element’s style against viewport and the interactive
state, so :hover/:focus/:active style the elements they name.
Sourcepub fn layout(&self, viewport: Size, shaper: &dyn Shaper) -> LayoutTree
pub fn layout(&self, viewport: Size, shaper: &dyn Shaper) -> LayoutTree
Lay the document out for a viewport, using the given text shaper.
Sourcepub fn paint(&self, viewport: Size, shaper: &dyn Shaper) -> CommandList
pub fn paint(&self, viewport: Size, shaper: &dyn Shaper) -> CommandList
Lay out and paint the document, returning the render command stream.
Sourcepub fn paint_with(
&self,
viewport: Size,
shaper: &dyn Shaper,
glyphs: &dyn Glyphs,
) -> CommandList
pub fn paint_with( &self, viewport: Size, shaper: &dyn Shaper, glyphs: &dyn Glyphs, ) -> CommandList
Lay out and paint the document, drawing text with glyphs.
Use this with a font-backed shaper and matching glyph renderer to render
vector text (see noonoo-ttf’s FontShaper + OutlineGlyphs).