Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bi-directional layout support #736

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

tjamaan
Copy link

@tjamaan tjamaan commented Nov 6, 2024

Objective

Add support for bi-directional layout (left-to-right and right-to-left) via the direction CSS style property.

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
Collaborator

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
Collaborator

@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 on lines +119 to +120
/// TODO: documentation
pub direction: Direction,
Copy link
Collaborator

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 on lines +97 to +103
match direction {
Direction::Rtl => {
justify_content.flip();
justify_items.as_mut().map(|x| x.flip());
}
_ => (),
}
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants