From d9fc645ca1400a78d2f0b0b4f2acfea0dc731430 Mon Sep 17 00:00:00 2001 From: Michelle Granat Date: Fri, 20 Sep 2024 14:13:40 +0300 Subject: [PATCH 1/5] Update button Catalog and Style documentation --- widget/src/button.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/widget/src/button.rs b/widget/src/button.rs index 552298bb30..89b0680cdc 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -471,6 +471,9 @@ pub enum Status { } /// The style of a button. +/// +/// If not specified with [`Button::style`] +/// the theme will provide the style. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Style { /// The [`Background`] of the button. @@ -505,6 +508,47 @@ impl Default for Style { } /// The theme catalog of a [`Button`]. +/// +/// All themes that can be used with [`Button`] +/// must implement this trait. +/// +/// # Example +/// ```no_run +/// #[derive(Debug, Default)] +/// pub enum ButtonStyles { +/// #[default] +/// Primary, +/// Secondary, +/// Danger +/// } +/// +/// impl Catalog for MyTheme { +/// type Class<'a> = ButtonStyles; +/// +/// fn default<'a>() -> Self::Class<'a> { +/// ButtonStyles::default() +/// } +/// +/// +/// fn style(&self, class: &Self::Class<'_>, status: Status) -> Style { +/// let mut style = Style::default(); +/// +/// match class { +/// ButtonStyles::Primary => { +/// style.background = Some(Background::Color(Color::from_rgb(0.529, 0.808, 0.921))); +/// }, +/// ButtonStyles::Secondary => { +/// style.background = Some(Background::Color(Color::WHITE)); +/// }, +/// ButtonStyles::Danger => { +/// style.background = Some(Background::Color(Color::from_rgb(0.941, 0.502, 0.502))); +/// }, +/// } +/// +/// style +/// } +/// } +/// ``` pub trait Catalog { /// The item class of the [`Catalog`]. type Class<'a>; From 6eac86f6ba5479d1d7473e289757fb893670110a Mon Sep 17 00:00:00 2001 From: Michelle Granat Date: Sat, 21 Sep 2024 07:39:43 +0300 Subject: [PATCH 2/5] Clarified button documentation --- widget/src/button.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/widget/src/button.rs b/widget/src/button.rs index 89b0680cdc..c7c318b683 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -515,7 +515,7 @@ impl Default for Style { /// # Example /// ```no_run /// #[derive(Debug, Default)] -/// pub enum ButtonStyles { +/// pub enum ButtonClass { /// #[default] /// Primary, /// Secondary, @@ -523,10 +523,10 @@ impl Default for Style { /// } /// /// impl Catalog for MyTheme { -/// type Class<'a> = ButtonStyles; +/// type Class<'a> = ButtonClass; /// /// fn default<'a>() -> Self::Class<'a> { -/// ButtonStyles::default() +/// ButtonClass::default() /// } /// /// @@ -534,13 +534,13 @@ impl Default for Style { /// let mut style = Style::default(); /// /// match class { -/// ButtonStyles::Primary => { +/// ButtonClass::Primary => { /// style.background = Some(Background::Color(Color::from_rgb(0.529, 0.808, 0.921))); /// }, -/// ButtonStyles::Secondary => { +/// ButtonClass::Secondary => { /// style.background = Some(Background::Color(Color::WHITE)); /// }, -/// ButtonStyles::Danger => { +/// ButtonClass::Danger => { /// style.background = Some(Background::Color(Color::from_rgb(0.941, 0.502, 0.502))); /// }, /// } @@ -549,6 +549,10 @@ impl Default for Style { /// } /// } /// ``` +/// +/// Although, in order to use [`Button::style`] +/// with `MyTheme`, [`Catalog::Class`] must implement +/// `From`. pub trait Catalog { /// The item class of the [`Catalog`]. type Class<'a>; From 83ff2a5d6a19adb3ce3812d8c72b62c1ab4eb5ca Mon Sep 17 00:00:00 2001 From: Michelle Granat Date: Mon, 23 Sep 2024 07:43:45 +0300 Subject: [PATCH 3/5] fix code typo --- widget/src/button.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget/src/button.rs b/widget/src/button.rs index c7c318b683..638199dacb 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -552,7 +552,7 @@ impl Default for Style { /// /// Although, in order to use [`Button::style`] /// with `MyTheme`, [`Catalog::Class`] must implement -/// `From`. +/// `From>`. pub trait Catalog { /// The item class of the [`Catalog`]. type Class<'a>; From 69a7778dd3a24e2b752f7b5e65fddb10f328ab74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 24 Sep 2024 22:52:42 +0200 Subject: [PATCH 4/5] Run `cargo fmt` --- widget/src/button.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/widget/src/button.rs b/widget/src/button.rs index 638199dacb..276a3d3fb4 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -471,7 +471,7 @@ pub enum Status { } /// The style of a button. -/// +/// /// If not specified with [`Button::style`] /// the theme will provide the style. #[derive(Debug, Clone, Copy, PartialEq)] @@ -508,10 +508,10 @@ impl Default for Style { } /// The theme catalog of a [`Button`]. -/// +/// /// All themes that can be used with [`Button`] /// must implement this trait. -/// +/// /// # Example /// ```no_run /// #[derive(Debug, Default)] @@ -521,7 +521,7 @@ impl Default for Style { /// Secondary, /// Danger /// } -/// +/// /// impl Catalog for MyTheme { /// type Class<'a> = ButtonClass; /// @@ -529,10 +529,10 @@ impl Default for Style { /// ButtonClass::default() /// } /// -/// +/// /// fn style(&self, class: &Self::Class<'_>, status: Status) -> Style { /// let mut style = Style::default(); -/// +/// /// match class { /// ButtonClass::Primary => { /// style.background = Some(Background::Color(Color::from_rgb(0.529, 0.808, 0.921))); @@ -544,12 +544,12 @@ impl Default for Style { /// style.background = Some(Background::Color(Color::from_rgb(0.941, 0.502, 0.502))); /// }, /// } -/// +/// /// style /// } /// } /// ``` -/// +/// /// Although, in order to use [`Button::style`] /// with `MyTheme`, [`Catalog::Class`] must implement /// `From>`. From db67aaacd1895cb7d5da1614e9c62a642e8ffb24 Mon Sep 17 00:00:00 2001 From: Michelle Granat Date: Mon, 7 Oct 2024 09:02:12 +0300 Subject: [PATCH 5/5] Fixed docs to pass tests --- widget/src/button.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/widget/src/button.rs b/widget/src/button.rs index 276a3d3fb4..a3394a013a 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -514,6 +514,9 @@ impl Default for Style { /// /// # Example /// ```no_run +/// # use iced_widget::core::{Color, Background}; +/// # use iced_widget::button::{Catalog, Status, Style}; +/// # struct MyTheme; /// #[derive(Debug, Default)] /// pub enum ButtonClass { /// #[default]