Skip to content

Commit e7e5fe3

Browse files
authored
Flip horizontal offsets for RTL in column layout (#38)
Adjust absolute-positioned child handling so horizontal offsets are mirrored only when the layout is a Column in RTL. Use is_row_rtl for determining main-axis before/after ordering, and conditionally swap cross_before/cross_after only when is_rtl && layout_type == LayoutType::Column. Add a unit test (rtl_absolute_in_column_only_flips_horizontal_offsets) to verify left becomes trailing in RTL while top remains unchanged.
1 parent 37fa5ae commit e7e5fe3

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/layout.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,13 +1768,16 @@ where
17681768

17691769
match child_position {
17701770
PositionType::Absolute => {
1771-
let (child_main_before, child_main_after) = if is_rtl {
1771+
let (child_main_before, child_main_after) = if is_row_rtl {
17721772
(child.node.main_after(store, layout_type), child.node.main_before(store, layout_type))
17731773
} else {
17741774
(child.node.main_before(store, layout_type), child.node.main_after(store, layout_type))
17751775
};
1776-
let child_cross_before = child.node.cross_before(store, layout_type);
1777-
let child_cross_after = child.node.cross_after(store, layout_type);
1776+
let (child_cross_before, child_cross_after) = if is_rtl && layout_type == LayoutType::Column {
1777+
(child.node.cross_after(store, layout_type), child.node.cross_before(store, layout_type))
1778+
} else {
1779+
(child.node.cross_before(store, layout_type), child.node.cross_after(store, layout_type))
1780+
};
17781781

17791782
let parent_main = parent_main + padding_main_before + padding_main_after;
17801783
let parent_cross = parent_cross + padding_cross_before + padding_cross_after;

tests/absolute.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,26 @@ fn auto_parent_pixels_child_percentage_absolute_child() {
330330
assert_eq!(world.cache.bounds(child1), Some(&Rect { posx: 0.0, posy: 0.0, width: 50.0, height: 50.0 }));
331331
assert_eq!(world.cache.bounds(child2), Some(&Rect { posx: 0.0, posy: 0.0, width: 25.0, height: 13.0 }));
332332
}
333+
334+
#[test]
335+
fn rtl_absolute_in_column_only_flips_horizontal_offsets() {
336+
let mut world = World::default();
337+
338+
let root = world.add(None);
339+
world.set_layout_type(root, LayoutType::Column);
340+
world.set_direction(root, Direction::RightToLeft);
341+
world.set_width(root, Units::Pixels(600.0));
342+
world.set_height(root, Units::Pixels(400.0));
343+
344+
let node = world.add(Some(root));
345+
world.set_position_type(node, PositionType::Absolute);
346+
world.set_width(node, Units::Pixels(100.0));
347+
world.set_height(node, Units::Pixels(80.0));
348+
world.set_left(node, Units::Pixels(20.0));
349+
world.set_top(node, Units::Pixels(10.0));
350+
351+
root.layout(&mut world.cache, &world.tree, &world.store, &mut ());
352+
353+
// RTL mirrors only horizontal offsets, so left becomes trailing while top is unchanged.
354+
assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 480.0, posy: 10.0, width: 100.0, height: 80.0 }));
355+
}

0 commit comments

Comments
 (0)