[apps/banner_view] Fix minimalSizeForOptimalDisplay

Should not use m_frame as it may not be set properly. By default, a
banner view wants to take the whole screen width
This fixes the following scenario :
Draw the polar curve r=12. When navigating from the tab to the graph,
the curve was visibly redrawn because the banner view height was not
computed properly.
This commit is contained in:
Léa Saviot
2019-09-30 15:09:03 +02:00
parent 491a93d8f1
commit 0055a59c75
3 changed files with 10 additions and 4 deletions

View File

@@ -17,7 +17,11 @@ void BannerView::drawRect(KDContext * ctx, KDRect rect) const {
}
KDSize BannerView::minimalSizeForOptimalDisplay() const {
return KDSize(0, HeightGivenNumberOfLines(numberOfLines()));
return KDSize(Ion::Display::Width, minimalHeightForOptimalDisplayGivenWidth(Ion::Display::Width));
}
KDCoordinate BannerView::minimalHeightForOptimalDisplayGivenWidth(KDCoordinate width) const {
return HeightGivenNumberOfLines(numberOfLinesGivenWidth(width));
}
void BannerView::layoutSubviews() {
@@ -61,9 +65,9 @@ void BannerView::layoutSubviews() {
}
}
int BannerView::numberOfLines() const {
int BannerView::numberOfLinesGivenWidth(KDCoordinate width) const {
int lineNumber = 1;
const KDCoordinate lineWidth = m_frame.width();
const KDCoordinate lineWidth = width;
KDCoordinate remainingWidth = lineWidth;
for (int i = 0; i < numberOfSubviews(); i++) {
KDCoordinate subviewWidth = const_cast<Shared::BannerView *>(this)->subviewAtIndex(i)->minimalSizeForOptimalDisplay().width();

View File

@@ -10,6 +10,7 @@ public:
static KDCoordinate HeightGivenNumberOfLines(int linesCount);
void drawRect(KDContext * ctx, KDRect rect) const override;
KDSize minimalSizeForOptimalDisplay() const override;
KDCoordinate minimalHeightForOptimalDisplayGivenWidth(KDCoordinate width) const;
void reload() { layoutSubviews(); }
static constexpr const KDFont * Font() { return KDFont::SmallFont; }
static constexpr KDColor TextColor() { return KDColorBlack; }
@@ -19,7 +20,7 @@ private:
int numberOfSubviews() const override = 0;
View * subviewAtIndex(int index) override = 0;
void layoutSubviews() override;
int numberOfLines() const;
int numberOfLinesGivenWidth(KDCoordinate width) const;
};
}

View File

@@ -752,6 +752,7 @@ KDRect CurveView::cursorFrame() {
KDRect CurveView::bannerFrame() {
KDRect bannerFrame = KDRectZero;
if (bannerIsVisible()) {
assert(bounds().width() == Ion::Display::Width); // Else the bannerHeight will not be properly computed
KDCoordinate bannerHeight = m_bannerView->minimalSizeForOptimalDisplay().height();
bannerFrame = KDRect(0, bounds().height()- bannerHeight, bounds().width(), bannerHeight);
}