Take an Iterator
of TextArea
in prepare
This commit is contained in:
parent
7f31965063
commit
0857bef584
3 changed files with 10 additions and 8 deletions
|
@ -101,7 +101,7 @@ async fn run() {
|
||||||
width: config.width,
|
width: config.width,
|
||||||
height: config.height,
|
height: config.height,
|
||||||
},
|
},
|
||||||
&[TextArea {
|
[TextArea {
|
||||||
buffer: &buffer,
|
buffer: &buffer,
|
||||||
left: 10,
|
left: 10,
|
||||||
top: 10,
|
top: 10,
|
||||||
|
@ -112,7 +112,8 @@ async fn run() {
|
||||||
bottom: 160,
|
bottom: 160,
|
||||||
},
|
},
|
||||||
default_color: Color::rgb(255, 255, 255),
|
default_color: Color::rgb(255, 255, 255),
|
||||||
}],
|
}]
|
||||||
|
.into_iter(),
|
||||||
&mut cache,
|
&mut cache,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -96,6 +96,7 @@ impl Default for TextBounds {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A text area containing text to be rendered along with its overflow behavior.
|
/// A text area containing text to be rendered along with its overflow behavior.
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct TextArea<'a> {
|
pub struct TextArea<'a> {
|
||||||
/// The buffer containing the text to be rendered.
|
/// The buffer containing the text to be rendered.
|
||||||
pub buffer: &'a Buffer,
|
pub buffer: &'a Buffer,
|
||||||
|
|
|
@ -61,14 +61,14 @@ impl TextRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepares all of the provided text areas for rendering.
|
/// Prepares all of the provided text areas for rendering.
|
||||||
pub fn prepare_with_depth(
|
pub fn prepare_with_depth<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
device: &Device,
|
device: &Device,
|
||||||
queue: &Queue,
|
queue: &Queue,
|
||||||
font_system: &mut FontSystem,
|
font_system: &mut FontSystem,
|
||||||
atlas: &mut TextAtlas,
|
atlas: &mut TextAtlas,
|
||||||
screen_resolution: Resolution,
|
screen_resolution: Resolution,
|
||||||
text_areas: &[TextArea<'_>],
|
text_areas: impl Iterator<Item = TextArea<'a>> + Clone,
|
||||||
cache: &mut SwashCache,
|
cache: &mut SwashCache,
|
||||||
mut metadata_to_depth: impl FnMut(usize) -> f32,
|
mut metadata_to_depth: impl FnMut(usize) -> f32,
|
||||||
) -> Result<(), PrepareError> {
|
) -> Result<(), PrepareError> {
|
||||||
|
@ -86,7 +86,7 @@ impl TextRenderer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for text_area in text_areas.iter() {
|
for text_area in text_areas.clone() {
|
||||||
for run in text_area.buffer.layout_runs() {
|
for run in text_area.buffer.layout_runs() {
|
||||||
for glyph in run.glyphs.iter() {
|
for glyph in run.glyphs.iter() {
|
||||||
if atlas.mask_atlas.glyph_cache.contains(&glyph.cache_key) {
|
if atlas.mask_atlas.glyph_cache.contains(&glyph.cache_key) {
|
||||||
|
@ -193,7 +193,7 @@ impl TextRenderer {
|
||||||
let mut glyph_indices: Vec<u32> = Vec::new();
|
let mut glyph_indices: Vec<u32> = Vec::new();
|
||||||
let mut glyphs_added = 0;
|
let mut glyphs_added = 0;
|
||||||
|
|
||||||
for text_area in text_areas.iter() {
|
for text_area in text_areas {
|
||||||
// Note: subpixel positioning is not currently handled, so we always truncate down to
|
// Note: subpixel positioning is not currently handled, so we always truncate down to
|
||||||
// the nearest pixel whenever necessary.
|
// the nearest pixel whenever necessary.
|
||||||
for run in text_area.buffer.layout_runs() {
|
for run in text_area.buffer.layout_runs() {
|
||||||
|
@ -351,14 +351,14 @@ impl TextRenderer {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepare(
|
pub fn prepare<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
device: &Device,
|
device: &Device,
|
||||||
queue: &Queue,
|
queue: &Queue,
|
||||||
font_system: &mut FontSystem,
|
font_system: &mut FontSystem,
|
||||||
atlas: &mut TextAtlas,
|
atlas: &mut TextAtlas,
|
||||||
screen_resolution: Resolution,
|
screen_resolution: Resolution,
|
||||||
text_areas: &[TextArea<'_>],
|
text_areas: impl Iterator<Item = TextArea<'a>> + Clone,
|
||||||
cache: &mut SwashCache,
|
cache: &mut SwashCache,
|
||||||
) -> Result<(), PrepareError> {
|
) -> Result<(), PrepareError> {
|
||||||
self.prepare_with_depth(
|
self.prepare_with_depth(
|
||||||
|
|
Loading…
Reference in a new issue