mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/regression] Create a banner view class
Change-Id: I30ad498b2c63c1a7edb09a05c40dd1f94373ead1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
app_objs += $(addprefix apps/regression/,\
|
||||
app.o\
|
||||
banner_view.o\
|
||||
calculation_controller.o\
|
||||
data.o\
|
||||
graph_controller.o\
|
||||
|
||||
88
apps/regression/banner_view.cpp
Normal file
88
apps/regression/banner_view.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "banner_view.h"
|
||||
#include "../constant.h"
|
||||
#include <assert.h>
|
||||
#include <poincare.h>
|
||||
|
||||
namespace Regression {
|
||||
|
||||
BannerView::BannerView(Data * data) :
|
||||
m_regressionTypeView(nullptr, 0.5f, 0.5f),
|
||||
m_slopeView(0.5f, 0.5f),
|
||||
m_yInterceptView(0.5f, 0.5f),
|
||||
m_xView(0.5f, 0.5f),
|
||||
m_yView(0.5f, 0.5f),
|
||||
m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
void BannerView::reload() {
|
||||
markRectAsDirty(bounds());
|
||||
m_regressionTypeView.setText("y = ax+b");
|
||||
char buffer[k_maxNumberOfCharacters];
|
||||
const char * legend = "a = ";
|
||||
int legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
float slope = m_data->slope();
|
||||
Float(slope).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
|
||||
m_slopeView.setText(buffer);
|
||||
|
||||
legend = "b = ";
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
float yIntercept = m_data->yIntercept();
|
||||
Float(yIntercept).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
|
||||
m_yInterceptView.setText(buffer);
|
||||
|
||||
legend = "x = ";
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
float x = m_data->xCursorPosition();
|
||||
Float(x).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
|
||||
m_xView.setText(buffer);
|
||||
|
||||
legend = "y = ";
|
||||
legendLength = strlen(legend);
|
||||
strlcpy(buffer, legend, legendLength+1);
|
||||
float y = m_data->yValueForXValue(x);
|
||||
Float(y).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
|
||||
m_yView.setText(buffer);
|
||||
}
|
||||
|
||||
void BannerView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), KDColorWhite);
|
||||
}
|
||||
|
||||
int BannerView::numberOfSubviews() const {
|
||||
return 5;
|
||||
}
|
||||
|
||||
View * BannerView::subviewAtIndex(int index) {
|
||||
assert(index >= 0);
|
||||
switch (index) {
|
||||
case 0:
|
||||
return &m_regressionTypeView;
|
||||
case 1:
|
||||
return &m_slopeView;
|
||||
case 2:
|
||||
return &m_yInterceptView;
|
||||
case 3:
|
||||
return &m_xView;
|
||||
case 4:
|
||||
return &m_yView;
|
||||
default:
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void BannerView::layoutSubviews() {
|
||||
KDCoordinate height = bounds().height();
|
||||
KDCoordinate width = bounds().width();
|
||||
m_regressionTypeView.setFrame(KDRect(0, 0, width/3, height/2));
|
||||
m_slopeView.setFrame(KDRect(width/3, 0, width/3, height/2));
|
||||
m_yInterceptView.setFrame(KDRect(2*width/3, 0, width/3, height/2));
|
||||
m_xView.setFrame(KDRect(0, height/2, width/3, height/2));
|
||||
m_yView.setFrame(KDRect(width/3, height/2, width/3, height/2));
|
||||
}
|
||||
|
||||
}
|
||||
29
apps/regression/banner_view.h
Normal file
29
apps/regression/banner_view.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef REGRESSION_BANNER_VIEW_H
|
||||
#define REGRESSION_BANNER_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "data.h"
|
||||
|
||||
namespace Regression {
|
||||
|
||||
class BannerView : public View {
|
||||
public:
|
||||
BannerView(Data * data);
|
||||
void reload();
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
constexpr static int k_maxNumberOfCharacters = 50;
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
PointerTextView m_regressionTypeView;
|
||||
BufferTextView m_slopeView;
|
||||
BufferTextView m_yInterceptView;
|
||||
BufferTextView m_xView;
|
||||
BufferTextView m_yView;
|
||||
Data * m_data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user