diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/platform/gui/win/Window.cpp | 10 | ||||
| -rw-r--r-- | src/ui/components/Menu.cpp | 6 | ||||
| -rw-r--r-- | src/ui/controls/Control.cpp | 10 | ||||
| -rw-r--r-- | src/ui/controls/ControlHost.cpp | 15 |
4 files changed, 18 insertions, 23 deletions
diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp index 02357336..eb5112f5 100644 --- a/src/platform/gui/win/Window.cpp +++ b/src/platform/gui/win/Window.cpp @@ -4,7 +4,6 @@ #include "cru/base/log/Logger.h" #include "cru/platform/graphics/NullPainter.h" #include "cru/platform/graphics/direct2d/WindowPainter.h" -#include "cru/platform/gui/DebugFlags.h" #include "cru/platform/gui/Input.h" #include "cru/platform/gui/Window.h" #include "cru/platform/gui/win/Cursor.h" @@ -224,9 +223,8 @@ bool WinNativeWindow::ReleaseMouse() { } void WinNativeWindow::RequestRepaint() { - if constexpr (DebugFlags::paint) { - CRU_LOG_TAG_DEBUG("A repaint is requested."); - } + CRU_LOG_TAG_DEBUG("A repaint is requested."); + if (!hwnd_) return; if (!::InvalidateRect(hwnd_, nullptr, FALSE)) throw Win32Error(::GetLastError(), "Failed to invalidate window."); if (!::UpdateWindow(hwnd_)) @@ -533,9 +531,7 @@ void WinNativeWindow::OnDestroyInternal() { void WinNativeWindow::OnPaintInternal() { paint_event_.Raise(nullptr); ValidateRect(hwnd_, nullptr); - if constexpr (DebugFlags::paint) { - CRU_LOG_TAG_DEBUG("A repaint is finished."); - } + CRU_LOG_TAG_DEBUG("A repaint is finished."); } void WinNativeWindow::OnMoveInternal(const int new_left, const int new_top) { diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp index 380da911..c6be942a 100644 --- a/src/ui/components/Menu.cpp +++ b/src/ui/components/Menu.cpp @@ -78,14 +78,14 @@ void Menu::AddTextItemAt(std::string text, Index index, PopupMenu::PopupMenu(controls::Control* attached_control) : attached_control_(attached_control) { menu_.SetOnItemClick([this](Index) { popup_->GetNativeWindow()->Close(); }); - popup_ = controls::Window::CreatePopup(); + popup_.reset(controls::Window::CreatePopup()); popup_->SetAttachedControl(attached_control); popup_->InsertChildAt(menu_.GetRootControl(), 0); } -PopupMenu::~PopupMenu() { delete popup_; } +PopupMenu::~PopupMenu() {} -controls::Control* PopupMenu::GetRootControl() { return popup_; } +controls::Control* PopupMenu::GetRootControl() { return popup_.get(); } void PopupMenu::SetPosition(const Point& position) { auto window = popup_->GetNativeWindow(); diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index 02148b72..70a3b1f3 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -27,6 +27,7 @@ Control::~Control() { } RemoveFromParent(); + RemoveAllChild(); } std::string Control::GetDebugId() const { @@ -89,9 +90,8 @@ void Control::InsertChildAt(Control* control, Index index) { children_.insert(children_.cbegin() + index, control); control->parent_ = this; - - TraverseDescendents([this](Control* control) { control->host_ = host_; }, - false); + control->TraverseDescendents( + [this](Control* control) { control->host_ = host_; }, true); if (host_) { host_->NotifyControlParentChange(control, nullptr, this); } @@ -111,8 +111,8 @@ void Control::RemoveChildAt(Index index) { auto control = children_[index]; children_.erase(children_.cbegin() + index); control->parent_ = nullptr; - TraverseDescendents([this](Control* control) { control->host_ = nullptr; }, - false); + control->TraverseDescendents( + [this](Control* control) { control->host_ = nullptr; }, true); if (host_) { host_->NotifyControlParentChange(control, this, nullptr); } diff --git a/src/ui/controls/ControlHost.cpp b/src/ui/controls/ControlHost.cpp index 09639465..f83aa1a2 100644 --- a/src/ui/controls/ControlHost.cpp +++ b/src/ui/controls/ControlHost.cpp @@ -15,11 +15,14 @@ ControlHost::ControlHost(Control* root_control) mouse_hover_control_(nullptr), mouse_captured_control_(nullptr), layout_prefer_to_fill_window_(true) { - root_control->TraverseDescendents( + root_control_->TraverseDescendents( [this](Control* control) { control->host_ = this; }, true); } -ControlHost::~ControlHost() {} +ControlHost::~ControlHost() { + root_control_->TraverseDescendents( + [this](Control* control) { control->host_ = nullptr; }, true); +} platform::gui::INativeWindow* ControlHost::GetNativeWindow() { return native_window_.get(); @@ -121,11 +124,7 @@ ControlHost::CreateNativeWindow() { return std::unique_ptr<platform::gui::INativeWindow>(native_window); } -void ControlHost::InvalidatePaint() { - repaint_schedule_canceler_.Reset( - platform::gui::IUiApplication::GetInstance()->SetImmediate( - [this] { Repaint(); })); -} +void ControlHost::InvalidatePaint() { native_window_->RequestRepaint(); } void ControlHost::InvalidateLayout() { relayout_schedule_canceler_.Reset( @@ -244,7 +243,7 @@ void ControlHost::OnNativeDestroy(platform::gui::INativeWindow* window, void ControlHost::OnNativePaint(platform::gui::INativeWindow* window, std::nullptr_t) { CRU_UNUSED(window) - InvalidatePaint(); + Repaint(); } void ControlHost::OnNativeResize(platform::gui::INativeWindow* window, |
