@@ -15,13 +15,19 @@ pub(crate) fn align<B: Brush>(
15
15
) {
16
16
// Whether the text base direction is right-to-left.
17
17
let is_rtl = layout. base_level & 1 == 1 ;
18
- let alignment_width = alignment_width. unwrap_or ( layout. full_width ) ;
18
+ let alignment_width = alignment_width. unwrap_or ( layout. width ) ;
19
19
20
20
// Apply alignment to line items
21
21
for line in & mut layout. lines {
22
22
// TODO: remove this field
23
23
line. alignment = alignment;
24
24
25
+ if is_rtl {
26
+ // In RTL text, trailing whitespace is on the left. As we hang that whitespace, offset
27
+ // the line to the left.
28
+ line. metrics . offset = -line. metrics . trailing_whitespace ;
29
+ }
30
+
25
31
// Compute free space.
26
32
let free_space = alignment_width - line. metrics . advance + line. metrics . trailing_whitespace ;
27
33
@@ -38,10 +44,10 @@ pub(crate) fn align<B: Brush>(
38
44
// Do nothing
39
45
}
40
46
( Alignment :: Right , _) | ( Alignment :: Start , true ) | ( Alignment :: End , false ) => {
41
- line. metrics . offset = free_space;
47
+ line. metrics . offset + = free_space;
42
48
}
43
49
( Alignment :: Middle , _) => {
44
- line. metrics . offset = free_space * 0.5 ;
50
+ line. metrics . offset + = free_space * 0.5 ;
45
51
}
46
52
( Alignment :: Justified , _) => {
47
53
// Justified alignment doesn't have any effect if free_space is negative or zero
@@ -54,7 +60,7 @@ pub(crate) fn align<B: Brush>(
54
60
// case, start-align, i.e., left-align for LTR text and right-align for RTL text.
55
61
if line. break_reason == BreakReason :: None || line. num_spaces == 0 {
56
62
if is_rtl {
57
- line. metrics . offset = free_space;
63
+ line. metrics . offset + = free_space;
58
64
}
59
65
continue ;
60
66
}
@@ -92,12 +98,6 @@ pub(crate) fn align<B: Brush>(
92
98
} ) ;
93
99
}
94
100
}
95
-
96
- if is_rtl {
97
- // In RTL text, trailing whitespace is on the left. As we hang that whitespace, offset
98
- // the line to the left.
99
- line. metrics . offset -= line. metrics . trailing_whitespace ;
100
- }
101
101
}
102
102
}
103
103
0 commit comments