From 3fabfec662c38f64ba5e126d5a6af232817c2b57 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Thu, 27 Oct 2022 20:48:59 -0500 Subject: [PATCH 01/11] adding documentation examples for textbox --- druid/src/widget/textbox.rs | 102 ++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index c525f43e7d..f452abe4cf 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -78,6 +78,24 @@ pub struct TextBox { impl TextBox { /// Create a new TextBox widget. + /// + /// # Examples + /// + /// ``` + /// use druid::widget::TextBox; + /// use druid::WidgetExt; + /// #[derive(Clone, Data, Lens)] + /// struct AppState { + /// name: String, + /// } + /// + /// let _: TextBox = TextBox::new() + /// .lens(AppState::name); + /// + /// let _ = TextBox::new() + /// .with_placeholder("placeholder text") + /// .lens(AppState::name); + /// ``` pub fn new() -> Self { let placeholder_text = ArcStr::from(""); let mut placeholder_layout = TextLayout::new(); @@ -105,6 +123,13 @@ impl TextBox { } /// Create a new multi-line `TextBox`. + /// + /// # Examples + /// + /// ``` + /// let multiline = TextBox::multiline() + /// .lens(AppState::name); + /// ``` pub fn multiline() -> Self { let mut this = TextBox::new(); this.inner @@ -121,6 +146,27 @@ impl TextBox { /// If `false`, lines will not be wrapped, and horizontal scrolling will /// be enabled. /// + /// # Examples + /// + /// ``` + /// //will scroll horizontally + /// let scroll_text_box = TextBox::new() + /// .with_line_wrapping(false) + /// .lens(AppState::name); + /// //will wrap only for a single line + /// let wrap_text_box = TextBox::new() + /// .with_line_wrapping(true) + /// .lens(AppState::name); + /// //will scroll as well as having multiple lines + /// let scroll_multi_line_text_box = TextBox::multiline() + /// .with_line_wrapping(false) + /// .lens(AppState::name); + /// //will wrap for each line + /// let wrap_multi_line_text_box = TextBox::multiline() + /// .with_line_wrapping(true) // this is default can be removed for the same result + /// .lens(AppState::name); + /// + /// ``` /// [`multiline`]: TextBox::multiline pub fn with_line_wrapping(mut self, wrap_lines: bool) -> Self { self.inner.set_horizontal_scroll_enabled(!wrap_lines); @@ -133,6 +179,23 @@ impl TextBox { /// /// The argument can be either an `f64` or a [`Key`]. /// + /// # Examples + /// + /// ``` + /// let text_box = TextBox::new() + /// .with_text_size(14.) + /// .lens(AppState::name); + /// ``` + /// + /// ``` + /// use druid::Key; + /// + /// const FONT_SIZE : Key = Key::new("font-size"); + /// + /// let text_box = TextBox::new() + /// .with_text_size(FONT_SIZE) + /// .lens(AppState::name); + /// ``` /// [`Key`]: ../struct.Key.html pub fn with_text_size(mut self, size: impl Into>) -> Self { self.set_text_size(size); @@ -155,6 +218,15 @@ impl TextBox { /// This should be considered a bug, but it will not be fixed until proper /// BiDi support is implemented. /// + /// # Examples + /// ``` + /// use druid::TextAlignment; + /// + /// let text_box = TextBox::new() + /// .with_text_alignment(TextAlignment::Center) + /// .lens(AppState::name); + /// ``` + /// /// [`TextAlignment`]: enum.TextAlignment.html /// [`multiline`]: #method.multiline pub fn with_text_alignment(mut self, alignment: TextAlignment) -> Self { @@ -166,6 +238,23 @@ impl TextBox { /// /// The argument can be a [`FontDescriptor`] or a [`Key`] /// that refers to a font defined in the [`Env`]. + /// + /// # Examples + /// + /// ``` + /// use druid::{ FontDescriptor, FontFamily }; + /// + /// const FONT : Key Key::new("font"); + /// + /// let text_box = TextBox::new() + /// .with_font(FontDescriptor::new(FontFamily::MONOSPACE)) + /// .lens(AppState::name); + /// + /// let text_box = TextBox::new() + /// .with_font(FONT) + /// .lens(AppState::name); + /// ``` + /// /// /// [`Env`]: ../struct.Env.html /// [`FontDescriptor`]: ../struct.FontDescriptor.html @@ -178,7 +267,20 @@ impl TextBox { /// Builder-style method for setting the text color. /// /// The argument can be either a `Color` or a [`Key`]. + /// # Examples + /// ``` + /// use druid::Color; + /// + /// const COLOR : Key Key::new("color"); + /// + /// let text_box = TextBox::new() + /// .with_text_color(Color::RED) + /// .lens(AppState::name); /// + /// let text_box = TextBox::new() + /// .with_font(COLOR) + /// .lens(AppState::name); + /// ``` /// [`Key`]: ../struct.Key.html pub fn with_text_color(mut self, color: impl Into>) -> Self { self.set_text_color(color); From 88eb664cb173849c9a49a88a5f58be3a39f70ab9 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Thu, 27 Oct 2022 21:01:23 -0500 Subject: [PATCH 02/11] adding in changelog and author --- AUTHORS | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index d22772a73c..41bdaf7103 100644 --- a/AUTHORS +++ b/AUTHORS @@ -22,3 +22,4 @@ Tim Murison Manmeet Singh Simon Fell Nick Larsen +Thomas McAndrew diff --git a/CHANGELOG.md b/CHANGELOG.md index 536c8979ed..a44eaed93e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -150,6 +150,7 @@ You can find its changes [documented below](#070---2021-01-01). - Update docs of `RawLabel`: does not require `ArcStr`([#1886] by [@Maan2003]) - Fix `Controller` links for `Click` ([#2158] by [@yrns]) - Delete inaccurate line for `KeyEvent` ([#2247] by [@amtep]) +- Added examples in `TextBox` ([] by [@ThomasMcAndrew]) ### Examples - Add readme ([#1423] by [@JAicewizard]) From db9aeb8674d03c0f2049d07d5df1d25c0fa90d79 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Thu, 27 Oct 2022 21:04:50 -0500 Subject: [PATCH 03/11] formating --- druid/src/widget/textbox.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index f452abe4cf..f1b00c40df 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -84,6 +84,7 @@ impl TextBox { /// ``` /// use druid::widget::TextBox; /// use druid::WidgetExt; + /// /// #[derive(Clone, Data, Lens)] /// struct AppState { /// name: String, @@ -153,14 +154,17 @@ impl TextBox { /// let scroll_text_box = TextBox::new() /// .with_line_wrapping(false) /// .lens(AppState::name); + /// /// //will wrap only for a single line /// let wrap_text_box = TextBox::new() /// .with_line_wrapping(true) /// .lens(AppState::name); + /// /// //will scroll as well as having multiple lines /// let scroll_multi_line_text_box = TextBox::multiline() /// .with_line_wrapping(false) /// .lens(AppState::name); + /// /// //will wrap for each line /// let wrap_multi_line_text_box = TextBox::multiline() /// .with_line_wrapping(true) // this is default can be removed for the same result From 0ef1f0735f044263935c64b028a707418a566b7a Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Fri, 28 Oct 2022 06:18:58 -0500 Subject: [PATCH 04/11] adding imports to documentation --- druid/src/widget/textbox.rs | 58 +++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index f1b00c40df..b44076d95b 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -83,16 +83,13 @@ impl TextBox { /// /// ``` /// use druid::widget::TextBox; - /// use druid::WidgetExt; + /// use druid::{ WidgetExt, Lens }; /// /// #[derive(Clone, Data, Lens)] /// struct AppState { /// name: String, /// } /// - /// let _: TextBox = TextBox::new() - /// .lens(AppState::name); - /// /// let _ = TextBox::new() /// .with_placeholder("placeholder text") /// .lens(AppState::name); @@ -128,6 +125,13 @@ impl TextBox { /// # Examples /// /// ``` + /// # use druid::widget::TextBox; + /// # use druid::{ WidgetExt, Lens }; + /// # + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # name: String, + /// # } /// let multiline = TextBox::multiline() /// .lens(AppState::name); /// ``` @@ -150,6 +154,13 @@ impl TextBox { /// # Examples /// /// ``` + /// # use druid::widget::TextBox; + /// # use druid::{ WidgetExt, Lens }; + /// # + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # name: String, + /// # } /// //will scroll horizontally /// let scroll_text_box = TextBox::new() /// .with_line_wrapping(false) @@ -186,12 +197,26 @@ impl TextBox { /// # Examples /// /// ``` + /// # use druid::widget::TextBox; + /// # use druid::{ WidgetExt, Lens }; + /// # + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # name: String, + /// # } /// let text_box = TextBox::new() /// .with_text_size(14.) /// .lens(AppState::name); /// ``` /// /// ``` + /// # use druid::widget::TextBox; + /// # use druid::{ WidgetExt, Lens }; + /// # + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # name: String, + /// # } /// use druid::Key; /// /// const FONT_SIZE : Key = Key::new("font-size"); @@ -224,6 +249,13 @@ impl TextBox { /// /// # Examples /// ``` + /// # use druid::widget::TextBox; + /// # use druid::{ WidgetExt, Lens }; + /// # + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # name: String, + /// # } /// use druid::TextAlignment; /// /// let text_box = TextBox::new() @@ -242,10 +274,17 @@ impl TextBox { /// /// The argument can be a [`FontDescriptor`] or a [`Key`] /// that refers to a font defined in the [`Env`]. - /// - /// # Examples + /// + /// # Examples /// /// ``` + /// # use druid::widget::TextBox; + /// # use druid::{ WidgetExt, Lens }; + /// # + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # name: String, + /// # } /// use druid::{ FontDescriptor, FontFamily }; /// /// const FONT : Key Key::new("font"); @@ -273,6 +312,13 @@ impl TextBox { /// The argument can be either a `Color` or a [`Key`]. /// # Examples /// ``` + /// # use druid::widget::TextBox; + /// # use druid::{ WidgetExt, Lens }; + /// # + /// # #[derive(Clone, Data, Lens)] + /// # struct AppState { + /// # name: String, + /// # } /// use druid::Color; /// /// const COLOR : Key Key::new("color"); From 73505e28f5cf5f58b123c2b82c1d2e6f619a61c3 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Fri, 28 Oct 2022 06:27:17 -0500 Subject: [PATCH 05/11] adding imports to documentation --- druid/src/widget/textbox.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index b44076d95b..ab8bc5f82b 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -83,7 +83,7 @@ impl TextBox { /// /// ``` /// use druid::widget::TextBox; - /// use druid::{ WidgetExt, Lens }; + /// use druid::{ WidgetExt, Data, Lens }; /// /// #[derive(Clone, Data, Lens)] /// struct AppState { @@ -126,7 +126,7 @@ impl TextBox { /// /// ``` /// # use druid::widget::TextBox; - /// # use druid::{ WidgetExt, Lens }; + /// # use druid::{ WidgetExt, Data, Lens }; /// # /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -155,7 +155,7 @@ impl TextBox { /// /// ``` /// # use druid::widget::TextBox; - /// # use druid::{ WidgetExt, Lens }; + /// # use druid::{ WidgetExt, Data, Lens }; /// # /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -198,7 +198,7 @@ impl TextBox { /// /// ``` /// # use druid::widget::TextBox; - /// # use druid::{ WidgetExt, Lens }; + /// # use druid::{ WidgetExt, Data, Lens }; /// # /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -211,7 +211,7 @@ impl TextBox { /// /// ``` /// # use druid::widget::TextBox; - /// # use druid::{ WidgetExt, Lens }; + /// # use druid::{ WidgetExt, Data, Lens }; /// # /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -250,7 +250,7 @@ impl TextBox { /// # Examples /// ``` /// # use druid::widget::TextBox; - /// # use druid::{ WidgetExt, Lens }; + /// # use druid::{ WidgetExt, Data, Lens }; /// # /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -279,7 +279,7 @@ impl TextBox { /// /// ``` /// # use druid::widget::TextBox; - /// # use druid::{ WidgetExt, Lens }; + /// # use druid::{ WidgetExt, Data, Lens }; /// # /// # #[derive(Clone, Data, Lens)] /// # struct AppState { @@ -313,7 +313,7 @@ impl TextBox { /// # Examples /// ``` /// # use druid::widget::TextBox; - /// # use druid::{ WidgetExt, Lens }; + /// # use druid::{ WidgetExt, Data, Lens }; /// # /// # #[derive(Clone, Data, Lens)] /// # struct AppState { From b79b25e257411497a4d5f310af0a3e492ac12a16 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Fri, 28 Oct 2022 06:35:30 -0500 Subject: [PATCH 06/11] adding imports to documentation --- druid/src/widget/textbox.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index ab8bc5f82b..86859775b9 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -287,7 +287,7 @@ impl TextBox { /// # } /// use druid::{ FontDescriptor, FontFamily }; /// - /// const FONT : Key Key::new("font"); + /// const FONT : Key = Key::new("font"); /// /// let text_box = TextBox::new() /// .with_font(FontDescriptor::new(FontFamily::MONOSPACE)) @@ -319,9 +319,9 @@ impl TextBox { /// # struct AppState { /// # name: String, /// # } - /// use druid::Color; + /// use druid::{ Color, Key }; /// - /// const COLOR : Key Key::new("color"); + /// const COLOR : Key = Key::new("color"); /// /// let text_box = TextBox::new() /// .with_text_color(Color::RED) From 8b157d853f4acc09d717ef16f1d4bd870651e686 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Fri, 28 Oct 2022 06:57:47 -0500 Subject: [PATCH 07/11] format --- druid/src/widget/textbox.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index 86859775b9..90924fcba4 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -285,7 +285,7 @@ impl TextBox { /// # struct AppState { /// # name: String, /// # } - /// use druid::{ FontDescriptor, FontFamily }; + /// use druid::{ FontDescriptor, FontFamily, Key }; /// /// const FONT : Key = Key::new("font"); /// @@ -328,7 +328,7 @@ impl TextBox { /// .lens(AppState::name); /// /// let text_box = TextBox::new() - /// .with_font(COLOR) + /// .with_text_color(COLOR) /// .lens(AppState::name); /// ``` /// [`Key`]: ../struct.Key.html From 1b56d6b7947c7028a4f8c405b7a4707aa9174541 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Sat, 29 Oct 2022 06:35:02 -0500 Subject: [PATCH 08/11] updating guess for PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a44eaed93e..bc12218fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -150,7 +150,7 @@ You can find its changes [documented below](#070---2021-01-01). - Update docs of `RawLabel`: does not require `ArcStr`([#1886] by [@Maan2003]) - Fix `Controller` links for `Click` ([#2158] by [@yrns]) - Delete inaccurate line for `KeyEvent` ([#2247] by [@amtep]) -- Added examples in `TextBox` ([] by [@ThomasMcAndrew]) +- Added examples in `TextBox` ([#2280] by [@ThomasMcAndrew]) ### Examples - Add readme ([#1423] by [@JAicewizard]) From 9da3aa71cc9c50241fd65c53516d7cfbcc406b03 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Mon, 28 Nov 2022 08:45:44 -0600 Subject: [PATCH 09/11] updating changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc12218fd2..6c2724ac8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -150,7 +150,7 @@ You can find its changes [documented below](#070---2021-01-01). - Update docs of `RawLabel`: does not require `ArcStr`([#1886] by [@Maan2003]) - Fix `Controller` links for `Click` ([#2158] by [@yrns]) - Delete inaccurate line for `KeyEvent` ([#2247] by [@amtep]) -- Added examples in `TextBox` ([#2280] by [@ThomasMcAndrew]) +- Added examples in `TextBox` ([#2284] by [@ThomasMcAndrew]) ### Examples - Add readme ([#1423] by [@JAicewizard]) @@ -565,6 +565,7 @@ Last release without a changelog :( [@NickLarsenNZ]: https://github.com/NickLarsenNZ [@barsae]: https://github.com/barsae [@amtep]: https://github.com/amtep +[@ThomasMcandrew]: https:github.com/ThomasMcandrew [#599]: https://github.com/linebender/druid/pull/599 [#611]: https://github.com/linebender/druid/pull/611 @@ -863,6 +864,7 @@ Last release without a changelog :( [#2203]: https://github.com/linebender/druid/pull/2203 [#2235]: https://github.com/linebender/druid/pull/2235 [#2247]: https://github.com/linebender/druid/pull/2247 +[#2284]: https://github.com/linebender/druid/pull/2284 [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 [0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0 From 899b53073df372a2ed02c7fca869952212192fa7 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Tue, 29 Nov 2022 18:32:22 -0600 Subject: [PATCH 10/11] updating changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c2724ac8b..9166511187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -150,7 +150,7 @@ You can find its changes [documented below](#070---2021-01-01). - Update docs of `RawLabel`: does not require `ArcStr`([#1886] by [@Maan2003]) - 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 `TextBox` ([#2284] by [@ThomasMcandrew]) ### Examples - Add readme ([#1423] by [@JAicewizard]) From 5c566880c9c5d33d165a7feef315935328e9c672 Mon Sep 17 00:00:00 2001 From: ThomasMcAndrew Date: Thu, 1 Dec 2022 07:07:23 -0600 Subject: [PATCH 11/11] changing wording for comment --- druid/src/widget/textbox.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index 90924fcba4..abccd1d616 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -178,7 +178,7 @@ impl TextBox { /// /// //will wrap for each line /// let wrap_multi_line_text_box = TextBox::multiline() - /// .with_line_wrapping(true) // this is default can be removed for the same result + /// .with_line_wrapping(true) // this is default and can be removed for the same result /// .lens(AppState::name); /// /// ```