summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-01 21:36:52 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-01 21:36:52 +0200
commitb8d5df28172a9f50c8b48123df05a336801f2bdc (patch)
treea3b0f74aeff17a420d423d4c13cf40427b76e0d0
parent1d83e59e8ab51d403baee0daa878644c6a37be3f (diff)
downloadiced-b8d5df28172a9f50c8b48123df05a336801f2bdc.tar.gz
iced-b8d5df28172a9f50c8b48123df05a336801f2bdc.tar.bz2
iced-b8d5df28172a9f50c8b48123df05a336801f2bdc.zip
Reintroduce old `text` helper as `value` helper
-rw-r--r--examples/websocket/src/main.rs12
-rw-r--r--widget/src/helpers.rs13
2 files changed, 16 insertions, 9 deletions
diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs
index ef450524..369ae820 100644
--- a/examples/websocket/src/main.rs
+++ b/examples/websocket/src/main.rs
@@ -2,7 +2,7 @@ mod echo;
use iced::alignment::{self, Alignment};
use iced::widget::{
- button, column, container, row, scrollable, text, text_input,
+ button, column, container, row, scrollable, text, text_input, value,
};
use iced::{color, Command, Element, Length, Subscription};
use once_cell::sync::Lazy;
@@ -96,14 +96,8 @@ impl WebSocket {
.into()
} else {
scrollable(
- column(
- self.messages
- .iter()
- .map(ToString::to_string)
- .map(text)
- .map(Element::from),
- )
- .spacing(10),
+ column(self.messages.iter().map(value).map(Element::from))
+ .spacing(10),
)
.id(MESSAGE_LOG.clone())
.height(Length::Fill)
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index deff0261..5bfb590f 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -154,6 +154,19 @@ where
Text::new(text)
}
+/// Creates a new [`Text`] widget that displays the provided value.
+///
+/// [`Text`]: core::widget::Text
+pub fn value<'a, Theme, Renderer>(
+ value: impl ToString,
+) -> Text<'a, Theme, Renderer>
+where
+ Theme: text::Catalog + 'a,
+ Renderer: core::text::Renderer,
+{
+ Text::new(value.to_string())
+}
+
/// Creates a new [`Checkbox`].
///
/// [`Checkbox`]: crate::Checkbox