@@ -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
@@ -34,10 +40,10 @@ pub(crate) fn align<B: Brush>(
34
40
// Do nothing
35
41
}
36
42
( Alignment :: Right , _) | ( Alignment :: Start , true ) | ( Alignment :: End , false ) => {
37
- line. metrics . offset = free_space;
43
+ line. metrics . offset + = free_space;
38
44
}
39
45
( Alignment :: Middle , _) => {
40
- line. metrics . offset = free_space * 0.5 ;
46
+ line. metrics . offset + = free_space * 0.5 ;
41
47
}
42
48
( Alignment :: Justified , _) => {
43
49
// Justified alignment doesn't have any effect if free_space is negative or zero
@@ -50,7 +56,7 @@ pub(crate) fn align<B: Brush>(
50
56
// case, start-align, i.e., left-align for LTR text and right-align for RTL text.
51
57
if line. break_reason == BreakReason :: None || line. num_spaces == 0 {
52
58
if is_rtl {
53
- line. metrics . offset = free_space;
59
+ line. metrics . offset + = free_space;
54
60
}
55
61
continue ;
56
62
}
@@ -88,12 +94,6 @@ pub(crate) fn align<B: Brush>(
88
94
} ) ;
89
95
}
90
96
}
91
-
92
- if is_rtl {
93
- // In RTL text, trailing whitespace is on the left. As we hang that whitespace, offset
94
- // the line to the left.
95
- line. metrics . offset -= line. metrics . trailing_whitespace ;
96
- }
97
97
}
98
98
}
99
99
0 commit comments