@@ -9,7 +9,7 @@ use cosmic_text::{Buffer, Metrics};
9
9
use serde:: { Deserialize , Serialize } ;
10
10
use smallvec:: SmallVec ;
11
11
12
- use crate :: { Font , TextLayoutInfo , TextRoot } ;
12
+ use crate :: { Font , TextLayoutInfo , TextRoot , TextSpanComponent } ;
13
13
pub use cosmic_text:: {
14
14
self , FamilyOwned as FontFamily , Stretch as FontStretch , Style as FontStyle ,
15
15
Weight as FontWeight ,
@@ -286,15 +286,18 @@ pub trait TextBuilderExt {
286
286
/// If no spans are provided then a default text entity will be spawned.
287
287
///
288
288
/// Returns an [`EntityCommands`] for the root entity.
289
- fn spawn_text_block < R : TextRoot > ( & mut self , spans : Vec < ( String , TextStyle ) > ) -> EntityCommands ;
289
+ fn spawn_text_block < R : TextRoot > (
290
+ & mut self ,
291
+ spans : impl IntoIterator < Item = ( String , TextStyle ) > ,
292
+ ) -> EntityCommands ;
290
293
}
291
294
292
295
impl TextBuilderExt for Commands < ' _ , ' _ > {
293
296
fn spawn_text_block < R : TextRoot > (
294
297
& mut self ,
295
- mut spans : Vec < ( String , TextStyle ) > ,
298
+ spans : impl IntoIterator < Item = ( String , TextStyle ) > ,
296
299
) -> EntityCommands {
297
- let mut spans = spans. drain ( .. ) ;
300
+ let mut spans = spans. into_iter ( ) ;
298
301
299
302
// Root of the block.
300
303
let first = spans. next ( ) . unwrap_or_default ( ) ;
@@ -312,9 +315,9 @@ impl TextBuilderExt for Commands<'_, '_> {
312
315
impl TextBuilderExt for EntityCommands < ' _ > {
313
316
fn spawn_text_block < R : TextRoot > (
314
317
& mut self ,
315
- mut spans : Vec < ( String , TextStyle ) > ,
318
+ spans : impl IntoIterator < Item = ( String , TextStyle ) > ,
316
319
) -> EntityCommands {
317
- let mut spans = spans. drain ( .. ) ;
320
+ let mut spans = spans. into_iter ( ) ;
318
321
319
322
// Root of the block.
320
323
let first = spans. next ( ) . unwrap_or_default ( ) ;
@@ -332,13 +335,19 @@ impl TextBuilderExt for EntityCommands<'_> {
332
335
/// Provides convenience methods for adding text spans to a text block.
333
336
pub trait TextSpanBuilderExt {
334
337
/// Adds a flat list of spans as children of the current entity.
335
- fn with_spans < S : Component > ( & mut self , spans : Vec < ( S , TextStyle ) > ) -> & mut Self ;
338
+ fn with_spans < S : TextSpanComponent > (
339
+ & mut self ,
340
+ spans : impl IntoIterator < Item = ( String , TextStyle ) > ,
341
+ ) -> & mut Self ;
336
342
}
337
343
338
344
impl TextSpanBuilderExt for EntityCommands < ' _ > {
339
- fn with_spans < S : Component > ( & mut self , mut spans : Vec < ( S , TextStyle ) > ) -> & mut Self {
340
- for ( span, style) in spans. drain ( ..) {
341
- self . with_child ( ( span, style) ) ;
345
+ fn with_spans < S : TextSpanComponent > (
346
+ & mut self ,
347
+ spans : impl IntoIterator < Item = ( String , TextStyle ) > ,
348
+ ) -> & mut Self {
349
+ for ( span, style) in spans. into_iter ( ) {
350
+ self . with_child ( ( S :: from ( span) , style) ) ;
342
351
}
343
352
self
344
353
}
0 commit comments