Fixed bounding rect of sf::Text ignoring whitespaces (216)
This commit is contained in:
parent
947ab5fd87
commit
5c431b4b93
@ -251,6 +251,7 @@ void Text::updateGeometry()
|
|||||||
float y = static_cast<float>(m_characterSize);
|
float y = static_cast<float>(m_characterSize);
|
||||||
|
|
||||||
// Create one quad for each character
|
// Create one quad for each character
|
||||||
|
float minY = static_cast<float>(m_characterSize);
|
||||||
Uint32 prevChar = 0;
|
Uint32 prevChar = 0;
|
||||||
for (std::size_t i = 0; i < m_string.getSize(); ++i)
|
for (std::size_t i = 0; i < m_string.getSize(); ++i)
|
||||||
{
|
{
|
||||||
@ -275,10 +276,24 @@ void Text::updateGeometry()
|
|||||||
// Handle special characters
|
// Handle special characters
|
||||||
switch (curChar)
|
switch (curChar)
|
||||||
{
|
{
|
||||||
case L' ' : x += hspace; continue;
|
case L' ' :
|
||||||
case L'\t' : x += hspace * 4; continue;
|
x += hspace;
|
||||||
case L'\n' : y += vspace; x = 0; continue;
|
continue;
|
||||||
case L'\v' : y += vspace * 4; continue;
|
|
||||||
|
case L'\t' :
|
||||||
|
x += hspace * 4;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case L'\n' :
|
||||||
|
if (x > m_bounds.width)
|
||||||
|
m_bounds.width = x;
|
||||||
|
y += vspace;
|
||||||
|
x = 0;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case L'\v' :
|
||||||
|
y += vspace * 4;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the current glyph's description
|
// Extract the current glyph's description
|
||||||
@ -302,6 +317,10 @@ void Text::updateGeometry()
|
|||||||
|
|
||||||
// Advance to the next character
|
// Advance to the next character
|
||||||
x += glyph.advance;
|
x += glyph.advance;
|
||||||
|
|
||||||
|
// Update the minimum Y coordinate
|
||||||
|
if (y + top < minY)
|
||||||
|
minY = y + top;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're using the underlined style, add the last line
|
// If we're using the underlined style, add the last line
|
||||||
@ -316,8 +335,12 @@ void Text::updateGeometry()
|
|||||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recompute the bounding rectangle
|
// Update the bounding rectangle
|
||||||
m_bounds = m_vertices.getBounds();
|
m_bounds.left = 0;
|
||||||
|
m_bounds.top = minY;
|
||||||
|
if (x > m_bounds.width)
|
||||||
|
m_bounds.width = x;
|
||||||
|
m_bounds.height = y - minY;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
Loading…
Reference in New Issue
Block a user