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: render of &str and String doesn't respect area.width #1177

Merged
merged 3 commits into from
Jun 15, 2024

Conversation

thscharler
Copy link
Contributor

Those two shouldn't write outside the given area I would think.

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.3%. Comparing base (d370aa7) to head (f8e5b6c).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1177   +/-   ##
=====================================
  Coverage   94.3%   94.3%           
=====================================
  Files         60      60           
  Lines      14677   14679    +2     
=====================================
+ Hits       13841   13843    +2     
  Misses       836     836           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thscharler thscharler closed this Jun 11, 2024
@thscharler thscharler reopened this Jun 11, 2024
@matta
Copy link
Contributor

matta commented Jun 11, 2024

Personally, I'm not a big fan of str implementing Widget. There are many ways to interpret the intent, and it isn't clear what it'll actually do. Because of the way traits show up in rust docs, I'm not sure how to document the behavior.

Should a str Widget behave like a Span with no styling? Or a multi-line thing? What if the Str has newlines? Should the rendering word wrap within the area? It would be good to document the answer.

If a str Widget is basically a Span with no styling it would be nice to find a way to share more of this implementation with Span. See @joshka 's commit yesterday which fixes rendering zero-width characters -> d370aa7. Does that bug apply to Str widgets too? If this is a case it might be better to remove the str Widget impl and instead have an UnstyledSpan widget. People can then write draw(UnstyledSpan(my_str)) if they want to.

@thscharler
Copy link
Contributor Author

Personally, I'm not a big fan of str implementing Widget. There are many ways to interpret the intent, and it isn't clear what it'll actually do. Because of the way traits show up in rust docs, I'm not sure how to document the behavior.

Should a str Widget behave like a Span with no styling? Or a multi-line thing? What if the Str has newlines? Should the rendering word wrap within the area? It would be good to document the answer.

I stumbled upon this implementation, and just tried it. Personally I wouldn't have expected it to handle newlines in any way and form.

But I agree that the behaviour should be documented.

If a str Widget is basically a Span with no styling it would be nice to find a way to share more of this implementation with Span. See @joshka 's commit yesterday which fixes rendering zero-width characters -> d370aa7. Does that bug apply to Str widgets too? If this is a case it might be better to remove the str Widget impl and instead have an UnstyledSpan widget. People can then write draw(UnstyledSpan(my_str)) if they want to.

Probably Buffer::set_string_n() should use the same algorithm as Span.

I looked at that one and wondered why graphemes(true) doesn't handle that case. As far as I understand http://www.unicode.org/reports/tr29/#Extend it shouldn't break at those zero width joiners. Or was it just a case of invalid data?

Copy link
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

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

This LGTM, don't see reason why we shouldn't have it.

@EdJoPaTo EdJoPaTo merged commit 4bfdc15 into ratatui:main Jun 15, 2024
61 checks passed
itsjunetime pushed a commit to itsjunetime/ratatui that referenced this pull request Jun 23, 2024
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.

5 participants