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.
This commit is contained in:
parent
55feff23fb
commit
f884b83809
1 changed files with 2 additions and 12 deletions
|
@ -27,20 +27,10 @@ namespace gui {
|
||||||
|
|
||||||
sf::Text label($font, name);
|
sf::Text label($font, name);
|
||||||
auto bounds = label.getLocalBounds();
|
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);
|
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);
|
$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…
Add table
Add a link
Reference in a new issue