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

fix: RTL text often invisible #2016

Closed
wants to merge 3 commits into from
Closed

Conversation

nicksenger
Copy link
Contributor

@nicksenger nicksenger commented Aug 10, 2023

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.

Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

RTL isn't supported yet, so we should probably avoid trying to fix it.

Support should come first. That involves researching what the expected behavior should be and reviewing any of the current assumptions in our text pipeline. It's also very likely that dependencies need to change (cosmic-text is missing a way to specify undefined bounds for a Buffer).

Let's figure all that out first!

@hecrj hecrj closed this Aug 15, 2023
@hecrj hecrj added bug Something isn't working text labels Aug 15, 2023
@hecrj hecrj added this to the 0.11.0 milestone Aug 15, 2023
@nicksenger
Copy link
Contributor Author

Aha, I didn't realize RTL was explicitly unsupported. Lmk if there's anywhere in particular I can contribute wrt this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rendering text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants