From 9ba955842913c9e1060bdb98deef9d645917b5cb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 15 Feb 2021 23:59:31 +0100 Subject: Allow dead code explicitly in `iced_web` --- web/src/widget/button.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web/src/widget/button.rs') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index e7cff6a0..7c389a9f 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -25,8 +25,10 @@ pub struct Button<'a, Message> { content: Element<'a, Message>, on_press: Option, width: Length, + #[allow(dead_code)] height: Length, min_width: u32, + #[allow(dead_code)] min_height: u32, padding: u16, style: Box, -- cgit From fe0a27c56d9d75fb521e69352259f1d737402a20 Mon Sep 17 00:00:00 2001 From: Ben LeFevre Date: Mon, 23 Nov 2020 17:19:21 +0000 Subject: Add support for asymmetrical padding --- web/src/widget/button.rs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'web/src/widget/button.rs') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 7c389a9f..0e75fa3f 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -1,7 +1,7 @@ //! Allow your users to perform actions by pressing a button. //! //! A [`Button`] has some local [`State`]. -use crate::{css, Background, Bus, Css, Element, Length, Widget}; +use crate::{css, Background, Bus, Css, Element, Length, Padding, Widget}; pub use iced_style::button::{Style, StyleSheet}; @@ -30,7 +30,7 @@ pub struct Button<'a, Message> { min_width: u32, #[allow(dead_code)] min_height: u32, - padding: u16, + padding: Padding, style: Box, } @@ -48,7 +48,7 @@ impl<'a, Message> Button<'a, Message> { height: Length::Shrink, min_width: 0, min_height: 0, - padding: 5, + padding: Padding::new(5), style: Default::default(), } } @@ -77,9 +77,14 @@ impl<'a, Message> Button<'a, Message> { self } - /// Sets the padding of the [`Button`]. - pub fn padding(mut self, padding: u16) -> Self { - self.padding = padding; + /// Sets the [`Padding`] of the [`Button`]. + ///```ignore + /// Button::new(/*...*/).padding(20); // 20px on all sides + /// Button::new(/*...*/).padding([10, 20]); // top/bottom, left/right + /// Button::new(/*...*/).padding([5, 10, 15, 20]); // top, right, bottom, left + /// ``` + pub fn padding>(mut self, padding: P) -> Self { + self.padding = padding.into(); self } @@ -122,9 +127,6 @@ where // TODO: State-based styling let style = self.style.active(); - let padding_class = - style_sheet.insert(bump, css::Rule::Padding(self.padding)); - let background = match style.background { None => String::from("none"), Some(background) => match background { @@ -132,25 +134,19 @@ where }, }; - let class = { - use dodrio::bumpalo::collections::String; - - String::from_str_in(&padding_class, bump).into_bump_str() - }; - let mut node = button(bump) - .attr("class", class) .attr( "style", bumpalo::format!( in bump, "background: {}; border-radius: {}px; width:{}; \ - min-width: {}; color: {}", + min-width: {}; color: {}; padding: {}", background, style.border_radius, css::length(self.width), css::min_length(self.min_width), - css::color(style.text_color) + css::color(style.text_color), + css::padding(self.padding) ) .into_bump_str(), ) -- cgit From 8a3b71df8b619571ce0a972826cb5a3987b66b3d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Tue, 1 Jun 2021 19:45:47 +0700 Subject: Replace ignored doc-tests with additional documentation for `Padding` --- web/src/widget/button.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'web/src/widget/button.rs') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 0e75fa3f..8a36aab9 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -78,11 +78,6 @@ impl<'a, Message> Button<'a, Message> { } /// Sets the [`Padding`] of the [`Button`]. - ///```ignore - /// Button::new(/*...*/).padding(20); // 20px on all sides - /// Button::new(/*...*/).padding([10, 20]); // top/bottom, left/right - /// Button::new(/*...*/).padding([5, 10, 15, 20]); // top, right, bottom, left - /// ``` pub fn padding>(mut self, padding: P) -> Self { self.padding = padding.into(); self -- cgit From dbc1181011d579ac1da2546fba08e11094633f4b Mon Sep 17 00:00:00 2001 From: Jonas Matser Date: Tue, 1 Dec 2020 11:52:52 +0100 Subject: Adds doc comment for disabled button Makes disabled button behavior consistent in web --- web/src/widget/button.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'web/src/widget/button.rs') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 8a36aab9..7c8612f6 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -20,6 +20,14 @@ use dodrio::bumpalo; /// let button = Button::new(&mut state, Text::new("Press me!")) /// .on_press(Message::ButtonPressed); /// ``` +/// +/// Buttons can be disabled by not having an on_press. +/// +/// ``` +/// let mut state = button::State::new(); +/// let disabled_button = Button::new(&mut state, Text::new("I'm disabled!")); +/// ``` + #[allow(missing_debug_implementations)] pub struct Button<'a, Message> { content: Element<'a, Message>, @@ -90,6 +98,7 @@ impl<'a, Message> Button<'a, Message> { } /// Sets the message that will be produced when the [`Button`] is pressed. + /// If on_press isn't set, button will be disabled. pub fn on_press(mut self, msg: Message) -> Self { self.on_press = Some(msg); self @@ -153,6 +162,8 @@ where node = node.on("click", move |_root, _vdom, _event| { event_bus.publish(on_press.clone()); }); + } else { + node = node.attr("disabled", ""); } node.finish() -- cgit From e66120b9c1d3998085de7422edaac778e4ebf3e3 Mon Sep 17 00:00:00 2001 From: Jonas Matser Date: Tue, 1 Dec 2020 14:28:40 +0100 Subject: Fix failing doctests --- web/src/widget/button.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'web/src/widget/button.rs') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 7c8612f6..6afcaee3 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -24,8 +24,14 @@ use dodrio::bumpalo; /// Buttons can be disabled by not having an on_press. /// /// ``` +/// # use iced_web::{button, Button, Text}; +/// # +/// # enum Message { +/// # ButtonPressed, +/// # } +/// # /// let mut state = button::State::new(); -/// let disabled_button = Button::new(&mut state, Text::new("I'm disabled!")); +/// let disabled_button = Button::::new(&mut state, Text::new("I'm disabled!")); /// ``` #[allow(missing_debug_implementations)] -- cgit From d46dd67a91731177406570aae5e921a728b8c2b4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Thu, 10 Jun 2021 18:40:32 +0700 Subject: Update disabled example of `Button` in docs --- web/src/widget/button.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'web/src/widget/button.rs') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 6afcaee3..cd450b55 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -21,19 +21,25 @@ use dodrio::bumpalo; /// .on_press(Message::ButtonPressed); /// ``` /// -/// Buttons can be disabled by not having an on_press. +/// If a [`Button::on_press`] handler is not set, the resulting [`Button`] will +/// be disabled: /// /// ``` /// # use iced_web::{button, Button, Text}; /// # -/// # enum Message { -/// # ButtonPressed, -/// # } -/// # -/// let mut state = button::State::new(); -/// let disabled_button = Button::::new(&mut state, Text::new("I'm disabled!")); +/// #[derive(Clone)] +/// enum Message { +/// ButtonPressed, +/// } +/// +/// fn disabled_button(state: &mut button::State) -> Button<'_, Message> { +/// Button::new(state, Text::new("I'm disabled!")) +/// } +/// +/// fn enabled_button(state: &mut button::State) -> Button<'_, Message> { +/// disabled_button(state).on_press(Message::ButtonPressed) +/// } /// ``` - #[allow(missing_debug_implementations)] pub struct Button<'a, Message> { content: Element<'a, Message>, -- cgit