1
- use std:: ops:: RangeInclusive ;
2
1
use std:: sync:: Arc ;
3
2
4
3
use emath:: { pos2, vec2, Align , NumExt , Pos2 , Rect , Vec2 } ;
@@ -190,11 +189,6 @@ fn layout_section(
190
189
}
191
190
}
192
191
193
- /// We ignore y at this stage
194
- fn rect_from_x_range ( x_range : RangeInclusive < f32 > ) -> Rect {
195
- Rect :: from_x_y_ranges ( x_range, 0.0 ..=0.0 )
196
- }
197
-
198
192
// Ignores the Y coordinate.
199
193
fn rows_from_paragraphs (
200
194
paragraphs : Vec < Paragraph > ,
@@ -222,23 +216,21 @@ fn rows_from_paragraphs(
222
216
size : vec2 ( 0.0 , paragraph. empty_paragraph_height ) ,
223
217
ends_with_newline : !is_last_paragraph,
224
218
} ) ,
225
- pos : pos2 ( paragraph . cursor_x , 0.0 ) ,
219
+ pos : pos2 ( 0.0 , 0.0 ) ,
226
220
} ) ;
227
221
} else {
228
222
let paragraph_max_x = paragraph. glyphs . last ( ) . unwrap ( ) . max_x ( ) ;
229
223
if paragraph_max_x <= job. effective_wrap_width ( ) {
230
224
// Early-out optimization: the whole paragraph fits on one row.
231
- let paragraph_min_x = paragraph. glyphs [ 0 ] . pos . x ;
232
- let rect = rect_from_x_range ( paragraph_min_x..=paragraph_max_x) ;
233
225
rows. push ( PlacedRow {
234
226
row : Arc :: new ( Row {
235
227
section_index_at_start : paragraph. section_index_at_start ,
236
228
glyphs : paragraph. glyphs ,
237
229
visuals : Default :: default ( ) ,
238
- size : rect . size ( ) ,
230
+ size : vec2 ( paragraph_max_x , 0.0 ) ,
239
231
ends_with_newline : !is_last_paragraph,
240
232
} ) ,
241
- pos : rect . min ,
233
+ pos : pos2 ( 0.0 , f32 :: NAN ) ,
242
234
} ) ;
243
235
} else {
244
236
line_break ( & paragraph, job, & mut rows, elided) ;
@@ -283,16 +275,15 @@ fn line_break(
283
275
{
284
276
// Allow the first row to be completely empty, because we know there will be more space on the next row:
285
277
// TODO(emilk): this records the height of this first row as zero, though that is probably fine since first_row_indentation usually comes with a first_row_min_height.
286
- let rect = rect_from_x_range ( first_row_indentation..=first_row_indentation) ;
287
278
out_rows. push ( PlacedRow {
288
279
row : Arc :: new ( Row {
289
280
section_index_at_start : paragraph. section_index_at_start ,
290
281
glyphs : vec ! [ ] ,
291
282
visuals : Default :: default ( ) ,
292
- size : rect . size ( ) ,
283
+ size : vec2 ( 0.0 , 0.0 ) ,
293
284
ends_with_newline : false ,
294
285
} ) ,
295
- pos : rect . min ,
286
+ pos : pos2 ( 0.0 , f32 :: NAN ) ,
296
287
} ) ;
297
288
row_start_x += first_row_indentation;
298
289
first_row_indentation = 0.0 ;
@@ -308,19 +299,17 @@ fn line_break(
308
299
. collect ( ) ;
309
300
310
301
let section_index_at_start = glyphs[ 0 ] . section_index ;
311
- let paragraph_min_x = glyphs[ 0 ] . pos . x ;
312
302
let paragraph_max_x = glyphs. last ( ) . unwrap ( ) . max_x ( ) ;
313
303
314
- let rect = rect_from_x_range ( paragraph_min_x..=paragraph_max_x) ;
315
304
out_rows. push ( PlacedRow {
316
305
row : Arc :: new ( Row {
317
306
section_index_at_start,
318
307
glyphs,
319
308
visuals : Default :: default ( ) ,
320
- size : rect . size ( ) ,
309
+ size : vec2 ( paragraph_max_x , 0.0 ) ,
321
310
ends_with_newline : false ,
322
311
} ) ,
323
- pos : rect . min ,
312
+ pos : pos2 ( 0.0 , f32 :: NAN ) ,
324
313
} ) ;
325
314
326
315
// Start a new row:
@@ -354,16 +343,15 @@ fn line_break(
354
343
let paragraph_min_x = glyphs[ 0 ] . pos . x ;
355
344
let paragraph_max_x = glyphs. last ( ) . unwrap ( ) . max_x ( ) ;
356
345
357
- let rect = rect_from_x_range ( paragraph_min_x..=paragraph_max_x) ;
358
346
out_rows. push ( PlacedRow {
359
347
row : Arc :: new ( Row {
360
348
section_index_at_start,
361
349
glyphs,
362
350
visuals : Default :: default ( ) ,
363
- size : rect . size ( ) ,
351
+ size : vec2 ( paragraph_max_x - paragraph_min_x , 0.0 ) ,
364
352
ends_with_newline : false ,
365
353
} ) ,
366
- pos : rect . min ,
354
+ pos : pos2 ( paragraph_min_x , 0.0 ) ,
367
355
} ) ;
368
356
}
369
357
}
@@ -609,8 +597,7 @@ fn halign_and_justify_row(
609
597
}
610
598
}
611
599
612
- // Note we ignore the leading/trailing whitespace here!
613
- pos. x = target_min_x;
600
+ // Note we **don't** ignore the leading/trailing whitespace here!
614
601
row. size . x = target_max_x - target_min_x;
615
602
}
616
603
@@ -647,10 +634,6 @@ fn galley_from_rows(
647
634
// When mixing different `FontImpl` (e.g. latin and emojis),
648
635
// we always center the difference:
649
636
+ 0.5 * ( glyph. font_height - glyph. font_impl_height ) ;
650
-
651
- // FIXME(afishhh): HACK! change the proper code above instead!!
652
- // this should probably not be merged like this!
653
- glyph. pos . x -= placed_row. pos . x ;
654
637
}
655
638
656
639
placed_row. pos . y = cursor_y;
0 commit comments