diff options
author | crupest <crupest@outlook.com> | 2021-12-04 18:06:43 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-12-04 18:06:43 +0800 |
commit | 942f1d34c48e61a853db745cd68e46db13266a5c (patch) | |
tree | fdb859933dbb302404391ed686bae8c7126c96ee /src/ui/controls | |
parent | 2317061516b0bd0002467acbead3120cbe49a6c5 (diff) | |
download | cru-942f1d34c48e61a853db745cd68e46db13266a5c.tar.gz cru-942f1d34c48e61a853db745cd68e46db13266a5c.tar.bz2 cru-942f1d34c48e61a853db745cd68e46db13266a5c.zip |
...
Diffstat (limited to 'src/ui/controls')
-rw-r--r-- | src/ui/controls/LayoutControl.cpp | 6 | ||||
-rw-r--r-- | src/ui/controls/TextHostControlService.cpp | 36 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/ui/controls/LayoutControl.cpp b/src/ui/controls/LayoutControl.cpp index 5954853e..e5a38445 100644 --- a/src/ui/controls/LayoutControl.cpp +++ b/src/ui/controls/LayoutControl.cpp @@ -3,6 +3,12 @@ #include "cru/ui/render/RenderObject.hpp" namespace cru::ui::controls { +void LayoutControl::ClearChildren() { + while (GetChildren().size() > 0) { + RemoveChild(0); + } +} + void LayoutControl::OnAddChild(Control* child, Index position) { if (container_render_object_ != nullptr) { container_render_object_->AddChild(child->GetRenderObject(), position); diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index b250ccae..90896632 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -14,12 +14,15 @@ #include "cru/platform/gui/Window.hpp" #include "cru/ui/Base.hpp" #include "cru/ui/DebugFlags.hpp" +#include "cru/ui/components/Menu.hpp" #include "cru/ui/events/UiEvent.hpp" #include "cru/ui/helper/ShortcutHub.hpp" #include "cru/ui/host/WindowHost.hpp" #include "cru/ui/render/ScrollRenderObject.hpp" #include "cru/ui/render/TextRenderObject.hpp" +#include <memory> + namespace cru::ui::controls { TextControlMovePattern TextControlMovePattern::kLeft( helper::ShortcutKeyBind(platform::gui::KeyCode::Left), @@ -119,6 +122,8 @@ std::vector<TextControlMovePattern> TextControlMovePattern::kDefaultPatterns = { TextHostControlService::TextHostControlService(gsl::not_null<Control*> control) : control_(control), text_host_control_(dynamic_cast<ITextHostControl*>(control.get())) { + context_menu_ = std::make_unique<components::PopupMenu>(); + SetUpShortcuts(); SetupOneHandler(&Control::MouseMoveEvent, @@ -152,6 +157,16 @@ void TextHostControlService::SetEnabled(bool enable) { } } +void TextHostControlService::SetContextMenuEnabled(bool enabled) { + if (context_menu_enabled_ == enabled) return; + + context_menu_enabled_ = enabled; + + if (!context_menu_enabled_ && context_menu_) { + context_menu_->Close(); + } +} + void TextHostControlService::SetEditable(bool editable) { this->editable_ = editable; if (!editable) CancelComposition(); @@ -594,4 +609,25 @@ void TextHostControlService::SetUpShortcuts() { }); } } + +void TextHostControlService::OpenContextMenu(const Point& position, + ContextMenuItem items) { + context_menu_ = std::make_unique<components::PopupMenu>(); + auto menu = context_menu_->GetMenu(); + if (items & ContextMenuItem::kSelectAll) { + menu->AddTextItem(u"Select All", [this] { this->SelectAll(); }); + } + if (items & ContextMenuItem::kCopy) { + menu->AddTextItem(u"Copy", [this] { this->Copy(); }); + } + if (items & ContextMenuItem::kCut) { + menu->AddTextItem(u"Cut", [this] { this->Cut(); }); + } + if (items & ContextMenuItem::kPaste) { + menu->AddTextItem(u"Paste", [this] { this->Paste(); }); + } + context_menu_->SetPosition(position); + context_menu_->Show(); +} + } // namespace cru::ui::controls |