@@ -195,6 +195,8 @@ pub(crate) struct LayoutData<B: Brush> {
195
195
pub ( crate ) text_len : usize ,
196
196
pub ( crate ) width : f32 ,
197
197
pub ( crate ) full_width : f32 ,
198
+ pub ( crate ) min_content_width : f32 ,
199
+ pub ( crate ) max_content_width : f32 ,
198
200
pub ( crate ) height : f32 ,
199
201
pub ( crate ) fonts : Vec < Font > ,
200
202
pub ( crate ) coords : Vec < i16 > ,
@@ -223,6 +225,8 @@ impl<B: Brush> Default for LayoutData<B> {
223
225
text_len : 0 ,
224
226
width : 0. ,
225
227
full_width : 0. ,
228
+ min_content_width : 0. ,
229
+ max_content_width : 0. ,
226
230
height : 0. ,
227
231
fonts : Vec :: new ( ) ,
228
232
coords : Vec :: new ( ) ,
@@ -246,6 +250,8 @@ impl<B: Brush> LayoutData<B> {
246
250
self . text_len = 0 ;
247
251
self . width = 0. ;
248
252
self . full_width = 0. ;
253
+ self . min_content_width = 0. ;
254
+ self . max_content_width = 0. ;
249
255
self . height = 0. ;
250
256
self . fonts . clear ( ) ;
251
257
self . coords . clear ( ) ;
@@ -444,6 +450,11 @@ impl<B: Brush> LayoutData<B> {
444
450
}
445
451
446
452
pub ( crate ) fn finish ( & mut self ) {
453
+ self . apply_spacing ( ) ;
454
+ self . calculate_content_widths ( ) ;
455
+ }
456
+
457
+ fn apply_spacing ( & mut self ) {
447
458
for run in & self . runs {
448
459
let word = run. word_spacing ;
449
460
let letter = run. letter_spacing ;
@@ -470,4 +481,43 @@ impl<B: Brush> LayoutData<B> {
470
481
}
471
482
}
472
483
}
484
+
485
+ fn calculate_content_widths ( & mut self ) {
486
+ let mut max_width = 0.0 ;
487
+ for item in & self . items {
488
+ match item. kind {
489
+ LayoutItemKind :: TextRun => {
490
+ let run = & self . runs [ item. index ] ;
491
+ let mut min_width = 0.0 ;
492
+ let mut trailing_whitespace = 0.0 ;
493
+ for cluster in & self . clusters [ run. cluster_range . clone ( ) ] {
494
+ let boundary = cluster. info . boundary ( ) ;
495
+ if matches ! ( boundary, Boundary :: Line | Boundary :: Mandatory ) {
496
+ self . min_content_width =
497
+ self . min_content_width . max ( min_width - trailing_whitespace) ;
498
+ min_width = 0.0 ;
499
+ if boundary == Boundary :: Mandatory {
500
+ max_width = 0.0 ;
501
+ }
502
+ }
503
+ min_width += cluster. advance ;
504
+ trailing_whitespace = if cluster. info . whitespace ( ) . is_space_or_nbsp ( ) {
505
+ cluster. advance
506
+ } else {
507
+ 0.0
508
+ } ;
509
+ }
510
+ self . min_content_width =
511
+ self . min_content_width . max ( min_width - trailing_whitespace) ;
512
+ max_width += run. advance - trailing_whitespace;
513
+ }
514
+ LayoutItemKind :: InlineBox => {
515
+ let ibox = & self . inline_boxes [ item. index ] ;
516
+ self . min_content_width = self . min_content_width . max ( ibox. width ) ;
517
+ max_width += ibox. width ;
518
+ }
519
+ }
520
+ self . max_content_width = self . max_content_width . max ( max_width) ;
521
+ }
522
+ }
473
523
}
0 commit comments