-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Modify sf::Text::getLocalBounds() to behave more intuitively #216
Comments
Actually, as long as you take in account the left and top coordinates of the text's bounding rect (which are non-zero, unlike other entities), everything works as expected. If someone still has a problem, even when left/top coordinates are considered, please post here your use case. So for now, we're left with just the whitespace issue. |
This could really use being fixed. |
Also, could you expand on what you mean by using the left/top coordinates? |
I mean doing |
There is still the whitespace issue to fix though. |
I am currently using http://en.sfml-dev.org/forums/index.php?topic=7174 but I don't even think it works properly (although more thorough testing to make sure the bug does not originate elsewhere is necessary). I have to add artificial padding currently to keep text in my GUI text boxes because no proper function exists to measure the text. |
Please provide a complete and minimal code that reproduces your problem. And as I said, you don't need the workaround shown in that thread if you use the bounding rectangle correctly. So you should also show what you tried with that. |
Hey, happy decennary! ;) What's the actual use of having an offset bound-rect for |
Text should align on the text base and not on whatever the current top left corner is. If you aligned around the top left corner and render the text at position (0, 0), then proceeded to render one letter at a time, you'd get text that jumps around, because let's say you start with Making sure that text positioning is relative to the text baseline, you can add more and more letters and the text remains stable, while the necessary offset is "absorbed" by the local bounds. |
Thanks for the detailed answer (as usual)! I (kinda) know the reason for the offset, my question is: when this particular way of addressing it -- counter-intuitively special-casing the |
It's mostly due to the general drawing API design, as |
I mean exactly because So, is this more like a historic artifact (and if yes, v3 would be the perfect time to iron it out), or am I (quite possibly!) missing something important here? In the meantime, I think I've got some better understanding of the assumed motivation:
But:
So, to reverse Laurent's decade-old comment ("If someone still has a problem ... please post here your use case"), and to repeat mine: What's the use-case that warrants this (apparent) quirk of the otherwise pristine API? (As opposed to providing the same functionality via -- albeit extra, but -- unsurprising, and also more expressive API calls?) Thanks! |
With its current semantics, getLocalBounds() is not very useful. For example, it depends on single character heights and ignores leading or trailing whitespaces.
Forum threads:
http://en.sfml-dev.org/forums/index.php?topic=7174
http://en.sfml-dev.org/forums/index.php?topic=6672
http://en.sfml-dev.org/forums/index.php?topic=7156
The text was updated successfully, but these errors were encountered: