diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/ui/components/Menu.hpp | 15 | ||||
-rw-r--r-- | include/cru/ui/controls/Button.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/controls/LayoutControl.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/controls/TextHostControlService.hpp | 20 |
4 files changed, 38 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_; diff --git a/include/cru/ui/controls/Button.hpp b/include/cru/ui/controls/Button.hpp index 9e324c62..e0335a39 100644 --- a/include/cru/ui/controls/Button.hpp +++ b/include/cru/ui/controls/Button.hpp @@ -39,6 +39,10 @@ class Button : public ContentControl, return click_detector_.StateChangeEvent(); } + IEvent<helper::ClickEventArgs>* ClickEvent() { + return click_detector_.ClickEvent(); + } + void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override; private: diff --git a/include/cru/ui/controls/LayoutControl.hpp b/include/cru/ui/controls/LayoutControl.hpp index 106dd94d..381df1df 100644 --- a/include/cru/ui/controls/LayoutControl.hpp +++ b/include/cru/ui/controls/LayoutControl.hpp @@ -18,6 +18,8 @@ class LayoutControl : public Control { using Control::AddChild; using Control::RemoveChild; + void ClearChildren(); + protected: // If container render object is not null. Render object of added or removed // child control will automatically sync to the container render object. diff --git a/include/cru/ui/controls/TextHostControlService.hpp b/include/cru/ui/controls/TextHostControlService.hpp index 6ebe2a27..5216827b 100644 --- a/include/cru/ui/controls/TextHostControlService.hpp +++ b/include/cru/ui/controls/TextHostControlService.hpp @@ -15,6 +15,10 @@ class TextRenderObject; class ScrollRenderObject; } // namespace cru::ui::render +namespace cru::ui::components { +class PopupMenu; +} + namespace cru::ui::controls { constexpr int k_default_caret_blink_duration = 500; @@ -86,6 +90,9 @@ class TextHostControlService : public Object { bool IsEditable() { return this->editable_; } void SetEditable(bool editable); + bool IsContextMenuEnabled() { return this->context_menu_enabled_; } + void SetContextMenuEnabled(bool enabled); + bool IsMultiLine() { return this->multi_line_; } // If text contains line feed characters, it will be converted to space. void SetMultiLine(bool multi_line); @@ -169,6 +176,15 @@ class TextHostControlService : public Object { void SetUpShortcuts(); + enum ContextMenuItem : unsigned { + kSelectAll = 0b1, + kCut = 0b10, + kCopy = 0b100, + kPaste = 0b1000 + }; + + void OpenContextMenu(const Point& position, ContextMenuItem items); + private: gsl::not_null<Control*> control_; gsl::not_null<ITextHostControl*> text_host_control_; @@ -182,6 +198,7 @@ class TextHostControlService : public Object { bool enable_ = false; bool editable_ = false; bool multi_line_ = false; + bool context_menu_enabled_ = true; bool caret_visible_ = false; platform::gui::TimerAutoCanceler caret_timer_canceler_; @@ -191,5 +208,8 @@ class TextHostControlService : public Object { // true if left mouse is down and selecting bool mouse_move_selecting_ = false; + + bool context_menu_dirty_ = true; + std::unique_ptr<components::PopupMenu> context_menu_; }; } // namespace cru::ui::controls |