From f884b83809f2c746e393c7e2e2f12559d06a15b4 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 16 Feb 2025 03:00:29 -0500 Subject: [PATCH] SFML's use of fonts is bizarre. It gives you a bounding box for the font, but then just ignores it and positions the text using the baseline, which is then outside of the bounding box. This is a quick fix but still looks wrong. --- combat_ui.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/combat_ui.cpp b/combat_ui.cpp index 06c5b87..3f9cea6 100644 --- a/combat_ui.cpp +++ b/combat_ui.cpp @@ -27,20 +27,10 @@ namespace gui { sf::Text label($font, name); auto bounds = label.getLocalBounds(); - fmt::println("CENTER w/h={},{} vs bounds={},{}", - cell.w, cell.h, bounds.size.x, bounds.size.y); auto label_cell = lel::center(bounds.size.x, bounds.size.y, cell); - label.setPosition({float(label_cell.x), float(label_cell.y)}); + // this stupid / 2 is because SFML renders from baseline rather than from the claimed bounding box + label.setPosition({float(label_cell.x), float(label_cell.y) - label_cell.h / 2}); $labels.push_back(label); - - - sf::RectangleShape label_box; - label_box.setPosition({float(label_cell.x), float(label_cell.y)}); - label_box.setSize({float(label_cell.w), float(label_cell.h)}); - label_box.setFillColor({10, 10, 10}); - label_box.setOutlineColor({100,100,100}); - label_box.setOutlineThickness(1.0); - $label_boxes.insert_or_assign("Z" + name, label_box); } }