Fix cascade menu bugs

This commit is contained in:
NaiJi ✨ 2021-08-26 21:22:19 +03:00
parent 592f1883aa
commit 76422b1e1f
5 changed files with 17 additions and 7 deletions

View File

@ -23,18 +23,28 @@ Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique
_bpm_calculator->startListening(0); _bpm_calculator->startListening(0);
}); });
auto test_menu_2 = std::make_shared<MenuDrop>();
test_menu_2->setRect(sf::FloatRect{0, 0, 200, 27 * 5});
auto test_cascade_button = std::make_shared<CascadeMenuButton>("Show submenu", font_holder.get(Fonts::Id::GUI));
auto quit_button = std::make_shared<PushButton>("Quit", font_holder.get(Fonts::Id::GUI)); auto quit_button = std::make_shared<PushButton>("Quit", font_holder.get(Fonts::Id::GUI));
quit_button->setCallback(callbacks.onLeaveEditorState); quit_button->setCallback(callbacks.onLeaveEditorState);
auto test_menu = std::make_shared<MenuDrop>(); auto test_menu = std::make_shared<MenuDrop>();
test_menu->setRect(sf::FloatRect{0, 0, 200, 27}); test_menu->setRect(sf::FloatRect{0, 0, 200, 27 * 3});
_menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27)); _menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27));
_menu_bar->addSubMenu("test", test_menu); _menu_bar->addSubMenu("test", test_menu);
test_cascade_button->setSubmenu(test_menu_2);
test_menu->addPushButton(bpm_button); test_menu->addPushButton(bpm_button);
test_menu->addCascadeButton(test_cascade_button);
test_menu->addPushButton(quit_button); test_menu->addPushButton(quit_button);
test_cascade_button->resetRect(test_menu_2);
_music->openFromFile("Uta-test.flac"); _music->openFromFile("Uta-test.flac");
_music->setVolume(5); _music->setVolume(5);
} }

View File

@ -1,5 +1,5 @@
#include "button.h" #include "button.h"
#include <iostream>
Button::Button(const std::string &text, const std::shared_ptr<sf::Font>& font, unsigned int font_size) : Button::Button(const std::string &text, const std::shared_ptr<sf::Font>& font, unsigned int font_size) :
_font(font) _font(font)
{ {

View File

@ -16,10 +16,11 @@ void CascadeMenuButton::input(const sf::Event& event)
break; break;
case sf::Event::MouseMoved: case sf::Event::MouseMoved:
if (isUnderMouse(event.mouseButton.x, event.mouseButton.y)) if (isUnderMouse(event.mouseMove.x, event.mouseMove.y))
{ {
_button_content.setFillColor(sf::Color(84, 158, 253)); _button_content.setFillColor(sf::Color(84, 158, 253));
_submenu->lock(); _submenu->lock();
_submenu->setVisibility(true);
} }
else else
{ {

View File

@ -13,10 +13,9 @@ public:
void setSubmenu(const std::shared_ptr<MenuDrop>& submenu); void setSubmenu(const std::shared_ptr<MenuDrop>& submenu);
const std::shared_ptr<MenuDrop> submenu() const; const std::shared_ptr<MenuDrop> submenu() const;
void resetRect(const std::shared_ptr<MenuDrop>& submenu);
private: private:
std::shared_ptr<MenuDrop> _submenu; std::shared_ptr<MenuDrop> _submenu;
void resetRect(const std::shared_ptr<MenuDrop>& submenu);
}; };

View File

@ -24,7 +24,7 @@ void MenuDrop::input(const sf::Event& event)
case sf::Event::MouseButtonReleased: case sf::Event::MouseButtonReleased:
case sf::Event::MouseMoved: case sf::Event::MouseMoved:
if (!isUnderMouse(event.mouseButton.x, event.mouseButton.y)) if (!isUnderMouse(event.mouseMove.x, event.mouseMove.y))
{ {
if (!isLocked() && !hasActiveSubmenus()) if (!isLocked() && !hasActiveSubmenus())
setVisibility(false); setVisibility(false);
@ -88,7 +88,7 @@ void MenuDrop::addCascadeButton(const std::shared_ptr<CascadeMenuButton>& button
{ {
auto& submenu = button->submenu(); auto& submenu = button->submenu();
submenu->setParent(_parent); submenu->setParent(_parent);
_submenus.emplace_back(); _submenus.emplace_back(submenu);
add(button); add(button);
} }