[escher] create class expression view

Change-Id: I16ddd22318ad120d736ad7f10bb2800a13c2b005
This commit is contained in:
Émilie Feral
2016-10-26 14:18:51 +02:00
parent 2eae7c43ff
commit 590c869bc8
4 changed files with 67 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ objs += $(addprefix escher/src/,\
button.o\
container.o\
header_view_controller.o\
expression_view.o\
image_view.o\
invocation.o\
input_view_controller.o\

View File

@@ -6,6 +6,7 @@
#include <escher/button.h>
#include <escher/container.h>
#include <escher/header_view_controller.h>
#include <escher/expression_view.h>
#include <escher/image.h>
#include <escher/image_view.h>
#include <escher/input_view_controller.h>

View File

@@ -0,0 +1,28 @@
#ifndef ESCHER_EXPRESSION_VIEW_H
#define ESCHER_EXPRESSION_VIEW_H
#include <escher/view.h>
#include <kandinsky/color.h>
#include <poincare/expression_layout.h>
/* This class does not handle the expression layout as the size of the layout is
* needed to compute the size of table cells hosting the expression. As the size
* of this cell is determined before we set the expression in the expression
* view, we cannot use minimalSizeForOptimalDisplay to assess the required
* size. */
class ExpressionView : public View {
public:
ExpressionView();
void setExpression(ExpressionLayout * expressionLayout);
void drawRect(KDContext * ctx, KDRect rect) const override;
void setBackgroundColor(KDColor backgroundColor);
void setTextColor(KDColor textColor);
KDSize minimalSizeForOptimalDisplay() override;
private:
ExpressionLayout * m_expressionLayout;
KDColor m_textColor;
KDColor m_backgroundColor;
};
#endif

View File

@@ -0,0 +1,37 @@
#include <escher/expression_view.h>
ExpressionView::ExpressionView() :
m_expressionLayout(nullptr),
m_textColor(KDColorBlack),
m_backgroundColor(KDColorWhite)
{
}
void ExpressionView::setExpression(ExpressionLayout * expressionLayout) {
m_expressionLayout = expressionLayout;
}
void ExpressionView::setBackgroundColor(KDColor backgroundColor) {
m_backgroundColor = backgroundColor;
}
void ExpressionView::setTextColor(KDColor textColor) {
m_textColor = textColor;
}
KDSize ExpressionView::minimalSizeForOptimalDisplay() {
if (m_expressionLayout == nullptr) {
return KDSizeZero;
}
return m_expressionLayout->size();
}
void ExpressionView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, m_backgroundColor);
if (m_expressionLayout != nullptr) {
//Position the origin of expression
KDSize expressionSize = m_expressionLayout->size();
KDPoint origin(0, 0.5f*(m_frame.height() - expressionSize.height()));
m_expressionLayout->draw(ctx, origin, m_textColor, m_backgroundColor);
}
}