mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(ui): add button enable/disable and reset on re-enter
Prevent double-clicking on buttons that push new scenes by disabling them on click and re-enabling when the UI manager's on_re_enter is called.
This commit is contained in:
@@ -31,7 +31,7 @@ public:
|
||||
Button& set_text(const std::string& text);
|
||||
|
||||
Button& set_auto_scale(bool auto_scale);
|
||||
|
||||
Button& set_enable(bool enable);
|
||||
float scale() const;
|
||||
template <typename F> Button& set_clicked(F&& f) {
|
||||
m_clicked = std::forward<F>(f);
|
||||
@@ -49,6 +49,7 @@ private:
|
||||
std::unique_ptr<Image> m_background;
|
||||
std::unique_ptr<Label> m_foreground;
|
||||
bool m_hovered = false;
|
||||
bool m_enable = true;
|
||||
float m_width = NORMAL_BUTTON_WIDTH;
|
||||
float m_height = NORMAL_BUTTON_HEIGHT;
|
||||
float m_scale = DEFAULT_SCALE;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/ui/button.hpp"
|
||||
#include "Cubed/ui/ui_manager.hpp"
|
||||
|
||||
namespace Cubed {
|
||||
@@ -15,8 +16,10 @@ public:
|
||||
~MainMenuUIManager();
|
||||
|
||||
void init() override;
|
||||
void on_re_enter();
|
||||
|
||||
private:
|
||||
MainMenuScene& m_scene;
|
||||
std::vector<Button*> m_pending_enable;
|
||||
};
|
||||
} // namespace Cubed
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/ui/button.hpp"
|
||||
#include "Cubed/ui/ui_manager.hpp"
|
||||
namespace Cubed {
|
||||
class WorldScene;
|
||||
@@ -11,8 +12,10 @@ public:
|
||||
PauseMenuUIManager& operator=(PauseMenuUIManager&&) = delete;
|
||||
PauseMenuUIManager(WorldScene& scene);
|
||||
void init() override;
|
||||
void on_re_enter();
|
||||
|
||||
private:
|
||||
WorldScene& m_scene;
|
||||
std::vector<Button*> m_pending_enable;
|
||||
};
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user