Show keyed_column doc example in multiple places
This commit is contained in:
parent
e98a441b0f
commit
70dd0501af
3 changed files with 68 additions and 8 deletions
|
|
@ -191,7 +191,27 @@ where
|
||||||
Column::with_children(children)
|
Column::with_children(children)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`keyed::Column`] with the given children.
|
/// Creates a new [`keyed::Column`] from an iterator of elements.
|
||||||
|
///
|
||||||
|
/// Keyed columns distribute content vertically while keeping continuity.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```no_run
|
||||||
|
/// # mod iced { pub mod widget { pub use iced_widget::*; } }
|
||||||
|
/// # pub type State = ();
|
||||||
|
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
|
||||||
|
/// use iced::widget::{keyed_column, text};
|
||||||
|
///
|
||||||
|
/// enum Message {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn view(state: &State) -> Element<'_, Message> {
|
||||||
|
/// keyed_column((0..=100).map(|i| {
|
||||||
|
/// (i, text!("Item {i}").into())
|
||||||
|
/// })).into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
pub fn keyed_column<'a, Key, Message, Theme, Renderer>(
|
pub fn keyed_column<'a, Key, Message, Theme, Renderer>(
|
||||||
children: impl IntoIterator<Item = (Key, Element<'a, Message, Theme, Renderer>)>,
|
children: impl IntoIterator<Item = (Key, Element<'a, Message, Theme, Renderer>)>,
|
||||||
) -> keyed::Column<'a, Key, Message, Theme, Renderer>
|
) -> keyed::Column<'a, Key, Message, Theme, Renderer>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//! Use widgets that can provide hints to ensure continuity.
|
//! Keyed widgets can provide hints to ensure continuity.
|
||||||
//!
|
//!
|
||||||
//! # What is continuity?
|
//! # What is continuity?
|
||||||
//! Continuity is the feeling of persistence of state.
|
//! Continuity is the feeling of persistence of state.
|
||||||
|
|
@ -41,13 +41,35 @@ pub mod column;
|
||||||
|
|
||||||
pub use column::Column;
|
pub use column::Column;
|
||||||
|
|
||||||
/// Creates a [`Column`] with the given children.
|
/// Creates a keyed [`Column`] with the given children.
|
||||||
|
///
|
||||||
|
/// Keyed columns distribute content vertically while keeping continuity.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```no_run
|
||||||
|
/// # mod iced { pub mod widget { pub use iced_widget::*; } }
|
||||||
|
/// # pub type State = ();
|
||||||
|
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
|
||||||
|
/// use iced::widget::keyed_column;
|
||||||
|
///
|
||||||
|
/// enum Message {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn view(state: &State) -> Element<'_, Message> {
|
||||||
|
/// keyed_column![
|
||||||
|
/// (0, "Item 0"),
|
||||||
|
/// (1, "Item 1"),
|
||||||
|
/// (2, "Item 2"),
|
||||||
|
/// ].into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! keyed_column {
|
macro_rules! keyed_column {
|
||||||
() => (
|
() => (
|
||||||
$crate::Column::new()
|
$crate::keyed::Column::new()
|
||||||
);
|
);
|
||||||
($($x:expr),+ $(,)?) => (
|
($(($key:expr, $x:expr)),+ $(,)?) => (
|
||||||
$crate::keyed::Column::with_children(vec![$($crate::core::Element::from($x)),+])
|
$crate::keyed::Column::with_children(vec![$(($key, $crate::core::Element::from($x))),+])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//! Distribute content vertically.
|
//! Keyed columns distribute content vertically while keeping continuity.
|
||||||
use crate::core::event::{self, Event};
|
use crate::core::event::{self, Event};
|
||||||
use crate::core::layout;
|
use crate::core::layout;
|
||||||
use crate::core::mouse;
|
use crate::core::mouse;
|
||||||
|
|
@ -11,7 +11,25 @@ use crate::core::{
|
||||||
Shell, Size, Vector, Widget,
|
Shell, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A container that distributes its contents vertically.
|
/// A container that distributes its contents vertically while keeping continuity.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```no_run
|
||||||
|
/// # mod iced { pub mod widget { pub use iced_widget::*; } }
|
||||||
|
/// # pub type State = ();
|
||||||
|
/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
|
||||||
|
/// use iced::widget::{keyed_column, text};
|
||||||
|
///
|
||||||
|
/// enum Message {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn view(state: &State) -> Element<'_, Message> {
|
||||||
|
/// keyed_column((0..=100).map(|i| {
|
||||||
|
/// (i, text!("Item {i}").into())
|
||||||
|
/// })).into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Column<
|
pub struct Column<
|
||||||
'a,
|
'a,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue