parley icon indicating copy to clipboard operation
parley copied to clipboard

Ability to control where line breaks appear

Open valadaptive opened this issue 1 year ago • 4 comments

That is, something like the word-break CSS property. Right now, Parley breaks all lines at word boundaries (there's logic to insert "emergency line breaks" if a single word overflows the maximum width, but it seems to be disabled).

For egui, we need to be able to customize where line breaks can appear (strictly at word boundaries, at word boundaries but falling back to letter boundaries, or at letter boundaries).

valadaptive avatar Mar 19 '25 08:03 valadaptive

The line breaking code already has the first two variants implemented. But the second is disabled behind an if(constant) rather than bring controlled by a style.

nicoburns avatar Mar 19 '25 08:03 nicoburns

For full CSS-level support, word-break will need to be a style property that can vary per-character. That would entail moving text analysis to the style builders' "build" methods, and adding a way for Swash to resolve it per-character (like how swash::partition calls a ShapeContext to select fonts). This would probably also mean that other non-Swash crates (like `icu_segmenter) couldn't be used since they don't have character-level support for these settings.

For egui, setting this as a per-layout property will suffice. Not sure how to best pass it as an option--neither of the builder methods take any layout-wide options. Maybe create a LayoutOptions struct and add it as an argument to the builder methods?

valadaptive avatar Mar 24 '25 01:03 valadaptive

@valadaptive Could we always find all break points in the text analysis (but categorise them depending on which word-break setting(s) they apply to). And then selectively ignore some of them in layout depending on a span-specific style?

nicoburns avatar Mar 24 '25 01:03 nicoburns

Maybe? I'm not sure to what extent the Unicode line-breaking algorithm can do that. I think it's stateful, and word-break: break-all says "treat certain line-breaking classes as if they were the ID class". I'm not sure if that implies that the rest of the line-breaking algorithm should do that too, or if its internal state can diverge depending on that. I'll probably have to look at how web browsers implement it.

valadaptive avatar Mar 24 '25 01:03 valadaptive