aboutsummaryrefslogtreecommitdiff
path: root/src/ui/components/PopupButton.cpp
blob: 41e0ad6cf7a575d40369f6aedbb149ee075ef401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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.GetDownPointOfScreen());
    popup_menu_.Show();
  });
}

PopupMenuTextButton::~PopupMenuTextButton() {}

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); });
  }
}

PopupMenuIconButton::PopupMenuIconButton() : popup_menu_(&button_) {
  button_.ClickEvent()->AddHandler([this](const helper::ClickEventArgs& args) {
    popup_menu_.SetPosition(args.GetDownPointOfScreen());
    popup_menu_.Show();
  });
}

PopupMenuIconButton::~PopupMenuIconButton() {}

void PopupMenuIconButton::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