aboutsummaryrefslogtreecommitdiff
path: root/src/ui/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/components')
-rw-r--r--src/ui/components/Menu.cpp19
-rw-r--r--src/ui/components/Select.cpp2
2 files changed, 12 insertions, 9 deletions
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp
index ea1afc07..9170c6d2 100644
--- a/src/ui/components/Menu.cpp
+++ b/src/ui/components/Menu.cpp
@@ -8,22 +8,22 @@
#include "cru/ui/controls/TextBlock.h"
#include "cru/ui/controls/Window.h"
#include "cru/ui/helper/ClickDetector.h"
-#include "cru/ui/style/StyleRuleSet.h"
namespace cru::ui::components {
MenuItem::MenuItem() {
container_.SetChild(&text_);
container_.GetStyleRuleSet()->SetParent(
ThemeManager::GetInstance()->GetResourceStyleRuleSet("menuitem.style"));
- container_.ClickEvent()->AddHandler([this](const helper::ClickEventArgs&) {
- if (this->on_click_) this->on_click_();
- });
}
MenuItem::MenuItem(std::string text) : MenuItem() { SetText(std::move(text)); }
void MenuItem::SetText(std::string text) { text_.SetText(std::move(text)); }
+IEvent<const helper::ClickEventArgs&>* MenuItem::ClickEvent() {
+ return container_.ClickEvent();
+}
+
Menu::Menu() {
container_.SetFlexDirection(controls::FlexDirection::Vertical);
container_.SetItemCrossAlign(controls::FlexCrossAlignment::Stretch);
@@ -66,11 +66,12 @@ void Menu::ClearItems() {
void Menu::AddTextItemAt(std::string text, Index index,
std::function<void()> on_click) {
MenuItem* item = new MenuItem(std::move(text));
- item->SetOnClick([this, index, on_click = std::move(on_click)] {
- auto on_item_click = on_item_click_;
- on_click();
- if (on_item_click) on_item_click(index);
- });
+ item->ClickEvent()->AddSpyOnlyHandler(
+ [this, index, on_click = std::move(on_click)] {
+ auto on_item_click = on_item_click_;
+ on_click();
+ if (on_item_click) on_item_click(index);
+ });
item->SetDeleteByParent(true);
AddItemAt(item, index);
}
diff --git a/src/ui/components/Select.cpp b/src/ui/components/Select.cpp
index 5dbb727c..da81017f 100644
--- a/src/ui/components/Select.cpp
+++ b/src/ui/components/Select.cpp
@@ -11,6 +11,8 @@ Select::Select() {
left_bottom);
popup_menu_.Show();
});
+
+ popup_menu_.GetPopup()->SetAttachedControl(&button_);
}
Select::~Select() {}