aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/render/ScrollRenderObject.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-25 23:57:16 +0800
committercrupest <crupest@outlook.com>2020-07-25 23:57:16 +0800
commit23bf673f9582d7bc99eb6440be1df0cf5c43b725 (patch)
treed4715f526d14d2f3367358e5ba7d987b92df7fd7 /include/cru/ui/render/ScrollRenderObject.hpp
parent83736f1208a613d2457147c2df3f493228bab3cb (diff)
downloadcru-23bf673f9582d7bc99eb6440be1df0cf5c43b725.tar.gz
cru-23bf673f9582d7bc99eb6440be1df0cf5c43b725.tar.bz2
cru-23bf673f9582d7bc99eb6440be1df0cf5c43b725.zip
Implement ScrollRenderObject::ScrollToContain .
Diffstat (limited to 'include/cru/ui/render/ScrollRenderObject.hpp')
-rw-r--r--include/cru/ui/render/ScrollRenderObject.hpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/cru/ui/render/ScrollRenderObject.hpp b/include/cru/ui/render/ScrollRenderObject.hpp
index 45fa3993..9b0cbf9a 100644
--- a/include/cru/ui/render/ScrollRenderObject.hpp
+++ b/include/cru/ui/render/ScrollRenderObject.hpp
@@ -3,6 +3,8 @@
#include "cru/platform/graph/util/Painter.hpp"
+#include <optional>
+
namespace cru::ui::render {
// Measure logic:
// Measure child with unspecified min and max size.
@@ -26,9 +28,19 @@ class ScrollRenderObject : public RenderObject {
// Return the coerced scroll offset.
Point GetScrollOffset();
void SetScrollOffset(const Point& offset);
+ void SetScrollOffset(std::optional<float> x, std::optional<float> y);
Point GetRawScrollOffset() const { return scroll_offset_; }
+ // Return the viewable area rect.
+ // Lefttop is scroll offset. Size is content size.
+ // If size exceeds view area, left and top is more important when calculate
+ // new scroll offset.
+ Rect GetViewRect() {
+ return Rect{GetScrollOffset(), GetContentRect().GetSize()};
+ }
+
// Rect lefttop relative to content rect.
+ // Param margin is just for convenience and it will just add to the rect.
void ScrollToContain(const Rect& rect, const Thickness& margin = Thickness{});
protected: