pub struct Css { /* private fields */ }Expand description
Represents a CSS class with a name, its style declarations, and optional pseudo rules.
Created by the class! macro and used in html! via the class: attribute.
When the renderer encounters a Css, it injects the styles into the
DOM’s <style> element on first use and applies the class name to the element.
Implementations§
Source§impl Css
Implementation of Css construction and style injection.
impl Css
Implementation of Css construction and style injection.
Sourcepub fn parse_pseudo_rules(input: &str) -> Vec<PseudoRule>
pub fn parse_pseudo_rules(input: &str) -> Vec<PseudoRule>
Parses pseudo-class/pseudo-element rules from a compact serialization string.
The serialization format is: :selector { key: value; key: value; }:another { ... }
This is used by the class! macro for fully static class definitions
where pseudo rules can be computed at compile time.
§Arguments
&str- The serialized pseudo rules string.
§Returns
Vec<PseudoRule>- The parsed pseudo rules.
Sourcepub fn parse_media_rules(input: &str) -> Vec<MediaRule>
pub fn parse_media_rules(input: &str) -> Vec<MediaRule>
Parses media query rules from a compact serialization string.
The serialization format is: @media query { key: value; key: value; }@media query2 { ... }
This is used by the class! macro for fully static class definitions
where media rules can be computed at compile time.
§Arguments
&str- The serialized media rules string.
§Returns
Vec<MediaRule>- The parsed media rules.
Sourcepub fn inject_style(&self)
pub fn inject_style(&self)
Injects this class’s styles into the DOM if not already present.
Uses a global HashSet to track injected class names, avoiding the
expensive existing_css.contains(css) full-text search on every call.
Builds the class rule, pseudo-class rules, and media rules as CSS text,
then appends them directly to the <style> element via
append_child with a new text node — no read-modify-write of the
entire stylesheet content.
§Panics
Panics if window() or document() is unavailable on the current platform.
Sourcepub fn inject_css(css_text: &str)
pub fn inject_css(css_text: &str)
Injects CSS text into the shared <style> element in the DOM.
Delegates to Css::append_css for the actual DOM append.
Unlike the previous implementation, this does not read the existing
stylesheet content or perform a full-text contains search.
§Arguments
&str- The CSS text to inject (e.g., reset styles, keyframes, media queries).
§Panics
Panics if window() or document() is unavailable on the current platform.
Source§impl Css
impl Css
pub fn get_name(&self) -> &String
pub fn get_mut_name(&mut self) -> &mut String
pub fn set_name(&mut self, val: String) -> &mut Self
pub fn get_style(&self) -> &String
pub fn get_mut_style(&mut self) -> &mut String
pub fn set_style(&mut self, val: String) -> &mut Self
pub fn get_pseudo_rules(&self) -> &Vec<PseudoRule>
pub fn get_mut_pseudo_rules(&mut self) -> &mut Vec<PseudoRule>
pub fn set_pseudo_rules(&mut self, val: Vec<PseudoRule>) -> &mut Self
pub fn get_media_rules(&self) -> &Vec<MediaRule>
pub fn get_mut_media_rules(&mut self) -> &mut Vec<MediaRule>
pub fn set_media_rules(&mut self, val: Vec<MediaRule>) -> &mut Self
Trait Implementations§
Source§impl Display for Css
Displays the CSS class name.
impl Display for Css
Displays the CSS class name.
This enables format!("{}", css) to produce the class name string,
which is required for reactive if conditions in class: attributes.
Source§impl IntoReactiveString for &'static Css
Converts a reference to a Css into its class name for reactive string storage.
impl IntoReactiveString for &'static Css
Converts a reference to a Css into its class name for reactive string storage.
Source§fn into_reactive_string(self) -> String
fn into_reactive_string(self) -> String
Source§impl IntoReactiveString for Css
Converts a Css into its class name for reactive string storage.
impl IntoReactiveString for Css
Converts a Css into its class name for reactive string storage.
Source§fn into_reactive_string(self) -> String
fn into_reactive_string(self) -> String
Source§impl IntoReactiveValue for &'static Css
Converts a reference to a CSS class into an attribute value by cloning.
impl IntoReactiveValue for &'static Css
Converts a reference to a CSS class into an attribute value by cloning.
Source§fn into_reactive_value(self) -> AttributeValue
fn into_reactive_value(self) -> AttributeValue
Converts this CSS class reference into an AttributeValue::Css by cloning.
§Returns
AttributeValue- A CSS class attribute value.
Source§impl IntoReactiveValue for Css
Converts a CSS class reference into an attribute value.
impl IntoReactiveValue for Css
Converts a CSS class reference into an attribute value.
Source§fn into_reactive_value(self) -> AttributeValue
fn into_reactive_value(self) -> AttributeValue
Converts this CSS class into an AttributeValue::Css.
§Returns
AttributeValue- A CSS class attribute value.