Store Styled with contiguous string
The previous implementation of Styled used chunks that consisted of a String and a ContentStyle. The current implementation instead stores a single String and chunks consisting of a ContentStyle and an ending index. This implementation may reduce allocations and makes width-related operations easier, for example getting the width of a Styled with its whitespace trimmed.
This commit is contained in:
parent
464aefa6d7
commit
26a8936cf5
4 changed files with 149 additions and 146 deletions
|
|
@ -31,7 +31,7 @@ fn draw(f: &mut Frame) {
|
|||
);
|
||||
|
||||
let breaks = f.wrap(text, f.size().width.into());
|
||||
let lines = Styled::default().then(text).split_at_indices(&breaks);
|
||||
let lines = Styled::new_plain(text).split_at_indices(&breaks);
|
||||
for (i, mut line) in lines.into_iter().enumerate() {
|
||||
line.trim_end();
|
||||
f.write(Pos::new(0, i as i32), line);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue