| 469 | } |
| 470 | |
| 471 | void TableView::scrollViewDidScroll(ScrollView* /*view*/) |
| 472 | { |
| 473 | if (!_dataSource) |
| 474 | return; |
| 475 | ssize_t countOfItems = _dataSource->numberOfCellsInTableView(this); |
| 476 | if (0 == countOfItems) |
| 477 | { |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | if (_isUsedCellsDirty) |
| 482 | { |
| 483 | _isUsedCellsDirty = false; |
| 484 | std::sort(_cellsUsed.begin(), _cellsUsed.end(), |
| 485 | [](TableViewCell* a, TableViewCell* b) -> bool { return a->getIdx() < b->getIdx(); }); |
| 486 | } |
| 487 | |
| 488 | ssize_t startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0; |
| 489 | Vec2 offset = this->getContentOffset() * -1; |
| 490 | maxIdx = MAX(countOfItems - 1, 0); |
| 491 | |
| 492 | if (_vordering == VerticalFillOrder::TOP_DOWN) |
| 493 | { |
| 494 | offset.y = offset.y + _viewSize.height / this->getContainer()->getScaleY(); |
| 495 | } |
| 496 | startIdx = this->_indexFromOffset(offset); |
| 497 | if (startIdx == AX_INVALID_INDEX) |
| 498 | { |
| 499 | startIdx = countOfItems - 1; |
| 500 | } |
| 501 | |
| 502 | if (_vordering == VerticalFillOrder::TOP_DOWN) |
| 503 | { |
| 504 | offset.y -= _viewSize.height / this->getContainer()->getScaleY(); |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | offset.y += _viewSize.height / this->getContainer()->getScaleY(); |
| 509 | } |
| 510 | offset.x += _viewSize.width / this->getContainer()->getScaleX(); |
| 511 | |
| 512 | endIdx = this->_indexFromOffset(offset); |
| 513 | if (endIdx == AX_INVALID_INDEX) |
| 514 | { |
| 515 | endIdx = countOfItems - 1; |
| 516 | } |
| 517 | |
| 518 | #if 0 // For Testing. |
| 519 | Object* pObj; |
| 520 | int i = 0; |
| 521 | CCARRAY_FOREACH(_cellsUsed, pObj) |
| 522 | { |
| 523 | TableViewCell* pCell = static_cast<TableViewCell*>(pObj); |
| 524 | AXLOGD("cells Used index {}, value = {}", i, pCell->getIdx()); |
| 525 | i++; |
| 526 | } |
| 527 | AXLOGD("---------------------------------------"); |
| 528 | i = 0; |
no test coverage detected