I wrote my own function to do something similar, because you can not query the display to figure out how large a string will be in pixels (as it is very dependent on the font being used to draw the string).
What I do is a keep a table in flash that has the width of each character in my font and then wrote a function "uint8_t calculateStringWidth(const char* string, const uint8_t* table)".
This iterates through the string and sums up the widths of each character in the string and returns it to the caller. From that you can do calculations based on the size of the string and whatever else (i.e. the screen size, item size, etc.)
I could share this code if it would be of use, but remember, it needs to have a table you create based on the font you are using.