From 1a53ed0791d9793ed8030d3a44e833e5e7c4542b Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 20 Nov 2021 21:25:29 +0800 Subject: ... --- include/cru/ui/components/Menu.hpp | 29 ++++++++++++++++++++++++++++- include/cru/ui/controls/Popup.hpp | 8 ++++++++ include/cru/ui/host/WindowHost.hpp | 5 +++-- 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'include/cru') diff --git a/include/cru/ui/components/Menu.hpp b/include/cru/ui/components/Menu.hpp index d60d38eb..96b21173 100644 --- a/include/cru/ui/components/Menu.hpp +++ b/include/cru/ui/components/Menu.hpp @@ -4,9 +4,9 @@ #include "cru/ui/controls/Button.hpp" #include "cru/ui/controls/Control.hpp" #include "cru/ui/controls/FlexLayout.hpp" +#include "cru/ui/controls/Popup.hpp" #include "cru/ui/controls/TextBlock.hpp" -#include #include namespace cru::ui::components { @@ -40,6 +40,8 @@ class Menu : public Component { ~Menu(); public: + controls::Control* GetRootControl() override { return container_; } + gsl::index GetItemCount() const { return static_cast(items_.size()); } @@ -57,4 +59,29 @@ class Menu : public Component { controls::FlexLayout* container_; std::vector items_; }; + +class PopupMenu : public Component { + public: + explicit PopupMenu(controls::Control* attached_control = nullptr); + + CRU_DELETE_COPY(PopupMenu) + CRU_DELETE_MOVE(PopupMenu) + + ~PopupMenu(); + + public: + controls::Control* GetRootControl() override; + + controls::Popup* GetPopup() { return popup_; } + Menu* GetMenu() { return menu_; } + + void SetPosition(const Point& position); + void Show(); + + private: + controls::Control* attached_control_; + + controls::Popup* popup_; + Menu* menu_; +}; } // namespace cru::ui::components diff --git a/include/cru/ui/controls/Popup.hpp b/include/cru/ui/controls/Popup.hpp index 321bbbc6..cd5e1813 100644 --- a/include/cru/ui/controls/Popup.hpp +++ b/include/cru/ui/controls/Popup.hpp @@ -8,6 +8,12 @@ namespace cru::ui::controls { class Popup : public RootControl { public: + static constexpr StringView kControlType = u"Popup"; + + static Popup* Create(Control* attached_control = nullptr) { + return new Popup(attached_control); + } + explicit Popup(Control* attached_control = nullptr); CRU_DELETE_COPY(Popup) @@ -15,6 +21,8 @@ class Popup : public RootControl { ~Popup() override; + String GetControlType() const override { return kControlType.ToString(); } + protected: gsl::not_null CreateNativeWindow( gsl::not_null host, diff --git a/include/cru/ui/host/WindowHost.hpp b/include/cru/ui/host/WindowHost.hpp index 258b0c4c..f3caeeef 100644 --- a/include/cru/ui/host/WindowHost.hpp +++ b/include/cru/ui/host/WindowHost.hpp @@ -59,7 +59,8 @@ class WindowHost : public Object { } void Relayout(); - void Relayout(const Size& available_size); + void RelayoutWithSize(const Size& available_size = Size::Infinate(), + bool set_window_size_to_fit_content = false); void Repaint(); @@ -173,7 +174,7 @@ class WindowHost : public Object { controls::Control* mouse_captured_control_ = nullptr; - bool layout_prefer_to_fill_window_ = true; + bool layout_prefer_to_fill_window_ = false; Event native_window_change_event_; -- cgit v1.2.3