From 44af4b1fdef79456ccc0611626201bd36f4bc73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 14 May 2020 17:43:27 +0200 Subject: [PATCH] [escher/table_view] Fix numberOfDisplayableRows/Columns Did not take into account the margin so was too big sometimes --- escher/src/table_view.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp index 28d3dfd74..aacbd8d42 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/table_view.cpp @@ -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 {