Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Text.GetLocalBounds ignores spaces at the beginning and end?  (Read 4372 times)

0 Members and 1 Guest are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Text.GetLocalBounds ignores spaces at the beginning and end?
« on: January 03, 2012, 04:55:59 pm »
When I fill a sf::Text with a string that starts or ends with spaces then the GetLocalBounds and GetGlobalBounds functions don't return the correct width.

Here is an example code:
Code: [Select]
sf::Text text("     test     ");
float Width = text.GetGlobalBounds().Width;

Width will be 49 (with the default font).
This is only the width of the "test", so the spaces are ignored.
The width should be something like 127 (this is what FindCharacterPosition returned).
TGUI: C++ SFML GUI

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Text.GetLocalBounds ignores spaces at the beginning and end?
« Reply #1 on: January 03, 2012, 04:58:19 pm »
Yep, this is a bug in the current implementation. It'll be easy to fix.
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Text.GetLocalBounds ignores spaces at the beginning and end?
« Reply #2 on: January 05, 2012, 12:51:24 am »
Before you fix this, I think both flavors might be interesting for this, depending on what you're using it for, e.g. for some mouse over stuff you might prefer just getting the rectangle where characters are actually drawn.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Text.GetLocalBounds ignores spaces at the beginning and end?
« Reply #3 on: January 05, 2012, 07:57:01 am »
Quote
Before you fix this, I think both flavors might be interesting for this, depending on what you're using it for, e.g. for some mouse over stuff you might prefer just getting the rectangle where characters are actually drawn.

I don't think that this should be the default behaviour for such a function.
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Text.GetLocalBounds ignores spaces at the beginning and end?
« Reply #4 on: January 05, 2012, 04:25:11 pm »
No, the default behaviour/return value should get you the complete rectangle. I was thinking more about something like an additional GetLocalTrimmedBounds() or something similar.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Text.GetLocalBounds ignores spaces at the beginning and end?
« Reply #5 on: January 05, 2012, 04:30:12 pm »
Is it really needed? Who uses text with whitespace at the beginning or at the end?
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Text.GetLocalBounds ignores spaces at the beginning and end?
« Reply #6 on: January 05, 2012, 04:33:54 pm »
Not sure, for the odd cases. I'd skip it, if it's adding significant overhead - keeping it otherwise.

The program could print text at fixed positions showing some dynamic text loaded from a text file (probably multi line) with leading or trailing spaces you don't want to trim by hand and still keep the borders to where there's real text.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Text.GetLocalBounds ignores spaces at the beginning and end?
« Reply #7 on: January 05, 2012, 04:39:28 pm »
Let's keep that for later ;)
Laurent Gomila - SFML developer