mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 16:20:49 +01:00
[apps] replace BannerView::textViewAtIndex by subviewAtIndex
This commit is contained in:
committed by
Émilie Feral
parent
513a4cf852
commit
236b752f4f
@@ -1,4 +1,5 @@
|
||||
#include "banner_view.h"
|
||||
#include <assert.h>
|
||||
#include <apps/i18n.h>
|
||||
|
||||
namespace Graph {
|
||||
@@ -14,9 +15,10 @@ BannerView::BannerView() :
|
||||
{
|
||||
}
|
||||
|
||||
TextView * BannerView::textViewAtIndex(int i) const {
|
||||
const TextView * textViews[6] = {&m_abscissaView, &m_functionView, &m_derivativeView, &m_tangentEquationView, &m_aView, &m_bView};
|
||||
return (TextView *)textViews[i];
|
||||
View * BannerView::subviewAtIndex(int index) {
|
||||
assert(0 <= index && index < numberOfSubviews());
|
||||
View * subviews[] = {&m_abscissaView, &m_functionView, &m_derivativeView, &m_tangentEquationView, &m_aView, &m_bView};
|
||||
return subviews[index];
|
||||
}
|
||||
|
||||
MessageTextView * BannerView::messageTextViewAtIndex(int i) const {
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
void setNumberOfSubviews(int numberOfSubviews) { m_numberOfSubviews = numberOfSubviews; }
|
||||
private:
|
||||
int numberOfSubviews() const override { return m_numberOfSubviews; }
|
||||
TextView * textViewAtIndex(int i) const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
MessageTextView * messageTextViewAtIndex(int i) const override;
|
||||
BufferTextView m_abscissaView;
|
||||
BufferTextView m_functionView;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "banner_view.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Regression {
|
||||
|
||||
@@ -18,9 +19,10 @@ BannerView::BannerView() :
|
||||
{
|
||||
}
|
||||
|
||||
TextView * BannerView::textViewAtIndex(int i) const {
|
||||
const TextView * textViews[k_numberOfSubviews] = {&m_dotNameView, &m_xView, &m_yView, &m_regressionTypeView, &m_subText1, &m_subText2, &m_subText3, &m_subText4, &m_subText5};
|
||||
return (TextView *)textViews[i];
|
||||
View * BannerView::subviewAtIndex(int index) {
|
||||
assert(0 <= index && index < numberOfSubviews());
|
||||
View * subviews[] = {&m_dotNameView, &m_xView, &m_yView, &m_regressionTypeView, &m_subText1, &m_subText2, &m_subText3, &m_subText4, &m_subText5};
|
||||
return subviews[index];
|
||||
}
|
||||
|
||||
MessageTextView * BannerView::messageTextViewAtIndex(int i) const {
|
||||
|
||||
@@ -17,7 +17,7 @@ private:
|
||||
static constexpr KDColor k_backgroundColor = Palette::GreyMiddle;
|
||||
static constexpr int k_numberOfSubviews = 9;
|
||||
int numberOfSubviews() const override { return k_numberOfSubviews; }
|
||||
TextView * textViewAtIndex(int i) const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
MessageTextView * messageTextViewAtIndex(int i) const override;
|
||||
BufferTextView m_dotNameView;
|
||||
BufferTextView m_xView;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "banner_view.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Sequence {
|
||||
|
||||
@@ -8,9 +9,10 @@ BannerView::BannerView() :
|
||||
{
|
||||
}
|
||||
|
||||
TextView * BannerView::textViewAtIndex(int i) const {
|
||||
const TextView * views[2] = {&m_abscissaView, &m_sequenceView};
|
||||
return (TextView *)views[i];
|
||||
View * BannerView::subviewAtIndex(int index) {
|
||||
assert(0 <= index && index < numberOfSubviews());
|
||||
View * subviews[] = {&m_abscissaView, &m_sequenceView};
|
||||
return subviews[index];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
private:
|
||||
static constexpr int k_numberOfSubviews = 2;
|
||||
int numberOfSubviews() const override { return k_numberOfSubviews; }
|
||||
TextView * textViewAtIndex(int i) const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
BufferTextView m_abscissaView;
|
||||
BufferTextView m_sequenceView;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "banner_view.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
@@ -14,7 +13,7 @@ void BannerView::setLegendAtIndex(char * text, int index) {
|
||||
* So changing a legend implies two things
|
||||
* - First, we need to update the textView to ensure it has the new content
|
||||
* - Second, we need to relayout *all* of our subviews. */
|
||||
TextView * textView = textViewAtIndex(index);
|
||||
TextView * textView = static_cast<TextView *>(subviewAtIndex(index));
|
||||
textView->setText(text);
|
||||
layoutSubviews();
|
||||
}
|
||||
@@ -37,15 +36,15 @@ void BannerView::layoutSubviews() {
|
||||
* line and iterate the process. */
|
||||
KDCoordinate totalWidth = bounds().width();
|
||||
KDCoordinate lineWidth = 0;
|
||||
TextView * textViewPreviousLine = textViewAtIndex(0);
|
||||
View * textViewPreviousLine = subviewAtIndex(0);
|
||||
int indexOfFirstViewOfCurrentLine = 0;
|
||||
KDCoordinate y = 0;
|
||||
/* We do a last iteration of the loop to layout the last line. */
|
||||
for (int i = 0; i <= numberOfSubviews(); i++) {
|
||||
TextView * textView = nullptr;
|
||||
View * textView = nullptr;
|
||||
KDCoordinate currentViewWidth = totalWidth;
|
||||
if (i < numberOfSubviews()) {
|
||||
textView = textViewAtIndex(i);
|
||||
textView = subviewAtIndex(i);
|
||||
currentViewWidth = textView->minimalSizeForOptimalDisplay().width();
|
||||
}
|
||||
// The subview exceed the total width
|
||||
@@ -54,7 +53,7 @@ void BannerView::layoutSubviews() {
|
||||
int nbOfTextViewInLine = i > indexOfFirstViewOfCurrentLine ? i-indexOfFirstViewOfCurrentLine : 1;
|
||||
KDCoordinate roundingError = totalWidth-lineWidth-nbOfTextViewInLine*(int)((totalWidth-lineWidth)/nbOfTextViewInLine);
|
||||
for (int j = indexOfFirstViewOfCurrentLine; j < i; j++) {
|
||||
textViewPreviousLine = textViewAtIndex(j);
|
||||
textViewPreviousLine = subviewAtIndex(j);
|
||||
KDCoordinate textWidth = textViewPreviousLine->minimalSizeForOptimalDisplay().width() + (totalWidth - lineWidth)/nbOfTextViewInLine;
|
||||
// For the last text view, avoid letting a 1-pixel-wide empty vertical due to rounding error:
|
||||
textWidth = j == i-1 ? textWidth + roundingError : textWidth;
|
||||
@@ -71,17 +70,12 @@ void BannerView::layoutSubviews() {
|
||||
}
|
||||
}
|
||||
|
||||
View * BannerView::subviewAtIndex(int index) {
|
||||
assert(index >= 0 && index < numberOfSubviews());
|
||||
return textViewAtIndex(index);
|
||||
}
|
||||
|
||||
int BannerView::numberOfLines() const {
|
||||
KDCoordinate width = bounds().width();
|
||||
KDCoordinate usedWidth = 0;
|
||||
KDCoordinate lineNumber = 0;
|
||||
for (int i = 0; i < numberOfSubviews(); i++) {
|
||||
KDCoordinate textWidth = KDFont::SmallFont->stringSize(textViewAtIndex(i)->text()).width();
|
||||
KDCoordinate textWidth = const_cast<Shared::BannerView *>(this)->subviewAtIndex(i)->minimalSizeForOptimalDisplay().width();
|
||||
if (usedWidth+textWidth > width) {
|
||||
usedWidth = textWidth;
|
||||
lineNumber++;
|
||||
|
||||
@@ -13,10 +13,9 @@ public:
|
||||
KDSize minimalSizeForOptimalDisplay() const override;
|
||||
private:
|
||||
int numberOfSubviews() const override = 0;
|
||||
View * subviewAtIndex(int index) override;
|
||||
View * subviewAtIndex(int index) override = 0;
|
||||
void layoutSubviews() override;
|
||||
int numberOfLines() const;
|
||||
virtual TextView * textViewAtIndex(int i) const = 0;
|
||||
virtual MessageTextView * messageTextViewAtIndex(int i) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "box_banner_view.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Statistics {
|
||||
|
||||
@@ -9,9 +10,10 @@ BoxBannerView::BoxBannerView() :
|
||||
{
|
||||
}
|
||||
|
||||
TextView * BoxBannerView::textViewAtIndex(int index) const {
|
||||
const TextView * textViews[3] = {&m_seriesName, &m_calculationName, &m_calculationValue};
|
||||
return (TextView *)textViews[index];
|
||||
View * BoxBannerView::subviewAtIndex(int index) {
|
||||
assert(0 <= index && index < numberOfSubviews());
|
||||
View * subviews[] = {&m_seriesName, &m_calculationName, &m_calculationValue};
|
||||
return subviews[index];
|
||||
}
|
||||
|
||||
MessageTextView * BoxBannerView::messageTextViewAtIndex(int index) const {
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
private:
|
||||
static constexpr int k_numberOfSubviews = 3;
|
||||
int numberOfSubviews() const override { return k_numberOfSubviews; }
|
||||
TextView * textViewAtIndex(int i) const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
MessageTextView * messageTextViewAtIndex(int i) const override;
|
||||
BufferTextView m_seriesName;
|
||||
MessageTextView m_calculationName;
|
||||
|
||||
@@ -14,9 +14,10 @@ HistogramBannerView::HistogramBannerView() :
|
||||
{
|
||||
}
|
||||
|
||||
TextView * HistogramBannerView::textViewAtIndex(int i) const {
|
||||
const TextView * textViews[k_numberOfSubviews] = {&m_intervalLegendView, &m_intervalView, &m_sizeLegendView, &m_sizeView, &m_frequencyLegendView, &m_frequencyView};
|
||||
return (TextView *)textViews[i];
|
||||
View * HistogramBannerView::subviewAtIndex(int index) {
|
||||
assert(0 <= index && index < numberOfSubviews());
|
||||
View * subviews[] = {&m_intervalLegendView, &m_intervalView, &m_sizeLegendView, &m_sizeView, &m_frequencyLegendView, &m_frequencyView};
|
||||
return subviews[index];
|
||||
}
|
||||
|
||||
MessageTextView * HistogramBannerView::messageTextViewAtIndex(int index) const {
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
private:
|
||||
static constexpr int k_numberOfSubviews = 6;
|
||||
int numberOfSubviews() const override { return k_numberOfSubviews; }
|
||||
TextView * textViewAtIndex(int i) const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
MessageTextView * messageTextViewAtIndex(int index) const override;
|
||||
MessageTextView m_intervalLegendView;
|
||||
BufferTextView m_intervalView;
|
||||
|
||||
Reference in New Issue
Block a user