Text can be centered wither with the centered attribute on a class or with = in the spec.

This commit is contained in:
Zed A. Shaw 2025-07-23 00:25:00 -04:00
parent 3752522597
commit 2c22da022f
2 changed files with 10 additions and 10 deletions

View file

@ -13,7 +13,7 @@ namespace guecs {
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size);
text->setFillColor(color);
if(centered) {
if(centered || cell.center) {
auto bounds = text->getLocalBounds();
auto text_cell = lel::center(bounds.size.x, bounds.size.y, cell);
// this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box
@ -57,6 +57,7 @@ namespace guecs {
sf::IntRect rect{{0,0}, bounds};
sprite = make_shared<sf::Sprite>(*sprite_texture.texture, rect);
fmt::println("SPRITE centered: {}", cell.center);
sprite->setPosition({float(cell.x + padding), float(cell.y + padding)});