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
impl Style
pub fn new() -> Self
Sourcepub fn insert(
self,
key: impl Into<Cow<'static, str>>,
value: impl ToString,
) -> Self
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.
Sourcepub fn try_insert(
self,
key: impl Into<Cow<'static, str>>,
value: Option<impl ToString>,
) -> Self
pub fn try_insert( self, key: impl Into<Cow<'static, str>>, value: Option<impl ToString>, ) -> Self
Same as insert
but take Option
Sourcepub fn merge(self, other: impl StyleUpdater) -> Self
pub fn merge(self, other: impl StyleUpdater) -> Self
Merge two style
Sourcepub fn try_merge(self, other: Option<impl StyleUpdater>) -> Self
pub fn try_merge(self, other: Option<impl StyleUpdater>) -> Self
Same as merge
but take Option
Sourcepub fn opacity(self, val: impl Into<Opacity>) -> Selfwhere
Opacity: StyleUpdater,
pub fn opacity(self, val: impl Into<Opacity>) -> Selfwhere
Opacity: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_opacity(self, val: Option<impl Into<Opacity>>) -> Self
pub fn try_opacity(self, val: Option<impl Into<Opacity>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn try_gap(self, val: Option<impl Into<Gap>>) -> Self
pub fn try_gap(self, val: Option<impl Into<Gap>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn align_content(self, val: impl Into<AlignContent>) -> Selfwhere
AlignContent: StyleUpdater,
pub fn align_content(self, val: impl Into<AlignContent>) -> Selfwhere
AlignContent: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_align_content(self, val: Option<impl Into<AlignContent>>) -> Self
pub fn try_align_content(self, val: Option<impl Into<AlignContent>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn align_items(self, val: impl Into<AlignItems>) -> Selfwhere
AlignItems: StyleUpdater,
pub fn align_items(self, val: impl Into<AlignItems>) -> Selfwhere
AlignItems: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_align_items(self, val: Option<impl Into<AlignItems>>) -> Self
pub fn try_align_items(self, val: Option<impl Into<AlignItems>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn justify_content(self, val: impl Into<JustifyContent>) -> Selfwhere
JustifyContent: StyleUpdater,
pub fn justify_content(self, val: impl Into<JustifyContent>) -> Selfwhere
JustifyContent: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_justify_content(self, val: Option<impl Into<JustifyContent>>) -> Self
pub fn try_justify_content(self, val: Option<impl Into<JustifyContent>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn justify_self(self, val: impl Into<JustifySelf>) -> Selfwhere
JustifySelf: StyleUpdater,
pub fn justify_self(self, val: impl Into<JustifySelf>) -> Selfwhere
JustifySelf: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_justify_self(self, val: Option<impl Into<JustifySelf>>) -> Self
pub fn try_justify_self(self, val: Option<impl Into<JustifySelf>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn align_self(self, val: impl Into<AlignSelf>) -> Selfwhere
AlignSelf: StyleUpdater,
pub fn align_self(self, val: impl Into<AlignSelf>) -> Selfwhere
AlignSelf: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_align_self(self, val: Option<impl Into<AlignSelf>>) -> Self
pub fn try_align_self(self, val: Option<impl Into<AlignSelf>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn flex_wrap(self, val: impl Into<FlexWrap>) -> Selfwhere
FlexWrap: StyleUpdater,
pub fn flex_wrap(self, val: impl Into<FlexWrap>) -> Selfwhere
FlexWrap: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_flex_wrap(self, val: Option<impl Into<FlexWrap>>) -> Self
pub fn try_flex_wrap(self, val: Option<impl Into<FlexWrap>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn flex_basis(self, val: impl Into<FlexBasis>) -> Selfwhere
FlexBasis: StyleUpdater,
pub fn flex_basis(self, val: impl Into<FlexBasis>) -> Selfwhere
FlexBasis: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_flex_basis(self, val: Option<impl Into<FlexBasis>>) -> Self
pub fn try_flex_basis(self, val: Option<impl Into<FlexBasis>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn flex_direction(self, val: impl Into<FlexDirection>) -> Selfwhere
FlexDirection: StyleUpdater,
pub fn flex_direction(self, val: impl Into<FlexDirection>) -> Selfwhere
FlexDirection: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_flex_direction(self, val: Option<impl Into<FlexDirection>>) -> Self
pub fn try_flex_direction(self, val: Option<impl Into<FlexDirection>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn flex_order(self, val: impl Into<FlexOrder>) -> Selfwhere
FlexOrder: StyleUpdater,
pub fn flex_order(self, val: impl Into<FlexOrder>) -> Selfwhere
FlexOrder: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_flex_order(self, val: Option<impl Into<FlexOrder>>) -> Self
pub fn try_flex_order(self, val: Option<impl Into<FlexOrder>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn flex_grow(self, val: impl Into<FlexGrow>) -> Selfwhere
FlexGrow: StyleUpdater,
pub fn flex_grow(self, val: impl Into<FlexGrow>) -> Selfwhere
FlexGrow: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_flex_grow(self, val: Option<impl Into<FlexGrow>>) -> Self
pub fn try_flex_grow(self, val: Option<impl Into<FlexGrow>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn flex_shrink(self, val: impl Into<FlexShrink>) -> Selfwhere
FlexShrink: StyleUpdater,
pub fn flex_shrink(self, val: impl Into<FlexShrink>) -> Selfwhere
FlexShrink: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_flex_shrink(self, val: Option<impl Into<FlexShrink>>) -> Self
pub fn try_flex_shrink(self, val: Option<impl Into<FlexShrink>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn display(self, val: impl Into<Display>) -> Selfwhere
Display: StyleUpdater,
pub fn display(self, val: impl Into<Display>) -> Selfwhere
Display: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_display(self, val: Option<impl Into<Display>>) -> Self
pub fn try_display(self, val: Option<impl Into<Display>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn visibility(self, val: impl Into<Visibility>) -> Selfwhere
Visibility: StyleUpdater,
pub fn visibility(self, val: impl Into<Visibility>) -> Selfwhere
Visibility: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_visibility(self, val: Option<impl Into<Visibility>>) -> Self
pub fn try_visibility(self, val: Option<impl Into<Visibility>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn cursor(self, val: impl Into<Cursor>) -> Selfwhere
Cursor: StyleUpdater,
pub fn cursor(self, val: impl Into<Cursor>) -> Selfwhere
Cursor: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_cursor(self, val: Option<impl Into<Cursor>>) -> Self
pub fn try_cursor(self, val: Option<impl Into<Cursor>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn background(self, val: impl Into<Background>) -> Selfwhere
Background: StyleUpdater,
pub fn background(self, val: impl Into<Background>) -> Selfwhere
Background: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_background(self, val: Option<impl Into<Background>>) -> Self
pub fn try_background(self, val: Option<impl Into<Background>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_background(self, val: impl FnOnce(Background) -> Background) -> Self
pub fn and_background(self, val: impl FnOnce(Background) -> Background) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn border(self, val: impl Into<Border>) -> Selfwhere
Border: StyleUpdater,
pub fn border(self, val: impl Into<Border>) -> Selfwhere
Border: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_border(self, val: Option<impl Into<Border>>) -> Self
pub fn try_border(self, val: Option<impl Into<Border>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_border(self, val: impl FnOnce(Border) -> Border) -> Self
pub fn and_border(self, val: impl FnOnce(Border) -> Border) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn margin(self, val: impl Into<Margin>) -> Selfwhere
Margin: StyleUpdater,
pub fn margin(self, val: impl Into<Margin>) -> Selfwhere
Margin: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_margin(self, val: Option<impl Into<Margin>>) -> Self
pub fn try_margin(self, val: Option<impl Into<Margin>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_margin(self, val: impl FnOnce(Margin) -> Margin) -> Self
pub fn and_margin(self, val: impl FnOnce(Margin) -> Margin) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn padding(self, val: impl Into<Padding>) -> Selfwhere
Padding: StyleUpdater,
pub fn padding(self, val: impl Into<Padding>) -> Selfwhere
Padding: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_padding(self, val: Option<impl Into<Padding>>) -> Self
pub fn try_padding(self, val: Option<impl Into<Padding>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_padding(self, val: impl FnOnce(Padding) -> Padding) -> Self
pub fn and_padding(self, val: impl FnOnce(Padding) -> Padding) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn try_size(self, val: Option<impl Into<Size>>) -> Self
pub fn try_size(self, val: Option<impl Into<Size>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_size(self, val: impl FnOnce(Size) -> Size) -> Self
pub fn and_size(self, val: impl FnOnce(Size) -> Size) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn transition(self, val: impl Into<Transition>) -> Selfwhere
Transition: StyleUpdater,
pub fn transition(self, val: impl Into<Transition>) -> Selfwhere
Transition: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_transition(self, val: Option<impl Into<Transition>>) -> Self
pub fn try_transition(self, val: Option<impl Into<Transition>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_transition(self, val: impl FnOnce(Transition) -> Transition) -> Self
pub fn and_transition(self, val: impl FnOnce(Transition) -> Transition) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn box_shadow(self, val: impl Into<BoxShadow>) -> Selfwhere
BoxShadow: StyleUpdater,
pub fn box_shadow(self, val: impl Into<BoxShadow>) -> Selfwhere
BoxShadow: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_box_shadow(self, val: Option<impl Into<BoxShadow>>) -> Self
pub fn try_box_shadow(self, val: Option<impl Into<BoxShadow>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_box_shadow(self, val: impl FnOnce(BoxShadow) -> BoxShadow) -> Self
pub fn and_box_shadow(self, val: impl FnOnce(BoxShadow) -> BoxShadow) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn position(self, val: impl Into<Position>) -> Selfwhere
Position: StyleUpdater,
pub fn position(self, val: impl Into<Position>) -> Selfwhere
Position: StyleUpdater,
Setter for $prop_ty
Sourcepub fn try_position(self, val: Option<impl Into<Position>>) -> Self
pub fn try_position(self, val: Option<impl Into<Position>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_position(self, val: impl FnOnce(Position) -> Position) -> Self
pub fn and_position(self, val: impl FnOnce(Position) -> Position) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Sourcepub fn try_text(self, val: Option<impl Into<Text>>) -> Self
pub fn try_text(self, val: Option<impl Into<Text>>) -> Self
Setter for $prop_ty
that takes Option<$prop_ty
Sourcepub fn and_text(self, val: impl FnOnce(Text) -> Text) -> Self
pub fn and_text(self, val: impl FnOnce(Text) -> Text) -> Self
Setter for $prop_ty
that takes a closure which returns $prop_ty
Trait Implementations§
Source§impl StyleUpdater for Style
impl StyleUpdater for Style
fn update_style(self, style: Style) -> Style
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
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more