[escher] Create a class expression menu list cell

Change-Id: I4dfa2acf33fd3a2bf39c6579650f74aef72395f1
This commit is contained in:
Émilie Feral
2017-02-09 10:37:09 +01:00
parent 64280be6ac
commit 8691c55b06
6 changed files with 75 additions and 32 deletions

View File

@@ -17,6 +17,7 @@ objs += $(addprefix escher/src/,\
even_odd_editable_text_cell.o\
even_odd_expression_cell.o\
even_odd_pointer_text_cell.o\
expression_menu_list_cell.o\
expression_view.o\
header_view_controller.o\
header_view_delegate.o\

View File

@@ -18,6 +18,7 @@
#include <escher/even_odd_editable_text_cell.h>
#include <escher/even_odd_expression_cell.h>
#include <escher/even_odd_pointer_text_cell.h>
#include <escher/expression_menu_list_cell.h>
#include <escher/expression_view.h>
#include <escher/header_view_controller.h>
#include <escher/header_view_delegate.h>

View File

@@ -0,0 +1,25 @@
#ifndef ESCHER_EXPRESSION_MENU_LIST_CELL_H
#define ESCHER_EXPRESSION_MENU_LIST_CELL_H
#include <escher/view.h>
#include <escher/expression_view.h>
#include <escher/palette.h>
#include <escher/metric.h>
#include <escher/table_view_cell.h>
class ExpressionMenuListCell : public TableViewCell {
public:
ExpressionMenuListCell();
void setHighlighted(bool highlight) override;
void setExpression(Poincare::ExpressionLayout * expressionLayout);
void drawRect(KDContext * ctx, KDRect rect) const override;
protected:
constexpr static KDCoordinate k_separatorThickness = 1;
ExpressionView m_labelExpressionView;
private:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
};
#endif

View File

@@ -1,26 +1,18 @@
#ifndef ESCHER_EXPRESSION_BUFFER_MENU_LIST_CELL_H
#define ESCHER_EXPRESSION_BUFFER_MENU_LIST_CELL_H
#ifndef ESCHER_TEXT_EXPRESSION_MENU_LIST_CELL_H
#define ESCHER_TEXT_EXPRESSION_MENU_LIST_CELL_H
#include <escher/view.h>
#include <escher/expression_view.h>
#include <escher/expression_menu_list_cell.h>
#include <escher/pointer_text_view.h>
#include <escher/palette.h>
#include <escher/metric.h>
#include <escher/table_view_cell.h>
class TextExpressionMenuListCell : public TableViewCell {
class TextExpressionMenuListCell : public ExpressionMenuListCell {
public:
TextExpressionMenuListCell(char * accessoryText = nullptr);
void setHighlighted(bool highlight) override;
void setExpression(Poincare::ExpressionLayout * expressionLayout);
void setAccessoryText(const char * textBody);
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
constexpr static KDCoordinate k_separatorThickness = 1;
ExpressionView m_labelExpressionView;
PointerTextView m_accessoryView;
};

View File

@@ -0,0 +1,42 @@
#include <escher/expression_menu_list_cell.h>
#include <assert.h>
ExpressionMenuListCell::ExpressionMenuListCell() :
TableViewCell(),
m_labelExpressionView(ExpressionView(0.0f, 0.5f, KDColorBlack, KDColorWhite))
{
}
void ExpressionMenuListCell::setHighlighted(bool highlight) {
TableViewCell::setHighlighted(highlight);
KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
m_labelExpressionView.setBackgroundColor(backgroundColor);
}
void ExpressionMenuListCell::setExpression(Poincare::ExpressionLayout * expressionLayout) {
m_labelExpressionView.setExpression(expressionLayout);
}
void ExpressionMenuListCell::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDColor backgroundColor = isHighlighted() ? Palette::Select : KDColorWhite;
ctx->fillRect(KDRect(k_separatorThickness, k_separatorThickness, width-2*k_separatorThickness, height-k_separatorThickness), backgroundColor);
ctx->fillRect(KDRect(0, 0, width, k_separatorThickness), Palette::GreyBright);
ctx->fillRect(KDRect(0, k_separatorThickness, k_separatorThickness, height-k_separatorThickness), Palette::GreyBright);
ctx->fillRect(KDRect(width-k_separatorThickness, k_separatorThickness, k_separatorThickness, height-k_separatorThickness), Palette::GreyBright);
}
int ExpressionMenuListCell::numberOfSubviews() const {
return 1;
}
View * ExpressionMenuListCell::subviewAtIndex(int index) {
assert(index == 0);
return &m_labelExpressionView;
}
void ExpressionMenuListCell::layoutSubviews() {
m_labelExpressionView.setFrame(bounds());
}

View File

@@ -2,39 +2,21 @@
#include <assert.h>
TextExpressionMenuListCell::TextExpressionMenuListCell(char * accessoryText) :
TableViewCell(),
m_labelExpressionView(ExpressionView(0.0f, 0.5f, KDColorBlack, KDColorWhite)),
ExpressionMenuListCell(),
m_accessoryView(PointerTextView(KDText::FontSize::Small, accessoryText, 0.0f, 0.5f, Palette::GreyDark, KDColorWhite))
{
}
void TextExpressionMenuListCell::setHighlighted(bool highlight) {
TableViewCell::setHighlighted(highlight);
ExpressionMenuListCell::setHighlighted(highlight);
KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
m_labelExpressionView.setBackgroundColor(backgroundColor);
m_accessoryView.setBackgroundColor(backgroundColor);
}
void TextExpressionMenuListCell::setExpression(Poincare::ExpressionLayout * expressionLayout) {
m_labelExpressionView.setExpression(expressionLayout);
markRectAsDirty(bounds());
}
void TextExpressionMenuListCell::setAccessoryText(const char * text) {
m_accessoryView.setText(text);
}
void TextExpressionMenuListCell::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDColor backgroundColor = isHighlighted() ? Palette::Select : KDColorWhite;
ctx->fillRect(KDRect(k_separatorThickness, k_separatorThickness, width-2*k_separatorThickness, height-k_separatorThickness), backgroundColor);
ctx->fillRect(KDRect(0, 0, width, k_separatorThickness), Palette::GreyBright);
ctx->fillRect(KDRect(0, k_separatorThickness, k_separatorThickness, height-k_separatorThickness), Palette::GreyBright);
ctx->fillRect(KDRect(width-k_separatorThickness, k_separatorThickness, k_separatorThickness, height-k_separatorThickness), Palette::GreyBright);
}
int TextExpressionMenuListCell::numberOfSubviews() const {
return 2;
}