diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/components/Menu.cpp | 8 | ||||
-rw-r--r-- | src/ui/controls/Popup.cpp | 8 | ||||
-rw-r--r-- | src/ui/controls/RootControl.cpp | 42 | ||||
-rw-r--r-- | src/ui/controls/Window.cpp | 3 | ||||
-rw-r--r-- | src/ui/host/WindowHost.cpp | 13 |
5 files changed, 37 insertions, 37 deletions
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp index 964eead9..c3359cf9 100644 --- a/src/ui/components/Menu.cpp +++ b/src/ui/components/Menu.cpp @@ -28,7 +28,10 @@ MenuItem::~MenuItem() { void MenuItem::SetText(String text) { text_->SetText(std::move(text)); } -Menu::Menu() { container_ = controls::FlexLayout::Create(); } +Menu::Menu() { + container_ = controls::FlexLayout::Create(); + container_->SetFlexDirection(FlexDirection::Vertical); +} Menu::~Menu() { if (!container_->GetWindowHost()) { @@ -88,6 +91,7 @@ void PopupMenu::SetPosition(const Point& position) { void PopupMenu::Show() { popup_->GetWindowHost()->RelayoutWithSize(Size::Infinate(), true); - popup_->GetWindowHost()->GetNativeWindow()->SetVisible(true); + popup_->GetWindowHost()->GetNativeWindow()->SetVisibility( + platform::gui::WindowVisibilityType::Show); } } // namespace cru::ui::components diff --git a/src/ui/controls/Popup.cpp b/src/ui/controls/Popup.cpp index ae6ac1d2..b386165b 100644 --- a/src/ui/controls/Popup.cpp +++ b/src/ui/controls/Popup.cpp @@ -8,11 +8,9 @@ #include <memory> namespace cru::ui::controls { -Popup::Popup(Control* attached_control) - : RootControl( - attached_control, - host::CreateWindowParams{ - nullptr, platform::gui::CreateWindowFlags::NoCaptionAndBorder}) { +Popup::Popup(Control* attached_control) : RootControl(attached_control) { + GetWindowHost()->GetNativeWindow()->SetStyleFlag( + cru::platform::gui::WindowStyleFlags::NoCaptionAndBorder); SetGainFocusOnCreateAndDestroyWhenLoseFocus(true); } diff --git a/src/ui/controls/RootControl.cpp b/src/ui/controls/RootControl.cpp index 4ae41c80..d89982c5 100644 --- a/src/ui/controls/RootControl.cpp +++ b/src/ui/controls/RootControl.cpp @@ -11,29 +11,12 @@ #include <memory> namespace cru::ui::controls { -RootControl::RootControl(Control* attached_control, - host::CreateWindowParams params) +RootControl::RootControl(Control* attached_control) : attached_control_(attached_control) { render_object_ = std::make_unique<render::StackLayoutRenderObject>(); render_object_->SetAttachedControl(this); SetContainerRenderObject(render_object_.get()); - window_host_ = std::make_unique<host::WindowHost>(this, params); - - if (gain_focus_on_create_and_destroy_when_lose_focus_) { - auto native_window = window_host_->GetNativeWindow(); - native_window->CreateEvent()->AddHandler( - [](platform::gui::INativeWindow* window) { - window->CreateEvent()->AddHandler( - [window](std::nullptr_t) { window->RequestFocus(); }); - }); - - native_window->FocusEvent()->AddHandler( - [native_window](platform::gui::FocusChangeType type) { - if (type == platform::gui::FocusChangeType::Lost) { - native_window->Close(); - } - }); - } + window_host_ = std::make_unique<host::WindowHost>(this); } RootControl::~RootControl() {} @@ -43,6 +26,25 @@ render::RenderObject* RootControl::GetRenderObject() const { } void RootControl::SetGainFocusOnCreateAndDestroyWhenLoseFocus(bool value) { - gain_focus_on_create_and_destroy_when_lose_focus_ = value; + gain_focus_on_create_and_destroy_when_lose_focus_event_guard_.Clear(); + if (value) { + auto native_window = window_host_->GetNativeWindow(); + + gain_focus_on_create_and_destroy_when_lose_focus_event_guard_ += + native_window->VisibilityChangeEvent()->AddHandler( + [native_window](platform::gui::WindowVisibilityType type) { + if (type == platform::gui::WindowVisibilityType::Show) { + native_window->RequestFocus(); + } + }); + + gain_focus_on_create_and_destroy_when_lose_focus_event_guard_ += + native_window->FocusEvent()->AddHandler( + [native_window](platform::gui::FocusChangeType type) { + if (type == platform::gui::FocusChangeType::Lost) { + native_window->Close(); + } + }); + } } } // namespace cru::ui::controls diff --git a/src/ui/controls/Window.cpp b/src/ui/controls/Window.cpp index 00fab8e9..76203f22 100644 --- a/src/ui/controls/Window.cpp +++ b/src/ui/controls/Window.cpp @@ -12,8 +12,7 @@ Window* Window::Create(Control* attached_control) { return new Window(attached_control); } -Window::Window(Control* attached_control) - : RootControl(attached_control, host::CreateWindowParams{}) {} +Window::Window(Control* attached_control) : RootControl(attached_control) {} Window::~Window() {} } // namespace cru::ui::controls diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index 3f3976b4..034d9bd8 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -8,7 +8,6 @@ #include "cru/platform/gui/UiApplication.hpp" #include "cru/platform/gui/Window.hpp" #include "cru/ui/DebugFlags.hpp" -#include "cru/ui/controls/Window.hpp" #include "cru/ui/host/LayoutPaintCycler.hpp" #include "cru/ui/render/MeasureRequirement.hpp" #include "cru/ui/render/RenderObject.hpp" @@ -104,8 +103,7 @@ inline void BindNativeEvent( } } // namespace -WindowHost::WindowHost(controls::Control* root_control, - CreateWindowParams params) +WindowHost::WindowHost(controls::Control* root_control) : root_control_(root_control), focus_control_(root_control) { root_control_->TraverseDescendants([this](controls::Control* control) { control->window_host_ = this; @@ -117,17 +115,16 @@ WindowHost::WindowHost(controls::Control* root_control, this->layout_paint_cycler_ = std::make_unique<LayoutPaintCycler>(this); - CreateNativeWindow(params); + CreateNativeWindow(); } WindowHost::~WindowHost() {} -gsl::not_null<platform::gui::INativeWindow*> WindowHost::CreateNativeWindow( - CreateWindowParams create_window_params) { +gsl::not_null<platform::gui::INativeWindow*> WindowHost::CreateNativeWindow() { const auto ui_application = IUiApplication::GetInstance(); - auto native_window = ui_application->CreateWindow(create_window_params.parent, - create_window_params.flag); + auto native_window = ui_application->CreateWindow(); + Ensures(native_window); native_window_ = native_window; |