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

Add font size warning to TextSection #9660

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hate
Copy link
Contributor

@hate hate commented Aug 31, 2023

Objective

  • TextSections are unable to display their text value if the font_size is less than or equal to 0, thus @ickshonpe suggested we emit a warning to the console whenever this occurs.
  • Fixes Negative font_size warning #9655

Solution

  • Emit a warning if we detect that the font_size is less than or equal to 0.
  • Add bevy_log as a dependency to bevy_text to be able to access the warn! macro.

@hate
Copy link
Contributor Author

hate commented Aug 31, 2023

Similarly, bevy_text::TextSection::from_styleshould emit a warning as well, but I am unsure how to call the warn! macro since the method signature is const

@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Aug 31, 2023
@alice-i-cecile
Copy link
Member

Good work :) We could make from_section no longer const, although that would be a bit sad.

Copy link

@KingTheSim KingTheSim left a comment

Choose a reason for hiding this comment

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

Shouldn't the function not attempt to create a TextSection if the font size is invalid?

@alice-i-cecile
Copy link
Member

That TextSection could later be updated to be valid though. Our options here are:

  • silently fail
  • warn
  • return a Result (which will almost always get unwrapped)
  • panic

Because the problem is repairable and cosmetic, I think that warning is the least bad option, although I'm open to being convinced.

@KingTheSim
Copy link

Silent fail won't give us information and Result always get's unwrapped, which doesn't add value.
If getting an invalid font size doesn't cause a crash/break down the line, I agree with the warning. We can later set a default value if that's ok. If it does break somewhere, panic with explanation is alright.

@ickshonpe
Copy link
Contributor

That TextSection could later be updated to be valid though.

When I posted the issue my thinking was that the warning would be added somewhere to the text systems rather than to TextSection itself because of the inverse of this, this implementation won't pick up if the text is updated later to an invalid state.
And there would be a flag to make sure the warning isn't spammed, similar to FontAtlasWarning.

Warning on creation of TextSections didn't occur to me and has advantages too. It covers 99% of cases, most users will never change the font size after creation, and the implementation is far simpler.

@ravenclaw900
Copy link

While we're at it, would it also make sense to check if the number is_finite (not NaN, -Inf, or Inf)? I would agree that this is an obvious bug in the calling code, but so is passing in a negative, therefore I think this check would be reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negative font_size warning
5 participants