Skip to content

Bi-directional layout support#736

Closed
tjamaan wants to merge 6 commits intoDioxusLabs:mainfrom
tjamaan:tj-direction
Closed

Bi-directional layout support#736
tjamaan wants to merge 6 commits intoDioxusLabs:mainfrom
tjamaan:tj-direction

Conversation

@tjamaan
Copy link
Copy Markdown

@tjamaan tjamaan commented Nov 6, 2024

Objective

Context

This change attempts to support bidi layout only for horizontal layout direction, i.e. it doesn't support vertical content such as CJK or Mongolian vertical writing systems.

Feedback wanted

Should inset, margin, padding, and border Rects be considered as absolute axis (left means left and right means right) or relative axis (left means layout start, right means layout end)?

Should the RTL conversion happen during the calculations or as a separate phase (i.e. calculate as if LTR then flip the horizontal axis)?

General code review is also wanted to be more aligned with the rest of taffy's code :)

@nicoburns
Copy link
Copy Markdown
Member

To answer your questions:

Should inset, margin, padding, and border Rects be considered as absolute axis (left means left and right means right) or relative axis (left means layout start, right means layout end)?

left should mean left, etc.

Should the RTL conversion happen during the calculations or as a separate phase (i.e. calculate as if LTR then flip the horizontal axis)?

My intuition on this is that it should happen during the calculations. But I would be open to being persuaded otherwise. As long as whichever implementation we choose is able to pass all the relevant tests and match other browsers I think I'll be happy.


Will do a proper review later.

Copy link
Copy Markdown
Member

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjamaan Actual direction changes look good to me. But we'll want to hook this up to our testing infrastructure to verify that. The process for that is something like:

  • Add support for the direction property to our gentest script
    • Add support for reading it to scripts/gentest/test_helper.js
    • Add support for generating to scripts/gentest/main.rs
  • Setup the gentest script to generate every test with both ltr and rtl as the default.
  • Write some new tests to test mixed direction.

I've also formatted main using the latest nightly, and I've also removed .cargo/config from our repo. So if you rebase on latest main that should get rid of a bunch of unrelated changes from the diff.

Comment thread src/tree/layout.rs
Comment on lines +119 to +120
/// TODO: documentation
pub direction: Direction,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in thinking that this isn't actually used? If so, it should probably be removed. Removing the direction field here and the direction function parameter from the traits would greatly reduce the size of the diff for this PR which would be nice!

