From b5145b9596807b62514de6e5c467f76342f47724 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 3 May 2022 14:24:14 +0300 Subject: [PATCH] Support on_scroll event in ui::scroller --- libs/ui/include/psemek/ui/scroller.hpp | 2 ++ libs/ui/source/scroller.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/libs/ui/include/psemek/ui/scroller.hpp b/libs/ui/include/psemek/ui/scroller.hpp index c764c799..ce62ecca 100644 --- a/libs/ui/include/psemek/ui/scroller.hpp +++ b/libs/ui/include/psemek/ui/scroller.hpp @@ -40,6 +40,8 @@ namespace psemek::ui protected: + virtual void on_scroll(geom::vector const & delta); + virtual float width() const; virtual geom::box visible_range() const; diff --git a/libs/ui/source/scroller.cpp b/libs/ui/source/scroller.cpp index 74c2cddf..c9700bcb 100644 --- a/libs/ui/source/scroller.cpp +++ b/libs/ui/source/scroller.cpp @@ -53,8 +53,10 @@ namespace psemek::ui float c = geom::unlerp(box[0], e.position[0]); c = geom::clamp(c, {0.f, 1.f}); + auto old = shift_tgt_; shift_tgt_[0] = shape_.box[0].length() / 2.f - c * sc[0].min; clamp_shift(); + on_scroll(shift_tgt_ - old); } break; } @@ -85,8 +87,10 @@ namespace psemek::ui float c = geom::unlerp(box[1], e.position[1]); c = geom::clamp(c, {0.f, 1.f}); + auto old = shift_tgt_; shift_tgt_[1] = shape_.box[1].length() / 2.f - c * sc[1].min; clamp_shift(); + on_scroll(shift_tgt_ - old); } break; } @@ -182,8 +186,10 @@ namespace psemek::ui delta[0] = e.delta; } + auto old = shift_tgt_; shift_tgt_ += delta * 50.f; clamp_shift(); + on_scroll(shift_tgt_ - old); post_reshape(); return true; } @@ -291,6 +297,9 @@ namespace psemek::ui p.end_stencil(); } + void scroller::on_scroll(geom::vector const &) + {} + float scroller::width() const { return 0;