summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--widget/src/column.rs12
-rw-r--r--widget/src/helpers.rs20
-rw-r--r--widget/src/keyed/column.rs13
-rw-r--r--widget/src/lazy/responsive.rs2
-rw-r--r--widget/src/row.rs12
-rw-r--r--widget/src/space.rs12
-rw-r--r--widget/src/text_input.rs8
7 files changed, 70 insertions, 9 deletions
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<impl Into<Element<'a, Message, Theme, Renderer>>>,
+ ) -> 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 e9898d67..3f2e56cd 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<Length>) -> 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<Length>) -> Space {
- Space::with_height(height)
+pub fn vertical_space() -> Space {
+ Space::with_height(Length::Fill)
}
/// Creates a horizontal [`Rule`] with the given height.
@@ -387,6 +387,18 @@ where
crate::Canvas::new(program)
}
+/// Creates a new [`QRCode`] widget from the given [`Data`].
+///
+/// [`QRCode`]: crate::QRCode
+/// [`Data`]: crate::qr_code::Data
+#[cfg(feature = "qr_code")]
+pub fn qr_code<Theme>(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<impl Into<Element<'a, Message, Theme, Renderer>>>,
+ ) -> 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/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/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<impl Into<Element<'a, Message, Theme, Renderer>>>,
+ ) -> Self {
+ if let Some(child) = child {
+ self.push(child)
+ } else {
+ self
+ }
+ }
}
impl<'a, Message, Renderer> Default for Row<'a, Message, Renderer>
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<Length>) -> Self {
+ self.width = width.into();
+ self
+ }
+
+ /// Sets the height of the [`Space`].
+ pub fn height(mut self, height: impl Into<Length>) -> Self {
+ self.height = height.into();
+ self
+ }
}
impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Space
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();