diff --git a/apps/graph/list/function_expression_view.cpp b/apps/graph/list/function_expression_view.cpp index 01301d2ab..fda097910 100644 --- a/apps/graph/list/function_expression_view.cpp +++ b/apps/graph/list/function_expression_view.cpp @@ -1,4 +1,5 @@ #include "function_expression_view.h" +#include namespace Graph { @@ -6,35 +7,48 @@ constexpr KDColor FunctionExpressionView::k_separatorColor; FunctionExpressionView::FunctionExpressionView() : EvenOddCell(), - m_function(nullptr) + m_function(nullptr), + m_expressionView(ExpressionView()) { } void FunctionExpressionView::setFunction(Function * f) { m_function = f; - markRectAsDirty(bounds()); + m_expressionView.setExpression(m_function->layout()); +} + +void FunctionExpressionView::reloadCell() { + EvenOddCell::reloadCell(); + m_expressionView.setBackgroundColor(backgroundColor()); + if (m_function) { + bool active = m_function->isActive(); + KDColor textColor = active ? KDColorBlack : Palette::k_desactiveTextColor; + m_expressionView.setTextColor(textColor); + } } Function * FunctionExpressionView::function() { return m_function; } +int FunctionExpressionView::numberOfSubviews() const { + return 1; +} + +View * FunctionExpressionView::subviewAtIndex(int index) { + assert(index == 0); + return &m_expressionView; +} + +void FunctionExpressionView::layoutSubviews() { + KDRect expressionFrame(k_separatorThickness, 0, bounds().width() - k_separatorThickness, bounds().height()); + m_expressionView.setFrame(expressionFrame); +} + void FunctionExpressionView::drawRect(KDContext * ctx, KDRect rect) const { EvenOddCell::drawRect(ctx, rect); // Color the separator ctx->fillRect(KDRect(0, 0, k_separatorThickness, bounds().height()), k_separatorColor); - if (m_function->layout() == nullptr) { - return; - } - // Select the background color according to the even line and the cursor selection - KDColor background = backgroundColor(); - // Select text color according to the state of the function - bool active = m_function->isActive(); - KDColor text = active ? KDColorBlack : Palette::k_desactiveTextColor; - //Position the origin of expression - KDSize expressionSize = m_function->layout()->size(); - KDPoint origin(k_separatorThickness, 0.5f*(m_frame.height() - expressionSize.height())); - m_function->layout()->draw(ctx, origin, text, background); } } diff --git a/apps/graph/list/function_expression_view.h b/apps/graph/list/function_expression_view.h index e3e79fe41..df54632b0 100644 --- a/apps/graph/list/function_expression_view.h +++ b/apps/graph/list/function_expression_view.h @@ -14,11 +14,18 @@ public: FunctionExpressionView(); void setFunction(Function * f); Function * function(); + void reloadCell() override; + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; void drawRect(KDContext * ctx, KDRect rect) const override; private: + static constexpr KDCoordinate k_verticalFunctionMargin = 50-12; + static constexpr KDCoordinate k_emptyRowHeight = 50; constexpr static KDColor k_separatorColor = KDColor(0xEFF2F4); constexpr static KDCoordinate k_separatorThickness = 1; Function * m_function; + ExpressionView m_expressionView; }; }