[escher/table_view] Fix numberOfDisplayableRows/Columns

Did not take into account the margin so was too big sometimes
This commit is contained in:
Léa Saviot
2020-05-14 17:43:27 +02:00
committed by Émilie Feral
parent 515aa543d3
commit 44af4b1fde

View File

@@ -179,20 +179,14 @@ void TableView::ContentView::layoutSubviews(bool force) {
int TableView::ContentView::numberOfDisplayableRows() const {
int rowOffset = rowsScrollingOffset();
int displayedHeightWithOffset = m_dataSource->indexFromCumulatedHeight(m_tableView->bounds().height() + m_tableView->contentOffset().y());
return std::min(
m_dataSource->numberOfRows(),
displayedHeightWithOffset + 1
) - rowOffset;
int displayedHeightWithOffset = m_dataSource->indexFromCumulatedHeight(m_tableView->bounds().height() + (m_tableView->contentOffset().y() - m_tableView->topMargin()));
return std::min(m_dataSource->numberOfRows(), displayedHeightWithOffset + 1) - rowOffset;
}
int TableView::ContentView::numberOfDisplayableColumns() const {
int columnOffset = columnsScrollingOffset();
int displayedWidthWithOffset = m_dataSource->indexFromCumulatedWidth(m_tableView->bounds().width() + m_tableView->contentOffset().x());
return std::min(
m_dataSource->numberOfColumns(),
displayedWidthWithOffset + 1
) - columnOffset;
int displayedWidthWithOffset = m_dataSource->indexFromCumulatedWidth(m_tableView->bounds().width() + m_tableView->contentOffset().x() - m_tableView->leftMargin());
return std::min(m_dataSource->numberOfColumns(), displayedWidthWithOffset + 1) - columnOffset;
}
int TableView::ContentView::rowsScrollingOffset() const {