diff options
| author | 2019-11-24 11:34:30 +0100 | |
|---|---|---|
| committer | 2019-11-24 11:34:30 +0100 | |
| commit | 149fd2aa1fa86858c7c1dcec8fd844caa78cec94 (patch) | |
| tree | a199cf8d2caaf6aa60e48e93d6dd0688969d43b0 /web/src/element.rs | |
| parent | 9712b319bb7a32848001b96bd84977430f14b623 (diff) | |
| parent | 47196c9007d12d3b3e0036ffabe3bf6d14ff4523 (diff) | |
| download | iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.tar.gz iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.tar.bz2 iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.zip | |
Merge pull request #65 from hecrj/improvement/docs
Documentation
Diffstat (limited to '')
| -rw-r--r-- | web/src/element.rs | 48 | 
1 files changed, 36 insertions, 12 deletions
| diff --git a/web/src/element.rs b/web/src/element.rs index a2b78c69..fcf0a4b6 100644 --- a/web/src/element.rs +++ b/web/src/element.rs @@ -3,29 +3,39 @@ use crate::{Bus, Color, Widget};  use dodrio::bumpalo;  use std::rc::Rc; +/// A generic [`Widget`]. +/// +/// It is useful to build composable user interfaces that do not leak +/// implementation details in their __view logic__. +/// +/// If you have a [built-in widget], you should be able to use `Into<Element>` +/// to turn it into an [`Element`]. +/// +/// [built-in widget]: widget/index.html +/// [`Widget`]: widget/trait.Widget.html +/// [`Element`]: struct.Element.html +#[allow(missing_debug_implementations)]  pub struct Element<'a, Message> {      pub(crate) widget: Box<dyn Widget<Message> + 'a>,  }  impl<'a, Message> Element<'a, Message> { +    /// Create a new [`Element`] containing the given [`Widget`]. +    /// +    /// [`Element`]: struct.Element.html +    /// [`Widget`]: widget/trait.Widget.html      pub fn new(widget: impl Widget<Message> + 'a) -> Self {          Self {              widget: Box::new(widget),          }      } -    pub fn node<'b>( -        &self, -        bump: &'b bumpalo::Bump, -        bus: &Bus<Message>, -    ) -> dodrio::Node<'b> { -        self.widget.node(bump, bus) -    } - -    pub fn explain(self, _color: Color) -> Element<'a, Message> { -        self -    } - +    /// Applies a transformation to the produced message of the [`Element`]. +    /// +    /// This method is useful when you want to decouple different parts of your +    /// UI and make them __composable__. +    /// +    /// [`Element`]: struct.Element.html      pub fn map<F, B>(self, f: F) -> Element<'a, B>      where          Message: 'static, @@ -36,6 +46,20 @@ impl<'a, Message> Element<'a, Message> {              widget: Box::new(Map::new(self.widget, f)),          }      } + +    /// Marks the [`Element`] as _to-be-explained_. +    pub fn explain(self, _color: Color) -> Element<'a, Message> { +        self +    } + +    /// Produces a VDOM node for the [`Element`]. +    pub fn node<'b>( +        &self, +        bump: &'b bumpalo::Bump, +        bus: &Bus<Message>, +    ) -> dodrio::Node<'b> { +        self.widget.node(bump, bus) +    }  }  struct Map<'a, A, B> { | 
