aboutsummaryrefslogtreecommitdiff
path: root/src/ui/render/flex_layout_render_object.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-20 17:08:57 +0800
committercrupest <crupest@outlook.com>2019-03-20 17:08:57 +0800
commit1e3cad155a234d2e3e9b6aca650d4d1c4c9e8d4e (patch)
tree3fc01db4d6d36ed9f6e7795d2b87da96b4412f5f /src/ui/render/flex_layout_render_object.hpp
parent5dc738a57930271194bd86673eb86f149096a7b2 (diff)
downloadcru-1e3cad155a234d2e3e9b6aca650d4d1c4c9e8d4e.tar.gz
cru-1e3cad155a234d2e3e9b6aca650d4d1c4c9e8d4e.tar.bz2
cru-1e3cad155a234d2e3e9b6aca650d4d1c4c9e8d4e.zip
...
Diffstat (limited to 'src/ui/render/flex_layout_render_object.hpp')
-rw-r--r--src/ui/render/flex_layout_render_object.hpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/ui/render/flex_layout_render_object.hpp b/src/ui/render/flex_layout_render_object.hpp
new file mode 100644
index 00000000..7172f0c0
--- /dev/null
+++ b/src/ui/render/flex_layout_render_object.hpp
@@ -0,0 +1,55 @@
+#pragma once
+#include "pre.hpp"
+
+#include <optional>
+
+#include "render_object.hpp"
+
+namespace cru::ui::render {
+enum class FlexDirection {
+ Horizontal,
+ HorizontalReverse,
+ Vertical,
+ VertivalReverse
+};
+
+enum class Alignment { Start, End, Center };
+
+struct FlexChildLayoutData {
+ std::optional<float> flex_basis;
+ float flex_grow = 0;
+ float flex_shrink = 0;
+ Alignment alignment = Alignment::Center;
+};
+
+class FlexLayoutRenderObject : public RenderObject {
+ public:
+ FlexLayoutRenderObject() = default;
+ FlexLayoutRenderObject(const FlexLayoutRenderObject& other) = delete;
+ FlexLayoutRenderObject& operator=(const FlexLayoutRenderObject& other) =
+ delete;
+ FlexLayoutRenderObject(FlexLayoutRenderObject&& other) = delete;
+ FlexLayoutRenderObject& operator=(FlexLayoutRenderObject&& other) = delete;
+ ~FlexLayoutRenderObject() override = default;
+
+ FlexDirection GetFlexDirection() const { return direction_; }
+ void SetFlexDirection(FlexDirection direction) { direction_ = direction; }
+
+ FlexChildLayoutData* GetChildLayoutData(int position);
+
+ void Draw(ID2D1RenderTarget* render_target) override;
+
+ RenderObject* HitTest(const Point& point) override;
+
+ protected:
+ void OnAddChild(RenderObject* new_child, int position) override;
+ void OnRemoveChild(RenderObject* removed_child, int position) override;
+
+ Size OnMeasureContent(const Size& available_size) override;
+ void OnLayoutContent(const Rect& content_rect) override;
+
+ private:
+ FlexDirection direction_ = FlexDirection::Horizontal;
+ std::vector<FlexChildLayoutData> child_layout_data_{};
+};
+} // namespace cru::ui::render