aboutsummaryrefslogtreecommitdiff
path: root/src/ui/render/WindowRenderObject.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-05-24 01:40:02 +0800
committercrupest <crupest@outlook.com>2020-05-24 01:40:02 +0800
commitd86a71f79afe0e4dac768f61d6bff690567aca5b (patch)
tree4957e9a64c77680deb07201fbd879bf036616dae /src/ui/render/WindowRenderObject.cpp
parentf3a8fd608a9776ef0a5f547da918a32cf6074060 (diff)
downloadcru-d86a71f79afe0e4dac768f61d6bff690567aca5b.tar.gz
cru-d86a71f79afe0e4dac768f61d6bff690567aca5b.tar.bz2
cru-d86a71f79afe0e4dac768f61d6bff690567aca5b.zip
...
Diffstat (limited to 'src/ui/render/WindowRenderObject.cpp')
-rw-r--r--src/ui/render/WindowRenderObject.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ui/render/WindowRenderObject.cpp b/src/ui/render/WindowRenderObject.cpp
new file mode 100644
index 00000000..cd1f806f
--- /dev/null
+++ b/src/ui/render/WindowRenderObject.cpp
@@ -0,0 +1,45 @@
+#include "cru/ui/render/WindowRenderObject.hpp"
+
+#include "../Helper.hpp"
+#include "cru/platform/graph/util/Painter.hpp"
+#include "cru/ui/UiHost.hpp"
+
+namespace cru::ui::render {
+WindowRenderObject::WindowRenderObject(UiHost* host) {
+ SetChildMode(ChildMode::Single);
+ ui_host_ = host;
+ after_layout_event_guard_.Reset(host->AfterLayoutEvent()->AddHandler(
+ [this](auto) { NotifyAfterLayoutRecursive(this); }));
+}
+
+void WindowRenderObject::Draw(platform::graph::IPainter* painter) {
+ painter->Clear(colors::white);
+ if (const auto child = GetChild()) {
+ auto offset = child->GetOffset();
+ platform::graph::util::WithTransform(
+ painter, platform::Matrix::Translation(offset.x, offset.y),
+ [child](platform::graph::IPainter* p) { child->Draw(p); });
+ }
+}
+
+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;
+}
+
+Size WindowRenderObject::OnMeasureContent(const Size& available_size) {
+ if (const auto child = GetChild()) child->Measure(available_size);
+ return available_size;
+}
+
+void WindowRenderObject::OnLayoutContent(const Rect& content_rect) {
+ if (const auto child = GetChild()) child->Layout(content_rect);
+}
+} // namespace cru::ui::render