[escher/scroll_view] Fix virtuality issues of layoutSubviews

Method contentSize() made virtual and overridden by ScrollableView
so that ScrollableView and TableView do not need to setSize themselves
and that setSize/setFrame is not called twice over m_contentView.
This commit is contained in:
Ruben Dashyan
2019-01-31 15:20:05 +01:00
committed by EmilieNumworks
parent c439d6f376
commit cda88b3c3b
6 changed files with 22 additions and 29 deletions

View File

@@ -38,12 +38,20 @@ const char * TableView::className() const {
#endif
void TableView::layoutSubviews() {
// We only have to layout our contentView.
// We will size it here, and ScrollView::layoutSubviews will position it.
m_contentView.resizeToFitContent();
ScrollView::layoutSubviews();
m_contentView.layoutSubviews();
/* FIXME:
* On the one hand, ScrollView::layoutSubviews()
* calls setFrame(...) over m_contentView,
* which typically calls layoutSubviews() over m_contentView.
* However, if the frame happens to be unchanged,
* setFrame(...) does not call layoutSubviews.
* On the other hand, calling only m_contentView.layoutSubviews()
* does not relayout ScrollView when the offset
* or the content's size changes.
* For those reasons, we call both of them explicitly.
* Finally, this solution is not optimal at all since
* layoutSubviews is called twice over m_contentView. */
}
void TableView::reloadCellAtLocation(int i, int j) {
@@ -75,13 +83,6 @@ KDCoordinate TableView::ContentView::columnWidth(int i) const {
return columnWidth;
}
void TableView::ContentView::resizeToFitContent() {
if (!(m_tableView->bounds() == KDRectZero)) {
layoutSubviews();
setSize(KDSize(width(), height()));
}
}
KDCoordinate TableView::ContentView::height() const {
return m_dataSource->cumulatedHeightFromIndex(m_dataSource->numberOfRows())+m_verticalCellOverlap;
}