mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[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:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user