From 9dd20ead085ff3b9b4bd441b5e4938cf8e813f35 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 15 Feb 2024 02:01:56 +0100 Subject: Rename `password` method in `TextInput` to `secure` --- widget/src/text_input.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'widget/src') diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index f5b57422..72ed1ef3 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -122,8 +122,8 @@ where } /// Converts the [`TextInput`] into a secure password input. - pub fn password(mut self) -> Self { - self.is_secure = true; + pub fn secure(mut self, is_secure: bool) -> Self { + self.is_secure = is_secure; self } @@ -991,9 +991,9 @@ where } return event::Status::Captured; - } else { - state.is_pasting = None; } + + state.is_pasting = None; } Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => { let state = state(); -- cgit From e8049af23dbf4988ff24b75b90104295f61098a2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 15 Feb 2024 02:08:22 +0100 Subject: Make `horizontal_space` and `vertical_space` fill by default --- widget/src/helpers.rs | 8 ++++---- widget/src/lazy/responsive.rs | 2 +- widget/src/space.rs | 12 ++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'widget/src') diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index e9898d67..400fced5 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -305,15 +305,15 @@ where /// Creates a new horizontal [`Space`] with the given [`Length`]. /// /// [`Space`]: crate::Space -pub fn horizontal_space(width: impl Into) -> Space { - Space::with_width(width) +pub fn horizontal_space() -> Space { + Space::with_width(Length::Fill) } /// Creates a new vertical [`Space`] with the given [`Length`]. /// /// [`Space`]: crate::Space -pub fn vertical_space(height: impl Into) -> Space { - Space::with_height(height) +pub fn vertical_space() -> Space { + Space::with_height(Length::Fill) } /// Creates a horizontal [`Rule`] with the given height. diff --git a/widget/src/lazy/responsive.rs b/widget/src/lazy/responsive.rs index 44312a21..313e1edb 100644 --- a/widget/src/lazy/responsive.rs +++ b/widget/src/lazy/responsive.rs @@ -50,7 +50,7 @@ where content: RefCell::new(Content { size: Size::ZERO, layout: None, - element: Element::new(horizontal_space(0)), + element: Element::new(horizontal_space().width(0)), }), } } diff --git a/widget/src/space.rs b/widget/src/space.rs index aeec91f9..35bb30c4 100644 --- a/widget/src/space.rs +++ b/widget/src/space.rs @@ -39,6 +39,18 @@ impl Space { height: height.into(), } } + + /// Sets the width of the [`Space`]. + pub fn width(mut self, width: impl Into) -> Self { + self.width = width.into(); + self + } + + /// Sets the height of the [`Space`]. + pub fn height(mut self, height: impl Into) -> Self { + self.height = height.into(); + self + } } impl Widget for Space -- cgit From feab96f323189ebae070a5d025531f86e436e21f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 15 Feb 2024 02:38:07 +0100 Subject: Add `push_maybe` to `Column` and `Row` --- widget/src/column.rs | 12 ++++++++++++ widget/src/helpers.rs | 12 ++++++++++++ widget/src/keyed/column.rs | 13 +++++++++++++ widget/src/row.rs | 12 ++++++++++++ 4 files changed, 49 insertions(+) (limited to 'widget/src') diff --git a/widget/src/column.rs b/widget/src/column.rs index 8154ad85..b9eb5d93 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -115,6 +115,18 @@ where self.children.push(child); self } + + /// Adds an element to the [`Column`], if `Some`. + pub fn push_maybe( + self, + child: Option>>, + ) -> Self { + if let Some(child) = child { + self.push(child) + } else { + self + } + } } impl<'a, Message, Renderer> Default for Column<'a, Message, Renderer> diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index 400fced5..6ae35aee 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -387,6 +387,18 @@ where crate::Canvas::new(program) } +/// Creates a new [`QRCode`] widget from the given [`Data`]. +/// +/// [`Svg`]: crate::QRCode +/// [`Data`]: crate::qr_code::Data +#[cfg(feature = "qr_code")] +pub fn qr_code(data: &crate::qr_code::Data) -> crate::QRCode<'_, Theme> +where + Theme: crate::qr_code::StyleSheet, +{ + crate::QRCode::new(data) +} + /// Creates a new [`Shader`]. /// /// [`Shader`]: crate::Shader diff --git a/widget/src/keyed/column.rs b/widget/src/keyed/column.rs index 88a6e503..ce74e701 100644 --- a/widget/src/keyed/column.rs +++ b/widget/src/keyed/column.rs @@ -124,6 +124,19 @@ where self.children.push(child); self } + + /// Adds an element to the [`Column`], if `Some`. + pub fn push_maybe( + self, + key: Key, + child: Option>>, + ) -> Self { + if let Some(child) = child { + self.push(key, child) + } else { + self + } + } } impl<'a, Key, Message, Renderer> Default for Column<'a, Key, Message, Renderer> diff --git a/widget/src/row.rs b/widget/src/row.rs index 735fbbc0..20b47a41 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -106,6 +106,18 @@ where self.children.push(child); self } + + /// Adds an element to the [`Row`], if `Some`. + pub fn push_maybe( + self, + child: Option>>, + ) -> Self { + if let Some(child) = child { + self.push(child) + } else { + self + } + } } impl<'a, Message, Renderer> Default for Row<'a, Message, Renderer> -- cgit From 777e2e34f50c440f59d9a407f75be80fbbfaccae Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 15 Feb 2024 02:47:35 +0100 Subject: Fix documentation for `qr_code` widget helper --- widget/src/helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'widget/src') diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index 6ae35aee..3f2e56cd 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -389,7 +389,7 @@ where /// Creates a new [`QRCode`] widget from the given [`Data`]. /// -/// [`Svg`]: crate::QRCode +/// [`QRCode`]: crate::QRCode /// [`Data`]: crate::qr_code::Data #[cfg(feature = "qr_code")] pub fn qr_code(data: &crate::qr_code::Data) -> crate::QRCode<'_, Theme> -- cgit