Skip to content

How to wrap a long text? #1864

Answered by andretietz
yk0n9 asked this question in Q&A
Discussion options

You must be logged in to vote

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()
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yk0n9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants