How to wrap a long text? #1864
-
fn view(&self) -> Element<'_, Self::Message> {
column::<Message, Renderer>(
vec![
// This text is very long, how to make it automatically wrap?
text("xxx...").into(),
]
).into()
} |
Beta Was this translation helpful? Give feedback.
Answered by
andretietz
May 22, 2023
Replies: 1 comment
-
Something like this would probably help: fn shorten(origin: &str, max_len: usize) -> String {
if origin.len() > max_len {
format!("{}...", &origin[..max_len])
} else {
origin.to_string()
}
} Use it so: fn view(&self) -> Element<'_, Self::Message> {
column::<Message, Renderer>(
vec![
// This text is very long, how to make it automatically wrap?
text(shorten("long text", 4)).into(), // will turn into "long..."
]
).into()
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
yk0n9
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this would probably help:
Use it so: