diff options
author | crupest <crupest@outlook.com> | 2020-10-29 00:01:26 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-29 00:01:26 +0800 |
commit | 52594324b302f6e9da10ac01fe803196371bb2d9 (patch) | |
tree | 38dd36e0bf934b283dd80f808531a2ee862b174b /src/ui/render | |
parent | df4df679e157f974773dad7776b204e9d4f3009e (diff) | |
download | cru-52594324b302f6e9da10ac01fe803196371bb2d9.tar.gz cru-52594324b302f6e9da10ac01fe803196371bb2d9.tar.bz2 cru-52594324b302f6e9da10ac01fe803196371bb2d9.zip |
...
Diffstat (limited to 'src/ui/render')
-rw-r--r-- | src/ui/render/RenderObject.cpp | 25 | ||||
-rw-r--r-- | src/ui/render/WindowRenderObject.cpp | 44 |
2 files changed, 12 insertions, 57 deletions
diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index 5266daaf..fd0c7712 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -24,7 +24,7 @@ void RenderObject::AddChild(RenderObject* render_object, const Index position) { children_.insert(children_.cbegin() + position, render_object); render_object->SetParent(this); - render_object->SetRenderHostRecursive(GetWindowHost()); + render_object->SetWindowHostRecursive(GetWindowHost()); OnAddChild(render_object, position); } @@ -37,7 +37,7 @@ void RenderObject::RemoveChild(const Index position) { const auto removed_child = *i; children_.erase(i); removed_child->SetParent(nullptr); - removed_child->SetRenderHostRecursive(nullptr); + removed_child->SetWindowHostRecursive(nullptr); OnRemoveChild(removed_child, position); } @@ -269,11 +269,11 @@ void RenderObject::SetParent(RenderObject* new_parent) { } void RenderObject::InvalidateLayout() { - if (ui_host_ != nullptr) ui_host_->InvalidateLayout(); + if (window_host_ != nullptr) window_host_->InvalidateLayout(); } void RenderObject::InvalidatePaint() { - if (ui_host_ != nullptr) ui_host_->InvalidatePaint(); + if (window_host_ != nullptr) window_host_->InvalidatePaint(); } constexpr std::u16string_view kUnamedName(u"UNNAMED"); @@ -297,17 +297,16 @@ std::u16string RenderObject::GetDebugPathInTree() const { return result; } -void RenderObject::NotifyAfterLayoutRecursive(RenderObject* render_object) { - render_object->OnAfterLayout(); - for (const auto o : render_object->GetChildren()) { - NotifyAfterLayoutRecursive(o); +void RenderObject::SetWindowHostRecursive(WindowHost* host) { + if (window_host_ != nullptr) { + detach_from_host_event_.Raise(nullptr); + } + window_host_ = host; + if (host != nullptr) { + attach_to_host_event_.Raise(nullptr); } -} - -void RenderObject::SetRenderHostRecursive(WindowHost* host) { - ui_host_ = host; for (const auto child : GetChildren()) { - child->SetRenderHostRecursive(host); + child->SetWindowHostRecursive(host); } } } // namespace cru::ui::render diff --git a/src/ui/render/WindowRenderObject.cpp b/src/ui/render/WindowRenderObject.cpp deleted file mode 100644 index 23cca12e..00000000 --- a/src/ui/render/WindowRenderObject.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "cru/ui/render/WindowRenderObject.hpp" - -#include "../Helper.hpp" -#include "cru/platform/graph/util/Painter.hpp" -#include "cru/ui/WindowHost.hpp" - -namespace cru::ui::render { -WindowRenderObject::WindowRenderObject(WindowHost* host) { - SetChildMode(ChildMode::Single); - ui_host_ = host; - after_layout_event_guard_.Reset(host->AfterLayoutEvent()->AddHandler( - [this](auto) { NotifyAfterLayoutRecursive(this); })); -} - -RenderObject* WindowRenderObject::HitTest(const Point& point) { - if (const auto child = GetChild()) { - auto offset = child->GetOffset(); - Point p{point.x - offset.x, point.y - offset.y}; - const auto result = child->HitTest(p); - if (result != nullptr) { - return result; - } - } - return Rect{Point{}, GetSize()}.IsPointInside(point) ? this : nullptr; -} - -std::u16string_view WindowRenderObject::GetName() const { - return u"WindowRenderObject"; -} - -Size WindowRenderObject::OnMeasureContent(const MeasureRequirement& requirement, - const MeasureSize& preferred_size) { - if (const auto child = GetChild()) { - child->Measure(requirement, preferred_size); - return child->GetSize(); - } else { - return Size{}; - } -} - -void WindowRenderObject::OnLayoutContent(const Rect& content_rect) { - if (const auto child = GetChild()) child->Layout(content_rect.GetLeftTop()); -} -} // namespace cru::ui::render |