In the current implementation, the tab size in sf::Text is always 4 times the width of a space. But the space added doesn't depend on the current cursor position as it is in "real" tabs.
I'd like to be able to set the tab size using SetTabWidth or something (default tab size can still be 4 * width of space). And the actual space should take the current cursor location into account.
I can provide a sample implementation for that.
I tried it like this and it works:
// Initialize the rendering coordinates
(...)
float tabSpace = space * myTabSize;
(...)
// Handle special characters
switch (curChar)
{
(...)
case L'\t' : x = tabSpace * static_cast<int>((x + space + tabSpace) / tabSpace); continue;
(...)
}
myTabSize is a new member variable that stores the tab size, in number of spaces.
Also, when looking at the source, I saw that essentially the same logic is there three times: once in GetCharacterPos, then in Render and finally in RecomputeRect. It would be easier to maintain the code if sf::Text used a std::vector of character positions. Then GetCharacterPos would need only O(1) time and Render could just use the vector to draw the characters at the appropriate position.