diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-17 12:54:55 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-17 12:54:55 +0800 |
| commit | 0f8f98b9005803ab154b43dcad0db1f292072a4d (patch) | |
| tree | 0a43d5a9c4e3b747ad955fc30a143aa07ab5888d /src/ui/components/Menu.cpp | |
| parent | b68f9f52a3ecdd8e379dd60ac1c1366e76695464 (diff) | |
| download | cru-0f8f98b9005803ab154b43dcad0db1f292072a4d.tar.gz cru-0f8f98b9005803ab154b43dcad0db1f292072a4d.tar.bz2 cru-0f8f98b9005803ab154b43dcad0db1f292072a4d.zip | |
Refactor window host.
Diffstat (limited to 'src/ui/components/Menu.cpp')
| -rw-r--r-- | src/ui/components/Menu.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp index 04227d66..c89c7fc9 100644 --- a/src/ui/components/Menu.cpp +++ b/src/ui/components/Menu.cpp @@ -4,10 +4,9 @@ #include "cru/ui/controls/Button.h" #include "cru/ui/controls/Control.h" #include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/Popup.h" #include "cru/ui/controls/TextBlock.h" +#include "cru/ui/controls/Window.h" #include "cru/ui/helper/ClickDetector.h" -#include "cru/ui/host/WindowHost.h" #include "cru/ui/style/StyleRuleSet.h" namespace cru::ui::components { @@ -22,8 +21,6 @@ MenuItem::MenuItem() { MenuItem::MenuItem(std::string text) : MenuItem() { SetText(std::move(text)); } -MenuItem::~MenuItem() {} - void MenuItem::SetText(std::string text) { text_.SetText(std::move(text)); } Menu::Menu() { @@ -33,7 +30,7 @@ Menu::Menu() { Menu::~Menu() { for (auto item : items_) { - item->DeleteIfDeleteByParent(false); + item->DeleteIfDeleteByParent(); } } @@ -78,27 +75,29 @@ void Menu::AddTextItemAt(std::string text, Index index, } PopupMenu::PopupMenu(controls::Control* attached_control) - : attached_control_(attached_control), popup_(attached_control) { - menu_.SetOnItemClick([this](Index) { popup_.GetNativeWindow()->Close(); }); - popup_.AddChildAt(menu_.GetRootControl(), 0); + : attached_control_(attached_control) { + menu_.SetOnItemClick([this](Index) { popup_->GetNativeWindow()->Close(); }); + popup_ = controls::Window::CreatePopup(); + popup_->SetAttachedControl(attached_control); + popup_->AddChildAt(menu_.GetRootControl(), 0); } -PopupMenu::~PopupMenu() {} +PopupMenu::~PopupMenu() { delete popup_; } -controls::Control* PopupMenu::GetRootControl() { return &popup_; } +controls::Control* PopupMenu::GetRootControl() { return popup_; } void PopupMenu::SetPosition(const Point& position) { - auto window = popup_.GetWindowHost()->GetNativeWindow(); + auto window = popup_->GetNativeWindow(); window->SetClientRect(Rect{position, window->GetClientSize()}); } void PopupMenu::Show() { - auto native_window = popup_.GetWindowHost()->GetNativeWindow(); + auto native_window = popup_->GetNativeWindow(); native_window->SetVisibility(platform::gui::WindowVisibilityType::Show); - popup_.GetWindowHost()->RelayoutWithSize(Size::Infinite(), true); + popup_->RelayoutWithSize(Size::Infinite(), true); native_window->RequestFocus(); native_window->SetToForeground(); } -void PopupMenu::Close() { popup_.GetWindowHost()->GetNativeWindow()->Close(); } +void PopupMenu::Close() { popup_->GetNativeWindow()->Close(); } } // namespace cru::ui::components |
