Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Sometime text in RTL languages, when the
Text
widget's width is set to shrink, is only displayed partially or not at all. In this minimal repro case, there should be two lines of text, but only the one with a fixed width shows up.The problem appears to be that glyphon is passed the max width for the text, and returns a buffer which corresponds to the provided width, however the width of the layout node used to render the text is based on the width of the text itself rather than this maximum. For LTR languages this is fine because the text is left-aligned in the buffer. For RTL languages, when the max-width is larger than the width of the actual text, the buffer returned from glyphon will extend outside the bounds of the layout node, so it is hidden or shows up only partially.
Screen.Recording.2023-08-10.at.7.46.15.AM.mov
Solution
The solution I found is to resize the buffer based on the measured text dimensions. This fixes (subjectively) the provided repro example. There is some runtime cost, but it seems like it should be acceptable since this operation is cached.
Considerations
As far as I can tell this doesn't change behavior for LTR text. For RTL text however, it does change the behavior when the specified width is greater than that required to render the text. RTL text will no longer automatically be shifted to the right side of the layout bounds if the specified bound width is greater than that required to display the text, so it is up to the Iced user to decide whether a particular section of text should be right aligned with its container or not (regardless of whether it flows LTR or RTL).
I think this is a reasonable trade to have text show up in cases where it currently doesn't, but maybe there is a way to get both? I didn't see it.