Reintroduce old text helper as value helper

This commit is contained in:
Héctor Ramón Jiménez 2024-04-01 21:36:52 +02:00
parent 1d83e59e8a
commit b8d5df2817
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 16 additions and 9 deletions

View file

@ -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)

View file

@ -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