diff --git a/libs/ui/include/psemek/ui/scroller.hpp b/libs/ui/include/psemek/ui/scroller.hpp index 1aaf6df4..32bb5b87 100644 --- a/libs/ui/include/psemek/ui/scroller.hpp +++ b/libs/ui/include/psemek/ui/scroller.hpp @@ -60,6 +60,9 @@ namespace psemek::ui bool horizontal_ = false; bool vertical_ = true; + bool horizontal_stick_ = false; + bool vertical_stick_ = false; + geom::vector shift_{0.f, 0.f}; geom::vector shift_tgt_{0.f, 0.f}; diff --git a/libs/ui/source/scroller.cpp b/libs/ui/source/scroller.cpp index daf99cdc..635afb73 100644 --- a/libs/ui/source/scroller.cpp +++ b/libs/ui/source/scroller.cpp @@ -218,12 +218,26 @@ namespace psemek::ui if (horizontal_scroll()) { + horizontal_stick_ |= child_bbox[0].length() > child_constraints[0].min; + + if (horizontal_stick_) + { + shift_tgt_[0] = std::min(child_bbox[0].length() - child_constraints[0].min, 0.f); + shift_[0] = shift_tgt_[0]; + } child_bbox[0].min += shift_[0]; child_bbox[0].max = child_bbox[0].min + child_constraints[0].min; } if (vertical_scroll()) { + vertical_stick_ |= child_bbox[1].length() > child_constraints[1].min; + + if (vertical_stick_) + { + shift_tgt_[1] = std::min(child_bbox[1].length() - child_constraints[1].min, 0.f); + shift_[1] = shift_tgt_[1]; + } child_bbox[1].min += shift_[1]; child_bbox[1].max = child_bbox[1].min + child_constraints[1].min; } @@ -343,10 +357,16 @@ namespace psemek::ui auto c = child_->size_constraints(); - shift_tgt_[0] = std::max(shift_tgt_[0], shape_.box[0].length() - c[0].min); + geom::vector min; + min[0] = shape_.box[0].length() - c[0].min; + min[1] = shape_.box[1].length() - c[1].min; + + shift_tgt_[0] = std::max(shift_tgt_[0], min[0]); + horizontal_stick_ = (shift_tgt_[0] == min[0]) || (min[0] > 0.f); shift_tgt_[0] = std::min(shift_tgt_[0], 0.f); - shift_tgt_[1] = std::max(shift_tgt_[1], shape_.box[1].length() - c[1].min); + shift_tgt_[1] = std::max(shift_tgt_[1], min[1]); + vertical_stick_ = (shift_tgt_[1] == min[1]) || (min[1] > 0.f); shift_tgt_[1] = std::min(shift_tgt_[1], 0.f); }