Hey, I have this that makes my buttons:
contentT=sf::Text(content,*game->getGuiFont());
contentT.setColor(sf::Color::Black);
contentT.setCharacterSize(18);
contentT.setPosition(xPos-content.length()/(2*contentT.getCharacterSize()), yPos-2);
sprLeft=*game->getSpriteManager()->getSprite(3);
sprLeft.setPosition(xPos-57,yPos);
//sprLeft.setPosition(xPos-(content.length()/2)*(contentT.getCharacterSize()/(content.length()/2)),yPos);
sprRight=*game->getSpriteManager()->getSprite(4);
//sprRight.setPosition(xPos+(content.length()*content.length()*1.9),yPos);
sprRight.setPosition(xPos+177,yPos);
what the matter here is, is that the sprLeft and sprRight are not aligned to equal positions on x when buttons are different in text lenght.
So for example
button with content "New Game" would be different sized than a button with content "Options", how could I make the buttons be equally sized/aligned no matter what the content lenght is?
I'm not really sure as to what you're doing, but here's how to centre text and a rectangle on the screen.
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 720;
sf::Text centredText("hello", myFont);
sf::RectangleShape centredRectangle(sf::Vector2f(20.0f, 20.0f));
const sf::FloatRect textBounds = centredText.getLocalBounds();
const sf::FloatRect rectBounds = centredRectangle.getLocalBounds();
//Note that you have to add textBounds.left and textBounds.top because text can have non-zero left and top bounds
centredText.setOrigin(textBounds.width / 2.0f + textBounds.left, textBounds.height / 2.0f + textBounds.top);
centredRectangle.setOrigin(rectBounds.width / 2.0f, rectBounds.height / 2.0f);
centredText.setPosition(SCREEN_WIDTH / 2.0f);
centredRectangle.setPosition(SCREEN_HEIGHT / 2.0f);
I'm fairly certain the answer you're looking for is somewhere there.