diff options
author | crupest <crupest@outlook.com> | 2021-11-20 22:43:30 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-11-20 22:43:30 +0800 |
commit | a60910cb3db6f47fd8f3b7f31648a9d0514d4f2c (patch) | |
tree | 32c01c22e21742ae0c9febb2cbc26339f99eec1d /src/ui/host | |
parent | 1a53ed0791d9793ed8030d3a44e833e5e7c4542b (diff) | |
download | cru-a60910cb3db6f47fd8f3b7f31648a9d0514d4f2c.tar.gz cru-a60910cb3db6f47fd8f3b7f31648a9d0514d4f2c.tar.bz2 cru-a60910cb3db6f47fd8f3b7f31648a9d0514d4f2c.zip |
...
Diffstat (limited to 'src/ui/host')
-rw-r--r-- | src/ui/host/WindowHost.cpp | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index d26b43ab..3f3976b4 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -104,7 +104,8 @@ inline void BindNativeEvent( } } // namespace -WindowHost::WindowHost(controls::Control* root_control) +WindowHost::WindowHost(controls::Control* root_control, + CreateWindowParams params) : root_control_(root_control), focus_control_(root_control) { root_control_->TraverseDescendants([this](controls::Control* control) { control->window_host_ = this; @@ -115,14 +116,14 @@ WindowHost::WindowHost(controls::Control* root_control) root_render_object_->SetWindowHostRecursive(this); this->layout_paint_cycler_ = std::make_unique<LayoutPaintCycler>(this); + + CreateNativeWindow(params); } WindowHost::~WindowHost() {} gsl::not_null<platform::gui::INativeWindow*> WindowHost::CreateNativeWindow( CreateWindowParams create_window_params) { - if (native_window_ != nullptr) return native_window_; - const auto ui_application = IUiApplication::GetInstance(); auto native_window = ui_application->CreateWindow(create_window_params.parent, @@ -153,10 +154,6 @@ gsl::not_null<platform::gui::INativeWindow*> WindowHost::CreateNativeWindow( BindNativeEvent(this, native_window, native_window->KeyUpEvent(), &WindowHost::OnNativeKeyUp, event_revoker_guards_); - if (saved_rect_) { - native_window->SetWindowRect(saved_rect_.value()); - } - native_window_change_event_.Raise(native_window); return native_window_; @@ -194,8 +191,7 @@ void WindowHost::RelayoutWithSize(const Size& available_size, render::MeasureSize::NotSpecified()); if (set_window_size_to_fit_content) { - auto rect = GetWindowRect(); - SetWindowRect({rect.GetLeftTop(), root_render_object_->GetSize()}); + native_window_->SetClientSize(root_render_object_->GetSize()); } root_render_object_->Layout(Point{}); @@ -277,29 +273,8 @@ void WindowHost::RunAfterLayoutStable(std::function<void()> action) { } } -Rect WindowHost::GetWindowRect() { - if (native_window_) return native_window_->GetWindowRect(); - return saved_rect_.value_or(Rect{}); -} - -void WindowHost::SetSavedWindowRect(std::optional<Rect> rect) { - saved_rect_ = std::move(rect); -} - -void WindowHost::SetWindowRect(const Rect& rect) { - SetSavedWindowRect(rect); - if (native_window_) native_window_->SetWindowRect(rect); -} - void WindowHost::OnNativeDestroy(INativeWindow* window, std::nullptr_t) { CRU_UNUSED(window) - - saved_rect_ = this->native_window_->GetWindowRect(); - - this->native_window_ = nullptr; - event_revoker_guards_.clear(); - - native_window_change_event_.Raise(nullptr); } void WindowHost::OnNativePaint(INativeWindow* window, std::nullptr_t) { |