From f5455d2686c432e54a87ebf1cc265babcc2c0a2f Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Fri, 11 Oct 2024 00:57:17 +0200 Subject: [PATCH] xilem_web: Remove some comment artifacts, put `WithStyle` bound to `Element` interface and document `Element::style` (#667) I missed comment artifacts in #621, added doc-comment/test for `SvgElement` and put the `WithStyle` on the `Element` interface bounds, as it plays better with rust-analyzer and is more consistent with the other API. --- xilem_web/src/interfaces.rs | 38 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/xilem_web/src/interfaces.rs b/xilem_web/src/interfaces.rs index 927c49ab..a848bcc9 100644 --- a/xilem_web/src/interfaces.rs +++ b/xilem_web/src/interfaces.rs @@ -54,7 +54,7 @@ pub trait Element: + DomView< State, Action, - DomNode: DomNode + AsRef, + DomNode: DomNode + AsRef, > { /// Set an attribute for an [`Element`] @@ -146,11 +146,20 @@ pub trait Element: Attr::new(self, Cow::from("id"), value.into_attr_value()) } - /// Set a style attribute - fn style(self, style: impl IntoStyles) -> Style - where - ::Props: WithStyle, - { + /// Set the [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) attribute + /// + /// # Examples + /// + /// ``` + /// use xilem_web::{style as s, elements::html::div, interfaces::Element}; + /// + /// # fn component() -> impl Element<()> { + /// div(()) + /// .style([s("display", "flex"), s("align-items", "center")]) + /// .style(s("justify-content", "center")) + /// # } + /// ``` + fn style(self, style: impl IntoStyles) -> Style { let mut styles = vec![]; style.into_styles(&mut styles); Style::new(self, styles) @@ -170,10 +179,7 @@ pub trait Element: /// // /// # } /// ``` - fn rotate(self, radians: f64) -> Rotate - where - ::Props: WithStyle, - { + fn rotate(self, radians: f64) -> Rotate { Rotate::new(self, radians) } @@ -328,7 +334,7 @@ pub trait Element: impl Element for T where T: DomView, - ::Props: WithAttributes + WithClasses, + ::Props: WithAttributes + WithClasses + WithStyle, T::DomNode: AsRef, { } @@ -551,19 +557,10 @@ where { } -// pub trait StyleExt { -// } - -// /// Keep this shared code in sync between `HtmlElement` and `SvgElement` -// macro_rules! style_impls { -// () => {}; -// } - // #[cfg(feature = "HtmlElement")] pub trait HtmlElement: Element + AsRef> { - // style_impls!(); } // #[cfg(feature = "HtmlElement")] @@ -1535,7 +1532,6 @@ where pub trait SvgElement: Element + AsRef> { - // style_impls!(); } // #[cfg(feature = "SvgElement")]