| 286 | } |
| 287 | |
| 288 | void Item::setPosition(int x, int y, int outerWidth, int maxVisiblePadding) { |
| 289 | if (_x >= 0 && _y >= 0 && (_x != x || _y != y)) { |
| 290 | // Make an animation if it is not the first setPosition(). |
| 291 | auto found = false; |
| 292 | auto leftHidden = -_width - maxVisiblePadding; |
| 293 | auto rightHidden = outerWidth + maxVisiblePadding; |
| 294 | for (auto i = _copies.begin(), e = _copies.end(); i != e;) { |
| 295 | if (i->x.animating()) { |
| 296 | if (i->y == y) { |
| 297 | i->x.start(_updateCallback, i->toX, x, _st.duration); |
| 298 | found = true; |
| 299 | } else { |
| 300 | i->x.start( |
| 301 | _updateCallback, |
| 302 | i->fromX, |
| 303 | (i->toX > i->fromX) ? rightHidden : leftHidden, |
| 304 | _st.duration); |
| 305 | } |
| 306 | ++i; |
| 307 | } else { |
| 308 | i = _copies.erase(i); |
| 309 | e = _copies.end(); |
| 310 | } |
| 311 | } |
| 312 | if (_copies.empty()) { |
| 313 | if (_y == y) { |
| 314 | auto copy = SlideAnimation( |
| 315 | _updateCallback, |
| 316 | _x, |
| 317 | x, |
| 318 | _y, |
| 319 | _st.duration); |
| 320 | _copies.push_back(std::move(copy)); |
| 321 | } else { |
| 322 | auto copyHiding = SlideAnimation( |
| 323 | _updateCallback, |
| 324 | _x, |
| 325 | (y > _y) ? rightHidden : leftHidden, |
| 326 | _y, |
| 327 | _st.duration); |
| 328 | _copies.push_back(std::move(copyHiding)); |
| 329 | auto copyShowing = SlideAnimation( |
| 330 | _updateCallback, |
| 331 | (y > _y) ? leftHidden : rightHidden, |
| 332 | x, |
| 333 | y, |
| 334 | _st.duration); |
| 335 | _copies.push_back(std::move(copyShowing)); |
| 336 | } |
| 337 | } else if (!found) { |
| 338 | auto copy = SlideAnimation( |
| 339 | _updateCallback, |
| 340 | (y > _y) ? leftHidden : rightHidden, |
| 341 | x, |
| 342 | y, |
| 343 | _st.duration); |
| 344 | _copies.push_back(std::move(copy)); |
| 345 | } |
no test coverage detected