aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/render/layout_render_object.hpp
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 /include/cru/ui/render/layout_render_object.hpp
parentf3a8fd608a9776ef0a5f547da918a32cf6074060 (diff)
downloadcru-d86a71f79afe0e4dac768f61d6bff690567aca5b.tar.gz
cru-d86a71f79afe0e4dac768f61d6bff690567aca5b.tar.bz2
cru-d86a71f79afe0e4dac768f61d6bff690567aca5b.zip
...
Diffstat (limited to 'include/cru/ui/render/layout_render_object.hpp')
-rw-r--r--include/cru/ui/render/layout_render_object.hpp88
1 files changed, 0 insertions, 88 deletions
diff --git a/include/cru/ui/render/layout_render_object.hpp b/include/cru/ui/render/layout_render_object.hpp
deleted file mode 100644
index 5c4c9c5c..00000000
--- a/include/cru/ui/render/layout_render_object.hpp
+++ /dev/null
@@ -1,88 +0,0 @@
-#pragma once
-#include "render_object.hpp"
-
-#include "cru/platform/graph/util/painter.hpp"
-
-namespace cru::ui::render {
-template <typename TChildLayoutData>
-class LayoutRenderObject : public RenderObject {
- public:
- using ChildLayoutData = TChildLayoutData;
-
- protected:
- LayoutRenderObject() : RenderObject(ChildMode::Multiple) {}
-
- public:
- CRU_DELETE_COPY(LayoutRenderObject)
- CRU_DELETE_MOVE(LayoutRenderObject)
-
- ~LayoutRenderObject() override = default;
-
- ChildLayoutData* GetChildLayoutData(Index position) {
- Expects(position >= 0 &&
- position < static_cast<Index>(child_layout_data_.size()));
- return &child_layout_data_[position];
- }
-
- void Draw(platform::graph::IPainter* painter) override;
-
- RenderObject* HitTest(const Point& point) override;
-
- protected:
- void OnAddChild(RenderObject* new_child, Index position) override;
- void OnRemoveChild(RenderObject* removed_child, Index position) override;
-
- private:
- std::vector<ChildLayoutData> child_layout_data_{};
-};
-
-template <typename TChildLayoutData>
-void LayoutRenderObject<TChildLayoutData>::Draw(
- platform::graph::IPainter* painter) {
- for (const auto child : GetChildren()) {
- auto offset = child->GetOffset();
- platform::graph::util::WithTransform(
- painter, platform::Matrix::Translation(offset.x, offset.y),
- [child](auto p) { child->Draw(p); });
- }
-}
-
-template <typename TChildLayoutData>
-RenderObject* LayoutRenderObject<TChildLayoutData>::HitTest(
- const Point& point) {
- const auto& children = GetChildren();
- for (auto i = children.crbegin(); i != children.crend(); ++i) {
- auto offset = (*i)->GetOffset();
- Point p{point.x - offset.x, point.y - offset.y};
- const auto result = (*i)->HitTest(p);
- if (result != nullptr) {
- return result;
- }
- }
-
- const auto margin = GetMargin();
- const auto size = GetSize();
- return Rect{margin.left, margin.top,
- std::max(size.width - margin.GetHorizontalTotal(), 0.0f),
- std::max(size.height - margin.GetVerticalTotal(), 0.0f)}
- .IsPointInside(point)
- ? this
- : nullptr;
-} // namespace cru::ui::render
-
-template <typename TChildLayoutData>
-void LayoutRenderObject<TChildLayoutData>::OnAddChild(RenderObject* new_child,
- const Index position) {
- CRU_UNUSED(new_child)
-
- child_layout_data_.emplace(child_layout_data_.cbegin() + position);
-}
-
-template <typename TChildLayoutData>
-void LayoutRenderObject<TChildLayoutData>::OnRemoveChild(
- RenderObject* removed_child, const Index position) {
- CRU_UNUSED(removed_child)
-
- child_layout_data_.erase(child_layout_data_.cbegin() + position);
-}
-} // namespace cru::ui::render