From 79e1ce7a35b0c468c6a4747f2372d33552f938ad Mon Sep 17 00:00:00 2001 From: ThomasMcandrew Date: Sun, 4 Dec 2022 07:30:55 -0600 Subject: [PATCH 01/16] starting docs --- druid/src/widget/list.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 340da1637b..ab7d2bed09 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -34,6 +34,10 @@ use crate::{ }; /// A list widget for a variable-size collection of items. +/// The list widget uses ['Vector'] from +/// +/// +/// ['Vector']: im::Vector pub struct List { closure: Box Box>>, children: Vec>>>, From 5dc46b42879339524a455e8aa2a96ffaec727d5d Mon Sep 17 00:00:00 2001 From: ThomasMcandrew Date: Sun, 4 Dec 2022 08:39:52 -0600 Subject: [PATCH 02/16] more documentation --- druid/src/widget/list.rs | 117 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index ab7d2bed09..20495ea9b2 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -34,10 +34,97 @@ use crate::{ }; /// A list widget for a variable-size collection of items. -/// The list widget uses ['Vector'] from +/// For a static sized collection of items use [`Flex`]. +/// The best data structure to use with the list widget is [`Vector`] from the [`im`] feature. +/// To include the [`im`] feature, update Cargo.toml +/// ``` +/// [dependencies] +/// // before +/// druid = "0.7.0" +/// // after +/// druid = { version = "0.7.0", features = ["im"] } +/// ``` /// +/// # Examples +/// ## Define the data /// -/// ['Vector']: im::Vector +/// ``` +/// # use druid::widget::Label; +/// use druid::im::{ Vector, WidgetExt }; +/// use druid::widget::list; +/// +/// #[derive(Clone, Data, Lens)] +/// struct AppState { +/// list_data: Vector, +/// } +/// ``` +/// ## Create initial State +/// +/// ``` +/// let initial_state = AppState { +/// list_data: Vector::from( +/// vec!( +/// "one", +/// "two", +/// "three", +/// "four", +/// )), +/// }; +/// ``` +/// ## Create widgets +/// +/// ``` +/// fn root() -> impl Widget { +/// let list = List::new(list_item) +/// .lens(AppState::list_data); +/// list +/// } +/// +/// fn list_item() -> impl Widget { +/// let label = Label::new(|data: &String, _env: &Env| +/// data.clone()) +/// label +/// } +/// ``` +/// ## Scrollable List +/// Commonly a list should be able to scroll, the [`Scroll`] widget can be used to implement this +/// feature. +/// See docs for more info. +/// +/// ``` +/// # use druid::widget::Scroll; +/// fn root() -> impl Widget { +/// let list = List::new(list_item) +/// .lens(AppState::list_data); +/// Scroll(list) +/// } +/// ``` +/// ## Complex widgets +/// List can be used with any complex widgets. +/// ``` +/// struct AppState { +/// list_data: Vector, +/// } +/// struct InnerState { +/// name: String, +/// } +/// +/// fn root() -> impl Widget { +/// let list = List::new(list_item) +/// .lens(AppState::list_data); +/// list +/// } +/// +/// fn list_item() -> impl Widget { +/// let label = Label::new(|data: &InnerState, _env: &Env| +/// data.name.clone()) +/// label +/// } +/// ``` +/// [`im`]: https://docs.rs/druid/0.6.0/druid/im/index.html +/// [`Flex`]: crate::widget::Flex +/// [`Vector`]: https://docs.rs/druid/0.6.0/druid/im/vector/index.html +/// [`Scroll`]: crate::widget::Scroll pub struct List { closure: Box Box>>, children: Vec>>>, @@ -49,6 +136,32 @@ pub struct List { impl List { /// Create a new list widget. Closure will be called every time when a new child /// needs to be constructed. + /// + /// The list widget can have a function passed in as a closure, or an abstract closure can also + /// be provided. + /// + /// # Example + /// ``` + /// fn root() -> impl Widget { + /// let list = List::new(list_item) + /// .lens(AppState::list_data); + /// list + /// } + /// fn list_item -> impl Widget { + /// let label = Label::new(|data: &String, _env: &Env| + /// data.clone()); + /// label + /// } + /// //This widget is the same as the two widgets above + /// //combined. + /// fn combined -> impl Widget { + /// let list = List::new(|| + /// Label::new(|data: &String, _env: &Env| + /// data.clone())) + /// .lens(AppState::list_data); + /// list + /// } + /// ``` pub fn new + 'static>(closure: impl Fn() -> W + 'static) -> Self { List { closure: Box::new(move || Box::new(closure())), From f840036127ebfcaaa87fe5f759a08cd22dc33e3d Mon Sep 17 00:00:00 2001 From: ThomasMcandrew Date: Sun, 4 Dec 2022 08:52:22 -0600 Subject: [PATCH 03/16] fixing problems with pre push hook --- druid/src/widget/list.rs | 57 +++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 20495ea9b2..ed3781602b 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -35,7 +35,7 @@ use crate::{ /// A list widget for a variable-size collection of items. /// For a static sized collection of items use [`Flex`]. -/// The best data structure to use with the list widget is [`Vector`] from the [`im`] feature. +/// The best data structure to use with the list widget is [`Vector`] from the [`im`] feature. /// To include the [`im`] feature, update Cargo.toml /// ``` /// [dependencies] @@ -61,6 +61,14 @@ use crate::{ /// ## Create initial State /// /// ``` +/// # use druid::widget::{ Label, List }; +/// # use druid::im::{ Vector, WidgetExt }; +/// +/// # #[derive(Clone, Data, Lens)] +/// # struct AppState { +/// # list_data: Vector, +/// # } +/// /// let initial_state = AppState { /// list_data: Vector::from( /// vec!( @@ -74,25 +82,41 @@ use crate::{ /// ## Create widgets /// /// ``` +/// # use druid::widget::{ Label, List }; +/// # use druid::im::{ Vector, WidgetExt }; +/// +/// # #[derive(Clone, Data, Lens)] +/// # struct AppState { +/// # list_data: Vector, +/// # } +/// /// fn root() -> impl Widget { /// let list = List::new(list_item) /// .lens(AppState::list_data); /// list /// } -/// +/// /// fn list_item() -> impl Widget { -/// let label = Label::new(|data: &String, _env: &Env| +/// let label = Label::new(|data: &String, _env: &Env| /// data.clone()) /// label /// } /// ``` /// ## Scrollable List /// Commonly a list should be able to scroll, the [`Scroll`] widget can be used to implement this -/// feature. +/// feature. /// See docs for more info. /// /// ``` +/// # use druid::widget::{ Label, List }; +/// # use druid::im::{ Vector, WidgetExt }; +/// +/// # #[derive(Clone, Data, Lens)] +/// # struct AppState { +/// # list_data: Vector, +/// # } /// # use druid::widget::Scroll; +/// /// fn root() -> impl Widget { /// let list = List::new(list_item) /// .lens(AppState::list_data); @@ -102,9 +126,14 @@ use crate::{ /// ## Complex widgets /// List can be used with any complex widgets. /// ``` +/// # use druid::widget::{ Label, List }; +/// # use druid::im::{ Vector, WidgetExt }; +/// +/// #[derive(Clone, Data, Lens)] /// struct AppState { /// list_data: Vector, /// } +/// #[derive(Clone, Data, Lens)] /// struct InnerState { /// name: String, /// } @@ -114,9 +143,9 @@ use crate::{ /// .lens(AppState::list_data); /// list /// } -/// +/// /// fn list_item() -> impl Widget { -/// let label = Label::new(|data: &InnerState, _env: &Env| +/// let label = Label::new(|data: &InnerState, _env: &Env| /// data.name.clone()) /// label /// } @@ -142,21 +171,29 @@ impl List { /// /// # Example /// ``` + /// # use druid::widget::{ Label, List }; + /// # use druid::im::{ Vector, WidgetExt }; + /// + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # list_data: Vector, + /// # } + /// /// fn root() -> impl Widget { /// let list = List::new(list_item) /// .lens(AppState::list_data); /// list /// } /// fn list_item -> impl Widget { - /// let label = Label::new(|data: &String, _env: &Env| + /// let label = Label::new(|data: &String, _env: &Env| /// data.clone()); /// label /// } - /// //This widget is the same as the two widgets above + /// //This widget is the same as the two widgets above /// //combined. /// fn combined -> impl Widget { - /// let list = List::new(|| - /// Label::new(|data: &String, _env: &Env| + /// let list = List::new(|| + /// Label::new(|data: &String, _env: &Env| /// data.clone())) /// .lens(AppState::list_data); /// list From 8a35fdc1ff5968bb68637d1b928b064890fb780c Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Sun, 4 Dec 2022 08:59:51 -0600 Subject: [PATCH 04/16] update --- druid/src/widget/list.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index ed3781602b..cbc876dc3a 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -46,6 +46,7 @@ use crate::{ /// ``` /// /// # Examples +/// /// ## Define the data /// /// ``` From 9bc8c262f938d2f16f34ecd966bdc488f8292e15 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 16:36:10 -0600 Subject: [PATCH 05/16] working on errors --- druid/src/widget/list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index cbc876dc3a..fdc3ea9ded 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -37,7 +37,7 @@ use crate::{ /// For a static sized collection of items use [`Flex`]. /// The best data structure to use with the list widget is [`Vector`] from the [`im`] feature. /// To include the [`im`] feature, update Cargo.toml -/// ``` +/// ```ignore /// [dependencies] /// // before /// druid = "0.7.0" From 6297c5a31af2e2d9d31e60f7922cbfbb19c69a96 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 16:39:46 -0600 Subject: [PATCH 06/16] working on errors --- druid/src/widget/list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index fdc3ea9ded..186e502b88 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -37,7 +37,7 @@ use crate::{ /// For a static sized collection of items use [`Flex`]. /// The best data structure to use with the list widget is [`Vector`] from the [`im`] feature. /// To include the [`im`] feature, update Cargo.toml -/// ```ignore +/// ```ignore /// [dependencies] /// // before /// druid = "0.7.0" From 38fae401c042b74c71dc4bd31cf61c105ab5c744 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 16:50:52 -0600 Subject: [PATCH 07/16] working on errors --- druid/src/widget/list.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 186e502b88..6450797286 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -51,6 +51,8 @@ use crate::{ /// /// ``` /// # use druid::widget::Label; +/// # use druid::{ Data, Lens }; +/// #[cfg(feature = "im")] /// use druid::im::{ Vector, WidgetExt }; /// use druid::widget::list; /// From 93d508b26f0c11d437da3c104261372e320676cc Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 17:13:27 -0600 Subject: [PATCH 08/16] working on errors --- druid/src/widget/list.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 6450797286..621233e9a3 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -51,9 +51,9 @@ use crate::{ /// /// ``` /// # use druid::widget::Label; -/// # use druid::{ Data, Lens }; +/// # use druid::{ Data, Lens, WidgetExt}; /// #[cfg(feature = "im")] -/// use druid::im::{ Vector, WidgetExt }; +/// use druid::im::Vector; /// use druid::widget::list; /// /// #[derive(Clone, Data, Lens)] @@ -65,7 +65,8 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::im::{ Vector, WidgetExt }; +/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -86,7 +87,8 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::im::{ Vector, WidgetExt }; +/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -112,7 +114,8 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::im::{ Vector, WidgetExt }; +/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -130,7 +133,8 @@ use crate::{ /// List can be used with any complex widgets. /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::im::{ Vector, WidgetExt }; +/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::im::Vector; /// /// #[derive(Clone, Data, Lens)] /// struct AppState { @@ -175,7 +179,8 @@ impl List { /// # Example /// ``` /// # use druid::widget::{ Label, List }; - /// # use druid::im::{ Vector, WidgetExt }; + /// # use druid::{ Data, Lens, WidgetExt}; + /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { From 2b525abf734e758a4d6a758836a7171a93d3d383 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 17:23:18 -0600 Subject: [PATCH 09/16] working on errors --- druid/src/widget/list.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 621233e9a3..598d803705 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -51,7 +51,7 @@ use crate::{ /// /// ``` /// # use druid::widget::Label; -/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt}; /// #[cfg(feature = "im")] /// use druid::im::Vector; /// use druid::widget::list; @@ -65,7 +65,7 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -87,7 +87,7 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -114,7 +114,7 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -133,7 +133,7 @@ use crate::{ /// List can be used with any complex widgets. /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt}; /// # use druid::im::Vector; /// /// #[derive(Clone, Data, Lens)] @@ -153,7 +153,7 @@ use crate::{ /// /// fn list_item() -> impl Widget { /// let label = Label::new(|data: &InnerState, _env: &Env| -/// data.name.clone()) +/// data.name.clone()); /// label /// } /// ``` @@ -179,7 +179,7 @@ impl List { /// # Example /// ``` /// # use druid::widget::{ Label, List }; - /// # use druid::{ Data, Lens, WidgetExt}; + /// # use druid::{ Data, Lens, Widget, WidgetExt}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -192,7 +192,7 @@ impl List { /// .lens(AppState::list_data); /// list /// } - /// fn list_item -> impl Widget { + /// fn list_item() -> impl Widget { /// let label = Label::new(|data: &String, _env: &Env| /// data.clone()); /// label From 7b62391be77430e9db6fb83ec14aa70532c156a0 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 17:33:33 -0600 Subject: [PATCH 10/16] working on errors --- druid/src/widget/list.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 598d803705..f99e38c8df 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -54,7 +54,7 @@ use crate::{ /// # use druid::{ Data, Lens, Widget, WidgetExt}; /// #[cfg(feature = "im")] /// use druid::im::Vector; -/// use druid::widget::list; +/// use druid::widget::List; /// /// #[derive(Clone, Data, Lens)] /// struct AppState { @@ -87,7 +87,7 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, Widget, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -103,7 +103,7 @@ use crate::{ /// /// fn list_item() -> impl Widget { /// let label = Label::new(|data: &String, _env: &Env| -/// data.clone()) +/// data.clone()); /// label /// } /// ``` @@ -133,7 +133,7 @@ use crate::{ /// List can be used with any complex widgets. /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, Widget, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; /// /// #[derive(Clone, Data, Lens)] @@ -199,7 +199,7 @@ impl List { /// } /// //This widget is the same as the two widgets above /// //combined. - /// fn combined -> impl Widget { + /// fn combined() -> impl Widget { /// let list = List::new(|| /// Label::new(|data: &String, _env: &Env| /// data.clone())) From c82bee75f282244185b0cccd69539d77c1ecec71 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 17:44:54 -0600 Subject: [PATCH 11/16] working on errors --- druid/src/widget/list.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index f99e38c8df..c8dbd96c45 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -76,10 +76,10 @@ use crate::{ /// let initial_state = AppState { /// list_data: Vector::from( /// vec!( -/// "one", -/// "two", -/// "three", -/// "four", +/// "one".into(), +/// "two".into(), +/// "three".into(), +/// "four".into(), /// )), /// }; /// ``` @@ -114,7 +114,7 @@ use crate::{ /// /// ``` /// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, Widget, WidgetExt}; +/// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -122,6 +122,11 @@ use crate::{ /// # list_data: Vector, /// # } /// # use druid::widget::Scroll; +/// # fn list_item() -> impl Widget { +/// # let label = Label::new(|data: &String, _env: &Env| +/// # data.clone()); +/// # label +/// # } /// /// fn root() -> impl Widget { /// let list = List::new(list_item) @@ -179,7 +184,7 @@ impl List { /// # Example /// ``` /// # use druid::widget::{ Label, List }; - /// # use druid::{ Data, Lens, Widget, WidgetExt}; + /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] From 6cef30a6551531314a64321e62ead9d288230801 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 19:51:37 -0600 Subject: [PATCH 12/16] working on errors --- druid/src/widget/list.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index c8dbd96c45..7f05fdfbb2 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -66,6 +66,7 @@ use crate::{ /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt}; +/// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -88,6 +89,7 @@ use crate::{ /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; +/// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -115,6 +117,7 @@ use crate::{ /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; +/// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -139,6 +142,7 @@ use crate::{ /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; +/// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// #[derive(Clone, Data, Lens)] @@ -185,6 +189,7 @@ impl List { /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; + /// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] From 3c27c6ab037c7261b5de9bd777b19b1765203857 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 19:59:34 -0600 Subject: [PATCH 13/16] working on errors --- druid/src/widget/list.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 7f05fdfbb2..8129168d80 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -134,7 +134,7 @@ use crate::{ /// fn root() -> impl Widget { /// let list = List::new(list_item) /// .lens(AppState::list_data); -/// Scroll(list) +/// Scroll::new(list) /// } /// ``` /// ## Complex widgets @@ -202,7 +202,7 @@ impl List { /// .lens(AppState::list_data); /// list /// } - /// fn list_item() -> impl Widget { + /// fn list_item() -> impl Widget { /// let label = Label::new(|data: &String, _env: &Env| /// data.clone()); /// label From 6cf721fdb173ba8c6a0f0cfc352f9fa7c7105a8c Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 20:24:54 -0600 Subject: [PATCH 14/16] working on errors --- druid/src/widget/list.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 8129168d80..350aab2329 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -50,11 +50,8 @@ use crate::{ /// ## Define the data /// /// ``` -/// # use druid::widget::Label; -/// # use druid::{ Data, Lens, Widget, WidgetExt}; -/// #[cfg(feature = "im")] +/// # use druid::{ Data, Lens }; /// use druid::im::Vector; -/// use druid::widget::List; /// /// #[derive(Clone, Data, Lens)] /// struct AppState { @@ -64,9 +61,7 @@ use crate::{ /// ## Create initial State /// /// ``` -/// # use druid::widget::{ Label, List }; -/// # use druid::{ Data, Lens, Widget, WidgetExt}; -/// #[cfg(feature = "im")] +/// # use druid::{ Data, Lens}; /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -89,7 +84,6 @@ use crate::{ /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; -/// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] @@ -115,16 +109,14 @@ use crate::{ /// See docs for more info. /// /// ``` -/// # use druid::widget::{ Label, List }; +/// # use druid::widget::{ Label, List, Scroll }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; -/// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { /// # list_data: Vector, /// # } -/// # use druid::widget::Scroll; /// # fn list_item() -> impl Widget { /// # let label = Label::new(|data: &String, _env: &Env| /// # data.clone()); @@ -142,7 +134,6 @@ use crate::{ /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; -/// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// #[derive(Clone, Data, Lens)] @@ -189,7 +180,6 @@ impl List { /// ``` /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; - /// #[cfg(feature = "im")] /// # use druid::im::Vector; /// /// # #[derive(Clone, Data, Lens)] From b46442f03180e6f8eb5f66f3f8d02b601c509844 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 20:48:26 -0600 Subject: [PATCH 15/16] updating pr number --- CHANGELOG.md | 2 ++ druid/src/widget/list.rs | 13 +++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6cbcae67c..637dcdf0e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -151,6 +151,7 @@ You can find its changes [documented below](#070---2021-01-01). - Fix `Controller` links for `Click` ([#2158] by [@yrns]) - Delete inaccurate line for `KeyEvent` ([#2247] by [@amtep]) - Added examples in `TextBox` ([#2284] by [@ThomasMcandrew]) +- Added examples in `List` ([#2302] by [@ThomasMcandrew]) ### Examples - Add readme ([#1423] by [@JAicewizard]) @@ -867,6 +868,7 @@ Last release without a changelog :( [#2247]: https://github.com/linebender/druid/pull/2247 [#2274]: https://github.com/linebender/druid/pull/2274 [#2284]: https://github.com/linebender/druid/pull/2284 +[#2302]: https://github.com/linebender/druid/pull/2302 [Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master [0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0 diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 350aab2329..10e6ceb51d 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -52,7 +52,6 @@ use crate::{ /// ``` /// # use druid::{ Data, Lens }; /// use druid::im::Vector; -/// /// #[derive(Clone, Data, Lens)] /// struct AppState { /// list_data: Vector, @@ -63,12 +62,10 @@ use crate::{ /// ``` /// # use druid::{ Data, Lens}; /// # use druid::im::Vector; -/// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { /// # list_data: Vector, /// # } -/// /// let initial_state = AppState { /// list_data: Vector::from( /// vec!( @@ -85,12 +82,10 @@ use crate::{ /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; -/// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { /// # list_data: Vector, /// # } -/// /// fn root() -> impl Widget { /// let list = List::new(list_item) /// .lens(AppState::list_data); @@ -112,7 +107,6 @@ use crate::{ /// # use druid::widget::{ Label, List, Scroll }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; -/// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { /// # list_data: Vector, @@ -122,7 +116,6 @@ use crate::{ /// # data.clone()); /// # label /// # } -/// /// fn root() -> impl Widget { /// let list = List::new(list_item) /// .lens(AppState::list_data); @@ -135,11 +128,11 @@ use crate::{ /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; -/// /// #[derive(Clone, Data, Lens)] /// struct AppState { /// list_data: Vector, /// } +/// /// #[derive(Clone, Data, Lens)] /// struct InnerState { /// name: String, @@ -181,22 +174,22 @@ impl List { /// # use druid::widget::{ Label, List }; /// # use druid::{ Data, Lens, Widget, WidgetExt, Env}; /// # use druid::im::Vector; - /// /// # #[derive(Clone, Data, Lens)] /// # struct AppState { /// # list_data: Vector, /// # } - /// /// fn root() -> impl Widget { /// let list = List::new(list_item) /// .lens(AppState::list_data); /// list /// } + /// /// fn list_item() -> impl Widget { /// let label = Label::new(|data: &String, _env: &Env| /// data.clone()); /// label /// } + /// /// //This widget is the same as the two widgets above /// //combined. /// fn combined() -> impl Widget { From 6ad97f30c28b8cc258666d1399038470185cb4c7 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Wed, 7 Dec 2022 20:49:01 -0600 Subject: [PATCH 16/16] format --- druid/src/widget/list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druid/src/widget/list.rs b/druid/src/widget/list.rs index 10e6ceb51d..5a174029b3 100644 --- a/druid/src/widget/list.rs +++ b/druid/src/widget/list.rs @@ -132,7 +132,7 @@ use crate::{ /// struct AppState { /// list_data: Vector, /// } -/// +/// /// #[derive(Clone, Data, Lens)] /// struct InnerState { /// name: String,