Text can be centered wither with the centered attribute on a class or with = in the spec.
This commit is contained in:
parent
3752522597
commit
2c22da022f
2 changed files with 10 additions and 10 deletions
|
@ -73,7 +73,7 @@ struct ClickerUI {
|
|||
ClickerUI() {
|
||||
$gui.position(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
$gui.layout(
|
||||
"[_|*%(300,400)clicker|_|_|_]"
|
||||
"[_|=*%(300,400)clicker|_|_|_]"
|
||||
"[_|_ |_|_|_]"
|
||||
"[_|_ |_|_|_]"
|
||||
"[_|_ |_|_|_]"
|
||||
|
@ -135,15 +135,14 @@ struct ClickerUI {
|
|||
using enum Event;
|
||||
switch(ev) {
|
||||
case CLICKER: {
|
||||
auto& shaker = $gui.get<Shake>($clicker);
|
||||
auto& sprite = $gui.get<guecs::Sprite>($clicker);
|
||||
shaker.play(sprite);
|
||||
fmt::println("CLICKER LOVES YOU!");
|
||||
} break;
|
||||
auto& shaker = $gui.get<Shake>($clicker);
|
||||
auto& sprite = $gui.get<guecs::Sprite>($clicker);
|
||||
shaker.play(sprite);
|
||||
fmt::println("CLICKER LOVES YOU!");
|
||||
} break;
|
||||
case A_BUTTON:
|
||||
fmt::println("a button clicked");
|
||||
break;
|
||||
|
||||
fmt::println("a button clicked");
|
||||
break;
|
||||
default:
|
||||
assert(false && "invalid event");
|
||||
}
|
||||
|
|
|
@ -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)});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue