mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[escher] create class expression view
Change-Id: I16ddd22318ad120d736ad7f10bb2800a13c2b005
This commit is contained in:
@@ -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\
|
||||
|
||||
@@ -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>
|
||||
|
||||
28
escher/include/escher/expression_view.h
Normal file
28
escher/include/escher/expression_view.h
Normal 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
|
||||
37
escher/src/expression_view.cpp
Normal file
37
escher/src/expression_view.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user