Repository navigation
Always align when line breaking - #941
Conversation
| /// If set to `None`, those lines use the alignment passed as the first argument to [`Layout::set_alignment`], | ||
| /// except that [`Alignment::Justify`] falls back to [`Alignment::Start`]. This is the behavior of |
There was a problem hiding this comment.
Nit: "as the first argument" is perhaps a bit too much detail here.
| /// Align the layout. This applies to the full layout at a time (rather than to individual lines as we go), | ||
| /// because the alignment implicitly uses the widest width in the layout if no max advance was provided. | ||
| /// | ||
| /// TODO: if we ever end up getting rid of multi-paragraph layout, can we avoid that; is this what | ||
| /// `calculate_content_widths` is for instead? | ||
| pub(crate) fn align<B: Brush>(layout: &mut LayoutData<B>) { |
There was a problem hiding this comment.
/// TODO: if we ever end up getting rid of multi-paragraph layout, can we avoid that; is this what
///calculate_content_widthsis for instead?
Yeah, I think if there's a single paragraph (assuming you mean no forced breaks) we could always align as we go. calculate_content_widths is really quite fast, so I suppose we could theoretically call that if there's no max advance and use the max width to break/align to. (The max width should be correct, the min can theoretically differ a bit as it can't reasonably account for reshaping).
Is aligning as we go noticeably faster?
There was a problem hiding this comment.
I've changed the TODO to track seeing if as-we-go would be faster.
Co-authored-by: Tom Churchman <thomas@churchman.nl>
LLM Contributions: Initially generated, review.
From what I've seen, every consumer of Parley always immediately calls
alignafter breaking, without ever re-aligning.As such, we can take advantage of this to store the results of spacing in the alignment pass, massively simplifying glyph iteration (and making future features - tabs and CJK justification - a lot easier to add performantly). This is as was proposed in #office hours > Text 2026-10-27. See also #935.
This change is the API diff needed to realise that performance gain.
Performance numbers for this just noise (as it doesn't actually change the operations which happen).
Working on this change has made it quite starkly apparent how our current Layout/line breaking APIs are very unintuitive. I don't necessarily have a complete answer for what to do about it, but I've put a discussion in the agenda for next week.
Changelog