diff options
author | crupest <crupest@outlook.com> | 2022-02-15 20:52:37 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-15 20:52:37 +0800 |
commit | fa6e9a419f688df12a57199aa3b4dce10cc6fd49 (patch) | |
tree | ab29f60da18826d287e84bb53bc124694fcccb2a /src/ui/components/PopupButton.cpp | |
parent | 85f4cb239f10e1801e43f0874a4f637def5daaee (diff) | |
download | cru-fa6e9a419f688df12a57199aa3b4dce10cc6fd49.tar.gz cru-fa6e9a419f688df12a57199aa3b4dce10cc6fd49.tar.bz2 cru-fa6e9a419f688df12a57199aa3b4dce10cc6fd49.zip |
...
Diffstat (limited to 'src/ui/components/PopupButton.cpp')
-rw-r--r-- | src/ui/components/PopupButton.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ui/components/PopupButton.cpp b/src/ui/components/PopupButton.cpp new file mode 100644 index 00000000..606d5fd8 --- /dev/null +++ b/src/ui/components/PopupButton.cpp @@ -0,0 +1,24 @@ +#include "cru/ui/components/PopupButton.h" +#include "cru/ui/components/Menu.h" +#include "cru/ui/controls/Popup.h" +#include "cru/ui/helper/ClickDetector.h" + +namespace cru::ui::components { +PopupMenuTextButton::PopupMenuTextButton() : popup_menu_(&button_) { + button_.SetChild(&button_text_); + button_.ClickEvent()->AddHandler([this](const helper::ClickEventArgs& args) { + popup_menu_.SetPosition(args.GetDownPoint()); + popup_menu_.Show(); + }); +} + +PopupMenuTextButton::~PopupMenuTextButton() { button_.RemoveFromParent(); } + +void PopupMenuTextButton::SetMenuItems(std::vector<String> items) { + popup_menu_.GetMenu()->ClearItems(); + for (Index i = 0; i < items.size(); i++) { + popup_menu_.GetMenu()->AddTextItem( + std::move(items[i]), [this, i] { menu_item_selected_event_.Raise(i); }); + } +} +} // namespace cru::ui::components |