Fix cascade menu render in Editor

This commit is contained in:
NaiJi ✨ 2021-08-31 11:42:58 +03:00
parent dbe26c5d9a
commit 1ac47b8b24
4 changed files with 11 additions and 4 deletions

View File

@ -66,7 +66,9 @@ void Editor::enter()
test_menu->setRect(sf::FloatRect{0, 0, 200, 27 * 3});
_menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27));
_menu_bar->addSubMenu("test", test_menu);
_menu_bar->addRootSubMenu("test", test_menu);
_menu_bar->addDependentSubmenu(test_menu_2);
_menu_bar->addDependentSubmenu(test_menu_3);
test_cascade_button->setSubmenu(test_menu_2);

View File

@ -61,7 +61,6 @@ void CascadeMenuButton::resetRect()
{
_submenu->setPosition({_button_content.getPosition().x + _button_content.getSize().x,
_button_content.getPosition().y});
_submenu->setVisibility(false);
}
}

View File

@ -67,7 +67,7 @@ bool MenuBar::isUnderMouse(int mouse_x, int mouse_y) const
return bar_under_mouse || submenus_under_mouse;
}
void MenuBar::addSubMenu(std::string name, const std::shared_ptr<MenuDrop>& submenu)
void MenuBar::addRootSubMenu(std::string name, const std::shared_ptr<MenuDrop>& submenu)
{
const auto new_button = std::make_shared<PushButton>(name, _font);
@ -91,6 +91,11 @@ void MenuBar::addSubMenu(std::string name, const std::shared_ptr<MenuDrop>& subm
++_amount_buttons;
}
void MenuBar::addDependentSubmenu(const std::shared_ptr<MenuDrop> &submenu)
{
_submenus.emplace_back(submenu);;
}
void MenuBar::setVisibility(bool is_visible)
{
Widget::setVisibility(is_visible);

View File

@ -19,7 +19,8 @@ public:
virtual bool isUnderMouse(int mouse_x, int mouse_y) const override;
virtual void setVisibility(bool is_visible = true) override;
void addSubMenu(std::string name, const std::shared_ptr<MenuDrop>& submenu);
void addRootSubMenu(std::string name, const std::shared_ptr<MenuDrop>& submenu);
void addDependentSubmenu(const std::shared_ptr<MenuDrop>& submenu);
private:
std::shared_ptr<sf::Font> _font;