I was searching on the documentation, and saw this method is used with {trim: True}
option in .wrap()
method. Could you explain what is function of .wrap()
exactly?
Add a link to the documentation you are talking about.
Here it is
Here's the signature of the function you are talking about:
pub fn wrap(self, wrap: Wrap) -> Paragraph<'a>
As you can see, it has a wrap
parameter of type Wrap
, which is what you saw when this method was used. If you click on the Wrap
type of the documentation, you'll be taken to the documentation of this type. This is what the documentation says:
Describes how to wrap text across lines.
.
And you even get a few examples with nice comments:
let bullet_points = Text::from(r#"Some indented points:
- First thing goes here and is long so that it wraps
- Here is another point that is long enough to wrap"#);
// With leading spaces trimmed (window width of 30 chars):
Paragraph::new(bullet_points.clone()).wrap(Wrap { trim: true });
// Some indented points:
// - First thing goes here and is
// long so that it wraps
// - Here is another point that
// is long enough to wrap
// But without trimming, indentation is preserved:
Paragraph::new(bullet_points).wrap(Wrap { trim: false });
// Some indented points:
// - First thing goes here
// and is long so that it wraps
// - Here is another point
// that is long enough to wrap
I think that's a good explanation of what it does. If you still don't understand it, let me know.
2 Likes
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.