Use for loop instead of fold in span_bounds
This commit is contained in:
parent
2d69464846
commit
2e4c55bbff
1 changed files with 27 additions and 27 deletions
|
|
@ -254,9 +254,10 @@ impl core::text::Paragraph for Paragraph {
|
||||||
fn span_bounds(&self, index: usize) -> Vec<Rectangle> {
|
fn span_bounds(&self, index: usize) -> Vec<Rectangle> {
|
||||||
let internal = self.internal();
|
let internal = self.internal();
|
||||||
|
|
||||||
|
let mut bounds = Vec::new();
|
||||||
let mut current_bounds = None;
|
let mut current_bounds = None;
|
||||||
|
|
||||||
let mut bounds = internal
|
let glyphs = internal
|
||||||
.buffer
|
.buffer
|
||||||
.layout_runs()
|
.layout_runs()
|
||||||
.flat_map(|run| {
|
.flat_map(|run| {
|
||||||
|
|
@ -268,8 +269,9 @@ impl core::text::Paragraph for Paragraph {
|
||||||
.map(move |glyph| (line_top, line_height, glyph))
|
.map(move |glyph| (line_top, line_height, glyph))
|
||||||
})
|
})
|
||||||
.skip_while(|(_, _, glyph)| glyph.metadata != index)
|
.skip_while(|(_, _, glyph)| glyph.metadata != index)
|
||||||
.take_while(|(_, _, glyph)| glyph.metadata == index)
|
.take_while(|(_, _, glyph)| glyph.metadata == index);
|
||||||
.fold(vec![], |mut spans, (line_top, line_height, glyph)| {
|
|
||||||
|
for (line_top, line_height, glyph) in glyphs {
|
||||||
let y = line_top + glyph.y;
|
let y = line_top + glyph.y;
|
||||||
|
|
||||||
let new_bounds = || {
|
let new_bounds = || {
|
||||||
|
|
@ -286,17 +288,15 @@ impl core::text::Paragraph for Paragraph {
|
||||||
None => {
|
None => {
|
||||||
current_bounds = Some(new_bounds());
|
current_bounds = Some(new_bounds());
|
||||||
}
|
}
|
||||||
Some(bounds) if y != bounds.y => {
|
Some(current_bounds) if y != current_bounds.y => {
|
||||||
spans.push(*bounds);
|
bounds.push(*current_bounds);
|
||||||
*bounds = new_bounds();
|
*current_bounds = new_bounds();
|
||||||
|
}
|
||||||
|
Some(current_bounds) => {
|
||||||
|
current_bounds.width += glyph.w;
|
||||||
}
|
}
|
||||||
Some(bounds) => {
|
|
||||||
bounds.width += glyph.w;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spans
|
|
||||||
});
|
|
||||||
|
|
||||||
bounds.extend(current_bounds);
|
bounds.extend(current_bounds);
|
||||||
bounds
|
bounds
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue