diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-19 02:59:30 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-19 02:59:30 +0800 |
| commit | 2eb34dfc3dd3ca718da6ebf049886b4ae140b332 (patch) | |
| tree | c43dbca6e6898fd474ca9b976b4bf21b3419e512 /src/ui/controls/ControlHost.cpp | |
| parent | df2dadbd0f0ace6e02281c84218537ec2ce5c47f (diff) | |
| download | cru-2eb34dfc3dd3ca718da6ebf049886b4ae140b332.tar.gz cru-2eb34dfc3dd3ca718da6ebf049886b4ae140b332.tar.bz2 cru-2eb34dfc3dd3ca718da6ebf049886b4ae140b332.zip | |
Remove all children when control destroyed.
Diffstat (limited to 'src/ui/controls/ControlHost.cpp')
| -rw-r--r-- | src/ui/controls/ControlHost.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
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, |
