Struct Style

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

This is the main struct used to build and manipulate css properties, it provieds many methods to do that.

use css_style::{prelude::*, color, unit::{ms, px}};

style()
    .and_transition(|conf| {
        conf
            .insert("opacity", |conf| conf.duration(ms(150.)).ease())
            .insert("transform", |conf| conf.duration(ms(150.)).ease())
            .insert("visibility", |conf| conf.duration(ms(150.)).ease())
    })
    .and_position(|conf| conf.absolute())
    .and_background(|conf| conf.color(color::named::WHITE))
    .and_border(|conf| {
        conf.none()
            .width(px(0))
            .radius(px(4))
    })
    .and_padding(|conf| conf.x(px(4)).y(px(2)))
    .and_margin(|conf| conf.top(px(2)))
    .insert("box-shadow", "0 2px 8px rgba(0, 35, 11, 0.15)");

Implementations§

Source§

impl Style

Source

pub fn new() -> Self

Source

pub fn to_css(&self) -> Option<String>

This method convert this style to html style value

Source

pub fn insert( self, key: impl Into<Cow<'static, str>>, value: impl ToString, ) -> Self

Insert a new css key value pair, or overwrite an existing one.

Source

pub fn try_insert( self, key: impl Into<Cow<'static, str>>, value: Option<impl ToString>, ) -> Self

Same as insert but take Option

Source

pub fn merge(self, other: impl StyleUpdater) -> Self

Merge two style

Source

pub fn try_merge(self, other: Option<impl StyleUpdater>) -> Self

Same as merge but take Option

Source

pub fn opacity(self, val: impl Into<Opacity>) -> Self

Setter for $prop_ty

Source

pub fn try_opacity(self, val: Option<impl Into<Opacity>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn gap(self, val: impl Into<Gap>) -> Self

Setter for $prop_ty

Source

pub fn try_gap(self, val: Option<impl Into<Gap>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn align_content(self, val: impl Into<AlignContent>) -> Self

Setter for $prop_ty

Source

pub fn try_align_content(self, val: Option<impl Into<AlignContent>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn align_items(self, val: impl Into<AlignItems>) -> Self

Setter for $prop_ty

Source

pub fn try_align_items(self, val: Option<impl Into<AlignItems>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn justify_content(self, val: impl Into<JustifyContent>) -> Self

Setter for $prop_ty

Source

pub fn try_justify_content(self, val: Option<impl Into<JustifyContent>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn justify_self(self, val: impl Into<JustifySelf>) -> Self

Setter for $prop_ty

Source

pub fn try_justify_self(self, val: Option<impl Into<JustifySelf>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn align_self(self, val: impl Into<AlignSelf>) -> Self

Setter for $prop_ty

Source

pub fn try_align_self(self, val: Option<impl Into<AlignSelf>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn flex_wrap(self, val: impl Into<FlexWrap>) -> Self

Setter for $prop_ty

Source

pub fn try_flex_wrap(self, val: Option<impl Into<FlexWrap>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn flex_basis(self, val: impl Into<FlexBasis>) -> Self

Setter for $prop_ty

Source

pub fn try_flex_basis(self, val: Option<impl Into<FlexBasis>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn flex_direction(self, val: impl Into<FlexDirection>) -> Self

Setter for $prop_ty

Source

pub fn try_flex_direction(self, val: Option<impl Into<FlexDirection>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn flex_order(self, val: impl Into<FlexOrder>) -> Self

Setter for $prop_ty

Source

pub fn try_flex_order(self, val: Option<impl Into<FlexOrder>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn flex_grow(self, val: impl Into<FlexGrow>) -> Self

Setter for $prop_ty

Source

pub fn try_flex_grow(self, val: Option<impl Into<FlexGrow>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn flex_shrink(self, val: impl Into<FlexShrink>) -> Self

Setter for $prop_ty

Source

pub fn try_flex_shrink(self, val: Option<impl Into<FlexShrink>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn display(self, val: impl Into<Display>) -> Self

Setter for $prop_ty

Source

pub fn try_display(self, val: Option<impl Into<Display>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn visibility(self, val: impl Into<Visibility>) -> Self

Setter for $prop_ty

Source

pub fn try_visibility(self, val: Option<impl Into<Visibility>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn cursor(self, val: impl Into<Cursor>) -> Self

Setter for $prop_ty

Source

pub fn try_cursor(self, val: Option<impl Into<Cursor>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn background(self, val: impl Into<Background>) -> Self

Setter for $prop_ty

Source

pub fn try_background(self, val: Option<impl Into<Background>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_background(self, val: impl FnOnce(Background) -> Background) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn border(self, val: impl Into<Border>) -> Self

Setter for $prop_ty

Source

pub fn try_border(self, val: Option<impl Into<Border>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_border(self, val: impl FnOnce(Border) -> Border) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn margin(self, val: impl Into<Margin>) -> Self

Setter for $prop_ty

Source

pub fn try_margin(self, val: Option<impl Into<Margin>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_margin(self, val: impl FnOnce(Margin) -> Margin) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn padding(self, val: impl Into<Padding>) -> Self

Setter for $prop_ty

Source

pub fn try_padding(self, val: Option<impl Into<Padding>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_padding(self, val: impl FnOnce(Padding) -> Padding) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn size(self, val: impl Into<Size>) -> Self

Setter for $prop_ty

Source

pub fn try_size(self, val: Option<impl Into<Size>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_size(self, val: impl FnOnce(Size) -> Size) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn transition(self, val: impl Into<Transition>) -> Self

Setter for $prop_ty

Source

pub fn try_transition(self, val: Option<impl Into<Transition>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_transition(self, val: impl FnOnce(Transition) -> Transition) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn box_shadow(self, val: impl Into<BoxShadow>) -> Self

Setter for $prop_ty

Source

pub fn try_box_shadow(self, val: Option<impl Into<BoxShadow>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_box_shadow(self, val: impl FnOnce(BoxShadow) -> BoxShadow) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn position(self, val: impl Into<Position>) -> Self

Setter for $prop_ty

Source

pub fn try_position(self, val: Option<impl Into<Position>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_position(self, val: impl FnOnce(Position) -> Position) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn text(self, val: impl Into<Text>) -> Self

Setter for $prop_ty

Source

pub fn try_text(self, val: Option<impl Into<Text>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_text(self, val: impl FnOnce(Text) -> Text) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Source

pub fn font(self, val: impl Into<Font>) -> Self

Setter for $prop_ty

Source

pub fn try_font(self, val: Option<impl Into<Font>>) -> Self

Setter for $prop_ty that takes Option<$prop_ty

Source

pub fn and_font(self, val: impl FnOnce(Font) -> Font) -> Self

Setter for $prop_ty that takes a closure which returns $prop_ty

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Style

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

impl Display for Style

Source§

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

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

impl PartialEq for Style

Source§

fn eq(&self, other: &Style) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StyleUpdater for Style

Source§

fn update_style(self, style: Style) -> Style

Source§

impl StructuralPartialEq for Style

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnwindSafe for Style

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: FloatComponent, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more