Skip to main content

Sheet

Struct Sheet 

Source
pub struct Sheet { /* private fields */ }
Expand description

The rules for a set of styles, each declaration written once.

A rule outside any cascade layer beats a layered one, so a plain stylesheet the page also loads overrides these classes.

use hypersig_style::value::{Color, px};
use hypersig_style::{PseudoClass, Sheet, Style};

let mut sheet = Sheet::new();
sheet.add(&Style::new().padding(px(8)).color(Color::CRIMSON));
sheet.add(&Style::new().on(PseudoClass::Hover, Style::new().color(Color::RED)));
let css: Vec<String> = sheet.buckets().map(|b| b.css().to_owned()).collect();
assert_eq!(
    css,
    [
        "@layer hypersig-tokens,hypersig-base,hypersig-atoms,hypersig-toggled;\
         @layer hypersig-atoms.k-----00{.color_crimson{color:crimson}.padding_8px{padding:8px}}",
        "@layer hypersig-tokens,hypersig-base,hypersig-atoms,hypersig-toggled;\
         @layer hypersig-atoms.k----4019-00{.hover\\:color_red:hover{color:red}}",
    ]
);

Implementations§

Source§

impl Sheet

Source

pub fn new() -> Self

An empty sheet.

Source

pub fn add(&mut self, style: &Style)

Adds the rules for the classes Style::class_names lists.

Source

pub fn add_toggled(&mut self, style: &Style)

Adds the rules for the classes Style::toggled_class_names lists.

Source

pub fn extend(&mut self, other: &Self)

Adds every rule of other.

Source

pub fn is_empty(&self) -> bool

Whether no style has been added.

Source

pub fn buckets(&self) -> impl Iterator<Item = Bucket> + '_

The rules grouped into buckets, in the order they apply, then one bucket per @keyframes rule.

Source

pub fn write_css(&self, out: &mut String)

Writes every bucket, as one stylesheet.

Source

pub fn to_css(&self) -> String

The stylesheet Sheet::write_css writes.

Trait Implementations§

Source§

impl Clone for Sheet

Source§

fn clone(&self) -> Sheet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Sheet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Sheet

Source§

fn default() -> Sheet

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

Auto Trait Implementations§

§

impl Freeze for Sheet

§

impl RefUnwindSafe for Sheet

§

impl Send for Sheet

§

impl Sync for Sheet

§

impl Unpin for Sheet

§

impl UnsafeUnpin for Sheet

§

impl UnwindSafe for Sheet

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.