diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/platform/GraphBase.hpp | 6 | ||||
-rw-r--r-- | include/cru/ui/render/ScrollRenderObject.hpp | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/cru/platform/GraphBase.hpp b/include/cru/platform/GraphBase.hpp index 28dab1e6..e476e3cd 100644 --- a/include/cru/platform/GraphBase.hpp +++ b/include/cru/platform/GraphBase.hpp @@ -161,6 +161,12 @@ struct Rect final { constexpr Size GetSize() const { return Size(width, height); } + constexpr Rect Expand(const Thickness& thickness) const { + return Rect(left - thickness.left, top - thickness.top, + width + thickness.GetHorizontalTotal(), + height + thickness.GetVerticalTotal()); + } + constexpr Rect Shrink(const Thickness& thickness) const { return Rect(left + thickness.left, top + thickness.top, width - thickness.GetHorizontalTotal(), 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: |