diff --git a/examples/hello-world.rs b/examples/hello-world.rs index 55adfc4..97ea835 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -101,7 +101,7 @@ async fn run() { width: config.width, height: config.height, }, - &[TextArea { + [TextArea { buffer: &buffer, left: 10, top: 10, @@ -112,7 +112,8 @@ async fn run() { bottom: 160, }, default_color: Color::rgb(255, 255, 255), - }], + }] + .into_iter(), &mut cache, ) .unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 276dd20..d0e214b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,6 +96,7 @@ impl Default for TextBounds { } /// A text area containing text to be rendered along with its overflow behavior. +#[derive(Clone, Copy)] pub struct TextArea<'a> { /// The buffer containing the text to be rendered. pub buffer: &'a Buffer, diff --git a/src/text_render.rs b/src/text_render.rs index dc2ca58..5245fad 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -61,14 +61,14 @@ impl TextRenderer { } /// Prepares all of the provided text areas for rendering. - pub fn prepare_with_depth( + pub fn prepare_with_depth<'a>( &mut self, device: &Device, queue: &Queue, font_system: &mut FontSystem, atlas: &mut TextAtlas, screen_resolution: Resolution, - text_areas: &[TextArea<'_>], + text_areas: impl Iterator> + Clone, cache: &mut SwashCache, mut metadata_to_depth: impl FnMut(usize) -> f32, ) -> 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 glyph in run.glyphs.iter() { if atlas.mask_atlas.glyph_cache.contains(&glyph.cache_key) { @@ -193,7 +193,7 @@ impl TextRenderer { let mut glyph_indices: Vec = Vec::new(); 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 // the nearest pixel whenever necessary. for run in text_area.buffer.layout_runs() { @@ -351,14 +351,14 @@ impl TextRenderer { Ok(()) } - pub fn prepare( + pub fn prepare<'a>( &mut self, device: &Device, queue: &Queue, font_system: &mut FontSystem, atlas: &mut TextAtlas, screen_resolution: Resolution, - text_areas: &[TextArea<'_>], + text_areas: impl Iterator> + Clone, cache: &mut SwashCache, ) -> Result<(), PrepareError> { self.prepare_with_depth(