Numworks Epsilon  1.4.1
Graphing Calculator Operating System
expression_view.cpp
Go to the documentation of this file.
2 using namespace Poincare;
3 
4 ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignment,
5  KDColor textColor, KDColor backgroundColor) :
6  m_expressionLayout(nullptr),
7  m_horizontalAlignment(horizontalAlignment),
8  m_verticalAlignment(verticalAlignment),
9  m_textColor(textColor),
10  m_backgroundColor(backgroundColor)
11 {
12 }
13 
15  return m_expressionLayout;
16 }
17 
19  m_expressionLayout = expressionLayout;
21 }
22 
24  if (m_backgroundColor != backgroundColor) {
25  m_backgroundColor = backgroundColor;
27  }
28 }
29 
31  if (textColor != m_textColor) {
32  m_textColor = textColor;
34  }
35 }
36 
37 void ExpressionView::setAlignment(float horizontalAlignment, float verticalAlignment) {
38  m_horizontalAlignment = horizontalAlignment;
39  m_verticalAlignment = verticalAlignment;
41 }
42 
44  if (m_expressionLayout == nullptr) {
45  return KDSizeZero;
46  }
47  return m_expressionLayout->size();
48 }
49 
50 void ExpressionView::drawRect(KDContext * ctx, KDRect rect) const {
51  ctx->fillRect(rect, m_backgroundColor);
52  if (m_expressionLayout != nullptr) {
53  //Position the origin of expression
54  KDSize expressionSize = m_expressionLayout->size();
55  KDPoint origin(m_horizontalAlignment*(m_frame.width() - expressionSize.width()),
56  0.5f*(m_frame.height() - expressionSize.height()));
57  m_expressionLayout->draw(ctx, origin, m_textColor, m_backgroundColor);
58  }
59 }
void setBackgroundColor(KDColor backgroundColor)
void draw(KDContext *ctx, KDPoint p, KDColor expressionColor=KDColorBlack, KDColor backgroundColor=KDColorWhite)
constexpr KDCoordinate width() const
Definition: size.h:10
void setExpression(Poincare::ExpressionLayout *expressionLayout)
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
KDSize minimalSizeForOptimalDisplay() const override
void setAlignment(float horizontalAlignment, float verticalAlignment)
Definition: point.h:6
Definition: size.h:6
KDRect m_frame
Definition: view.h:66
ExpressionView(float horizontalAlignment=0.0f, float verticalAlignment=0.5f, KDColor textColor=KDColorBlack, KDColor backgroundColor=KDColorWhite)
Poincare::ExpressionLayout * expressionLayout() const
void setTextColor(KDColor textColor)
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
constexpr KDSize KDSizeZero
Definition: size.h:17
void drawRect(KDContext *ctx, KDRect rect) const override
KDCoordinate width() const
Definition: rect.h:39
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
constexpr KDCoordinate height() const
Definition: size.h:11