| 214 | } |
| 215 | |
| 216 | void ScrollView::setContentOffset(Vec2 offset, bool animated /* = false*/) |
| 217 | { |
| 218 | if (animated) |
| 219 | { // animate scrolling |
| 220 | this->setContentOffsetInDuration(offset, BOUNCE_DURATION); |
| 221 | } |
| 222 | else |
| 223 | { // set the container position directly |
| 224 | if (!_bounceable) |
| 225 | { |
| 226 | const Vec2 minOffset = this->minContainerOffset(); |
| 227 | const Vec2 maxOffset = this->maxContainerOffset(); |
| 228 | |
| 229 | offset.x = MAX(minOffset.x, MIN(maxOffset.x, offset.x)); |
| 230 | offset.y = MAX(minOffset.y, MIN(maxOffset.y, offset.y)); |
| 231 | } |
| 232 | |
| 233 | _container->setPosition(offset); |
| 234 | |
| 235 | if (_delegate != nullptr) |
| 236 | { |
| 237 | _delegate->scrollViewDidScroll(this); |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | void ScrollView::setContentOffsetInDuration(Vec2 offset, float dt) |
| 243 | { |