From 7efec4331d194fb06dddc340ee42c9eb4cf4a036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 23 Sep 2016 14:03:05 +0200 Subject: [PATCH] [apps/graph/list] Improve the drawRect of function cells Change-Id: I2338151444e04f44e2b432ec8435ff63a2837fc9 --- apps/graph/list/function_cell.cpp | 7 ++++++- apps/graph/list/function_cell.h | 6 +++++- apps/graph/list/function_expression_view.cpp | 11 ++++++----- apps/graph/list/function_name_view.cpp | 18 ++++++++++++------ apps/graph/list/function_name_view.h | 1 + 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/apps/graph/list/function_cell.cpp b/apps/graph/list/function_cell.cpp index 298171c85..757d79729 100644 --- a/apps/graph/list/function_cell.cpp +++ b/apps/graph/list/function_cell.cpp @@ -3,6 +3,11 @@ #include #include +constexpr KDColor FunctionCell::k_evenLineBackgroundColor; +constexpr KDColor FunctionCell::k_oddLineBackgroundColor; +constexpr KDColor FunctionCell::k_selectedLineBackgroundColor; +constexpr KDColor FunctionCell::k_desactiveTextColor; + FunctionCell::FunctionCell() : View(), Responder(nullptr), @@ -32,7 +37,7 @@ View * FunctionCell::subviewAtIndex(int index) { } void FunctionCell::layoutSubviews() { m_functionNameView.setFrame(KDRect(0, 0, k_functionNameWidth, k_functionCellHeight)); - m_functionExpressionView.setFrame(KDRect(k_functionNameWidth, 0, k_functionExpressionWidth, k_functionCellHeight)); + m_functionExpressionView.setFrame(KDRect(k_functionNameWidth, 0, bounds().width()-k_functionNameWidth, k_functionCellHeight)); } diff --git a/apps/graph/list/function_cell.h b/apps/graph/list/function_cell.h index c45c4b709..5300e0e6b 100644 --- a/apps/graph/list/function_cell.h +++ b/apps/graph/list/function_cell.h @@ -17,9 +17,13 @@ public: void didBecomeFirstResponder() override; bool handleEvent(Ion::Events::Event event) override; + static constexpr KDColor k_evenLineBackgroundColor = KDColor(0xF9F9F9); + static constexpr KDColor k_oddLineBackgroundColor = KDColor(0xEEEEF2); + static constexpr KDColor k_selectedLineBackgroundColor = KDColor(0x8582DB); + static constexpr KDColor k_desactiveTextColor = KDColor(0x646464); + private: static constexpr KDCoordinate k_functionNameWidth = 40; - static constexpr KDCoordinate k_functionExpressionWidth = 100; static constexpr KDCoordinate k_functionCellHeight = 50; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; diff --git a/apps/graph/list/function_expression_view.cpp b/apps/graph/list/function_expression_view.cpp index 8a7ebc481..9df7de0d9 100644 --- a/apps/graph/list/function_expression_view.cpp +++ b/apps/graph/list/function_expression_view.cpp @@ -10,15 +10,16 @@ FunctionExpressionView::FunctionExpressionView(Responder * parentResponder) : } void FunctionExpressionView::drawRect(KDContext * ctx, KDRect rect) const { + // Select the background color according to the even line and the cursor selection bool evenLine = isEven(); - KDColor background = evenLine ? KDColor(0xEEEEEE) : KDColor(0x777777); + KDColor background = evenLine ? FunctionCell::k_evenLineBackgroundColor : FunctionCell::k_oddLineBackgroundColor; + background = m_focused ? FunctionCell::k_selectedLineBackgroundColor : background; ctx->fillRect(rect, background); + // Select text color according to the state of the function bool active = function()->isActive(); - KDColor text = active ? KDColorGreen : KDColorRed; - KDColor textBackground = m_focused ? KDColorWhite : KDColorBlack; - + KDColor text = active ? KDColorBlack : FunctionCell::k_desactiveTextColor; Graph::Function * function = FunctionExpressionView::function(); - ctx->drawString(function->text(), KDPointZero, text, textBackground); + ctx->drawString(function->text(), KDPointZero, text, background); // m_function->layout()->draw(ctx, KDPointZero); } diff --git a/apps/graph/list/function_name_view.cpp b/apps/graph/list/function_name_view.cpp index 162aede0a..b0571406c 100644 --- a/apps/graph/list/function_name_view.cpp +++ b/apps/graph/list/function_name_view.cpp @@ -11,15 +11,21 @@ FunctionNameView::FunctionNameView(Responder * parentResponder, Invocation invoc } void FunctionNameView::drawRect(KDContext * ctx, KDRect rect) const { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + // First color the color indicator + KDColor functionColor = function()->color(); + ctx->fillRect(KDRect(0, 0, k_colorIndicatorThickness, height), functionColor); + // Select the background color according to the even line and the cursor selection bool evenLine = isEven(); - KDColor background = evenLine ? KDColor(0xEEEEEE) : KDColor(0x777777); - ctx->fillRect(rect, background); + KDColor background = evenLine ? FunctionCell::k_evenLineBackgroundColor : FunctionCell::k_oddLineBackgroundColor; + background = m_focused ? FunctionCell::k_selectedLineBackgroundColor : background; + ctx->fillRect(KDRect(4, 0, width-4, height), background); + // Select text color according to the state of the function bool active = function()->isActive(); - KDColor text = active ? KDColorGreen : KDColorRed; - KDColor textBackground = m_focused ? KDColorWhite : KDColorBlack; - + KDColor text = active ? KDColorBlack : FunctionCell::k_desactiveTextColor; Graph::Function * function = FunctionNameView::function(); - ctx->drawString(function->name(), KDPointZero, text, textBackground); + ctx->drawString(function->name(), KDPoint(4, 0), text, background); // m_function->layout()->draw(ctx, KDPointZero); } diff --git a/apps/graph/list/function_name_view.h b/apps/graph/list/function_name_view.h index e63ad7b11..9c8a4a26e 100644 --- a/apps/graph/list/function_name_view.h +++ b/apps/graph/list/function_name_view.h @@ -18,6 +18,7 @@ public: void didResignFirstResponder() override; bool handleEvent(Ion::Events::Event event) override; private: + constexpr static int k_colorIndicatorThickness = 4; bool m_focused; Invocation m_invocation; };