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.

Zed A. Shaw 3 weeks ago
parent 55feff23fb
commit f884b83809
  1. 14
      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);
}
}

Loading…
Cancel
Save