Comment thread src/compute/grid/mod.rs
Comment on lines +97 to +103
match direction {
Direction::Rtl => {
justify_content.flip();
justify_items.as_mut().map(|x| x.flip());
}
_ => (),
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use if direction.is_rtl() here?

@alice-i-cecile alice-i-cecile added the enhancement New feature or request label Dec 24, 2024
@nicoburns
Copy link
Copy Markdown
Member

@tjamaan Are you intending to finish this feature or should I mark this as open for adoption?

One thing that has changed recently is that there is less need for writing custom tests as we are now able to run the WPT tests against Taffy using Blitz (cargo run -p wpt css/css-flexbox css/css-grid from the Blitz repo - you can update the Taffy dependency to be a local path dependency). Unfortunately this PR as-is isn't currently enabling any extra WPT test passes relative to Taffy main.

@nicoburns nicoburns added the adopt me The author has vanished or is too busy; feel free to create a new PR with the changes! label Dec 8, 2025
@kane50613
Copy link
Copy Markdown
Contributor

hey @nicoburns I'd like to adopt this PR! Should I fork the repo and apply these commits or continue on this branch

@nicoburns
Copy link
Copy Markdown
Member

@kane50613 That's great! I think you'll need to fork and create you're own branch, as I don't think github will let you push tobthis one.

kane50613 added a commit to kane50613/taffy that referenced this pull request Dec 27, 2025
diff is adpoted from DioxusLabs#736 originally written by @tjamaan
kane50613 added a commit to kane50613/taffy that referenced this pull request Dec 27, 2025
diff is adopted from DioxusLabs#736 originally written by @tjamaan
nicoburns pushed a commit that referenced this pull request Jan 5, 2026
diff is adopted from #736 originally written by @tjamaan
nicoburns pushed a commit that referenced this pull request Jan 25, 2026
diff is adopted from #736 originally written by @tjamaan
kane50613 added a commit to kane50613/taffy that referenced this pull request Feb 13, 2026
diff is adopted from DioxusLabs#736 originally written by @tjamaan
nicoburns pushed a commit to nicoburns/taffy that referenced this pull request Mar 17, 2026
diff is adopted from DioxusLabs#736 originally written by @tjamaan

add grid & flex test fixtures

add block layout & inherited fixtures, remove unused `flip` function

better `direction` field comments for consistency

merge `alignment_based_offset` match cases

remove newline

Fix double application of inset

Add edge helpers to ContentSlot

Fixup x/y positioning of block children

This fixes errors introduced when resolving merge conflicts when rebasing
the floats PR on top of the direction PR.

Fix build when block_layout is enabled bu float_layout isn't

Signed-off-by: Nico Burns <nico@nicoburns.com>

Fix build when no default features are enabled

Signed-off-by: Nico Burns <nico@nicoburns.com>

remove redundant `direction` prop from layout inputs

update test helper to get direction from computed style

Account for the possibility of negative free space

Don't account for margins when computing slot width

Don't add scrollbar_width to RTL x position of flex items

The scrollbar of items is within their width.

correct RTL grid placement

cargo fmt

Signed-off-by: Nico Burns <nico@nicoburns.com>

Create rtl variants of all tests

Signed-off-by: Nico Burns <nico@nicoburns.com>

fix

fix `TrackCounts` use

add `AlignContent::reversed`, avoid using `ContentSlot` without `float_layout` guard

remove `scrollbar_size` redeclartion

simplify changes

simplify `rtl_column_occupancy_index_for_initialization` params

reduce diff

cargo fmt

simplify flexbox rtl offset math

fix `round` on negative value

README: add slint (DioxusLabs#918)
nicoburns added a commit that referenced this pull request Mar 17, 2026
* implement `direction` property

diff is adopted from #736 originally written by @tjamaan

add grid & flex test fixtures

add block layout & inherited fixtures, remove unused `flip` function

better `direction` field comments for consistency

merge `alignment_based_offset` match cases

remove newline

Fix double application of inset

Add edge helpers to ContentSlot

Fixup x/y positioning of block children

This fixes errors introduced when resolving merge conflicts when rebasing
the floats PR on top of the direction PR.

Fix build when block_layout is enabled bu float_layout isn't

Signed-off-by: Nico Burns <nico@nicoburns.com>

Fix build when no default features are enabled

Signed-off-by: Nico Burns <nico@nicoburns.com>

remove redundant `direction` prop from layout inputs

update test helper to get direction from computed style

Account for the possibility of negative free space

Don't account for margins when computing slot width

Don't add scrollbar_width to RTL x position of flex items

The scrollbar of items is within their width.

correct RTL grid placement

cargo fmt

Signed-off-by: Nico Burns <nico@nicoburns.com>

Create rtl variants of all tests

Signed-off-by: Nico Burns <nico@nicoburns.com>

fix

fix `TrackCounts` use

add `AlignContent::reversed`, avoid using `ContentSlot` without `float_layout` guard

remove `scrollbar_size` redeclartion

simplify changes

simplify `rtl_column_occupancy_index_for_initialization` params

reduce diff

cargo fmt

simplify flexbox rtl offset math

fix `round` on negative value

README: add slint (#918)

* Hide debug output in tests

* Disable rounding for some tests

* Update relayout_is_stable_with_rounding tests to new "round_ties_up" rounding strategy

---------

Co-authored-by: Nico Burns <nico@nicoburns.com>
@nicoburns
Copy link
Copy Markdown
Member

Superceded by #906

@nicoburns nicoburns closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adopt me The author has vanished or is too busy; feel free to create a new PR with the changes! enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support direction property (right-to-left layout)

4 participants