aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/components
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-12-04 18:06:43 +0800
committercrupest <crupest@outlook.com>2021-12-04 18:06:43 +0800
commit942f1d34c48e61a853db745cd68e46db13266a5c (patch)
treefdb859933dbb302404391ed686bae8c7126c96ee /include/cru/ui/components
parent2317061516b0bd0002467acbead3120cbe49a6c5 (diff)
downloadcru-942f1d34c48e61a853db745cd68e46db13266a5c.tar.gz
cru-942f1d34c48e61a853db745cd68e46db13266a5c.tar.bz2
cru-942f1d34c48e61a853db745cd68e46db13266a5c.zip
...
Diffstat (limited to 'include/cru/ui/components')
-rw-r--r--include/cru/ui/components/Menu.hpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/include/cru/ui/components/Menu.hpp b/include/cru/ui/components/Menu.hpp
index 96b21173..a72c0313 100644
--- a/include/cru/ui/components/Menu.hpp
+++ b/include/cru/ui/components/Menu.hpp
@@ -7,6 +7,7 @@
#include "cru/ui/controls/Popup.hpp"
#include "cru/ui/controls/TextBlock.hpp"
+#include <functional>
#include <vector>
namespace cru::ui::components {
@@ -25,9 +26,14 @@ class MenuItem : public Component {
void SetText(String text);
+ void SetOnClick(std::function<void()> on_click) {
+ on_click_ = std::move(on_click);
+ }
+
private:
controls::Button* container_;
controls::TextBlock* text_;
+ std::function<void()> on_click_;
};
class Menu : public Component {
@@ -49,11 +55,13 @@ class Menu : public Component {
void AddItem(Component* component) { AddItem(component, GetItemCount()); }
void AddItem(Component* component, gsl::index index);
Component* RemoveItem(gsl::index index);
+ void ClearItems();
- void AddTextItem(String text) {
- AddTextItem(std::move(text), GetItemCount());
+ void AddTextItem(String text, std::function<void()> on_click) {
+ AddTextItem(std::move(text), GetItemCount(), std::move(on_click));
}
- void AddTextItem(String text, gsl::index index);
+ void AddTextItem(String text, gsl::index index,
+ std::function<void()> on_click);
private:
controls::FlexLayout* container_;
@@ -77,6 +85,7 @@ class PopupMenu : public Component {
void SetPosition(const Point& position);
void Show();
+ void Close();
private:
controls::Control* attached_control_;