mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] Create a class expression menu list cell
Change-Id: I4dfa2acf33fd3a2bf39c6579650f74aef72395f1
This commit is contained in:
@@ -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\
|
||||
|
||||
@@ -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>
|
||||
|
||||
25
escher/include/escher/expression_menu_list_cell.h
Normal file
25
escher/include/escher/expression_menu_list_cell.h
Normal 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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
42
escher/src/expression_menu_list_cell.cpp
Normal file
42
escher/src/expression_menu_list_cell.cpp
Normal 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());
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user