Simplify documentation of Element::map
This commit is contained in:
parent
628df69538
commit
4b33a450e0
1 changed files with 25 additions and 46 deletions
|
|
@ -94,52 +94,34 @@ impl<'a, Message, Theme, Renderer> Element<'a, Message, Theme, Renderer> {
|
||||||
/// producing them. Let's implement our __view logic__ now:
|
/// producing them. Let's implement our __view logic__ now:
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # mod counter {
|
/// # mod iced {
|
||||||
/// # #[derive(Debug, Clone, Copy)]
|
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, iced_core::renderer::Null>;
|
||||||
/// # pub enum Message {}
|
|
||||||
/// # pub struct Counter;
|
|
||||||
/// #
|
/// #
|
||||||
/// # impl Counter {
|
/// # pub mod widget {
|
||||||
/// # pub fn view(
|
/// # pub fn row<'a, Message>(iter: impl IntoIterator<Item = super::Element<'a, Message>>) -> super::Element<'a, Message> {
|
||||||
/// # &self,
|
|
||||||
/// # ) -> iced_core::Element<Message, (), iced_core::renderer::Null> {
|
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// # mod iced {
|
/// # mod counter {
|
||||||
/// # pub use iced_core::renderer::Null as Renderer;
|
/// # #[derive(Debug, Clone, Copy)]
|
||||||
/// # pub use iced_core::Element;
|
/// # pub enum Message {}
|
||||||
|
/// # pub struct Counter;
|
||||||
/// #
|
/// #
|
||||||
/// # pub mod widget {
|
/// # pub type Element<'a, Message> = iced_core::Element<'a, Message, iced_core::Theme, iced_core::renderer::Null>;
|
||||||
/// # pub struct Row<Message> {
|
|
||||||
/// # _t: std::marker::PhantomData<Message>,
|
|
||||||
/// # }
|
|
||||||
/// #
|
/// #
|
||||||
/// # impl<Message> Row<Message> {
|
/// # impl Counter {
|
||||||
/// # pub fn new() -> Self {
|
/// # pub fn view(&self) -> Element<Message> {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
|
||||||
/// #
|
|
||||||
/// # pub fn spacing(mut self, _: u32) -> Self {
|
|
||||||
/// # unimplemented!()
|
|
||||||
/// # }
|
|
||||||
/// #
|
|
||||||
/// # pub fn push(
|
|
||||||
/// # mut self,
|
|
||||||
/// # _: iced_core::Element<Message, (), iced_core::renderer::Null>,
|
|
||||||
/// # ) -> Self {
|
|
||||||
/// # unimplemented!()
|
|
||||||
/// # }
|
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// use counter::Counter;
|
/// use counter::Counter;
|
||||||
///
|
///
|
||||||
/// use iced::widget::Row;
|
/// use iced::widget::row;
|
||||||
/// use iced::{Element, Renderer};
|
/// use iced::Element;
|
||||||
///
|
///
|
||||||
/// struct ManyCounters {
|
/// struct ManyCounters {
|
||||||
/// counters: Vec<Counter>,
|
/// counters: Vec<Counter>,
|
||||||
|
|
@ -151,24 +133,21 @@ impl<'a, Message, Theme, Renderer> Element<'a, Message, Theme, Renderer> {
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl ManyCounters {
|
/// impl ManyCounters {
|
||||||
/// pub fn view(&mut self) -> Row<Message> {
|
/// pub fn view(&self) -> Element<Message> {
|
||||||
/// // We can quickly populate a `Row` by folding over our counters
|
/// // We can quickly populate a `row` by mapping our counters
|
||||||
/// self.counters.iter_mut().enumerate().fold(
|
/// row(
|
||||||
/// Row::new().spacing(20),
|
/// self.counters
|
||||||
/// |row, (index, counter)| {
|
/// .iter()
|
||||||
/// // We display the counter
|
/// .map(Counter::view)
|
||||||
/// let element: Element<counter::Message, _, _> =
|
/// .enumerate()
|
||||||
/// counter.view().into();
|
/// .map(|(index, counter)| {
|
||||||
///
|
|
||||||
/// row.push(
|
|
||||||
/// // Here we turn our `Element<counter::Message>` into
|
/// // Here we turn our `Element<counter::Message>` into
|
||||||
/// // an `Element<Message>` by combining the `index` and the
|
/// // an `Element<Message>` by combining the `index` and the
|
||||||
/// // message of the `element`.
|
/// // message of the `element`.
|
||||||
/// element
|
/// counter.map(move |message| Message::Counter(index, message))
|
||||||
/// .map(move |message| Message::Counter(index, message)),
|
/// }),
|
||||||
/// )
|
|
||||||
/// },
|
|
||||||
/// )
|
/// )
|
||||||
|
/// .into()
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue