forked from NaiJi/project-kyoku
Remove hardcode for button size
This commit is contained in:
parent
a0ad8e7ed6
commit
c2677bdd2b
|
@ -6,13 +6,15 @@ MainMenu::MainMenu(sf::RenderWindow& game_window, Callbacks&& callbacks) :
|
|||
_buttons(std::make_shared<Group>()),
|
||||
_game_window(game_window)
|
||||
{
|
||||
const float window_width = game_window.getSize().x;
|
||||
const float window_height = game_window.getSize().y;
|
||||
|
||||
std::shared_ptr<Button> button_start = std::make_shared<Button>("Start");
|
||||
button_start->setRect(sf::FloatRect(140, 140, 500, 100));
|
||||
button_start->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 2, window_width / 3., window_height / 7.));
|
||||
button_start->setCallback(callbacks.onAppendGameState);
|
||||
|
||||
std::shared_ptr<Button> button_exit = std::make_shared<Button>("Exit");
|
||||
button_exit->setRect(sf::FloatRect(140, 140, 400, 100));
|
||||
button_exit->setPosition({240, 340});
|
||||
button_exit->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 4, window_width / 3., window_height / 7.));
|
||||
button_exit->setCallback([&]()
|
||||
{
|
||||
_game_window.close();
|
||||
|
|
|
@ -53,7 +53,7 @@ void Button::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|||
void Button::setRect(const sf::FloatRect& rect)
|
||||
{
|
||||
_button_content.setPosition(rect.left, rect.top);
|
||||
_button_content.setSize({rect.width - rect.left, rect.height - rect.top});
|
||||
_button_content.setSize({rect.width, rect.height});
|
||||
}
|
||||
|
||||
void Button::setPosition(const sf::Vector2f &position)
|
||||
|
|
Loading…
Reference in New Issue