diff --git a/escher/Makefile b/escher/Makefile index d14dc1c4d..8c771f47a 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -46,6 +46,7 @@ objs += $(addprefix escher/src/,\ table_view_cell.o\ table_view_data_source.o\ text_field.o\ + text_buffer_menu_list_cell.o\ text_menu_list_cell.o\ text_view.o\ tiled_view.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index f6efbdc48..ff7ca46ef 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff --git a/escher/include/escher/text_buffer_menu_list_cell.h b/escher/include/escher/text_buffer_menu_list_cell.h new file mode 100644 index 000000000..3907c949a --- /dev/null +++ b/escher/include/escher/text_buffer_menu_list_cell.h @@ -0,0 +1,27 @@ +#ifndef ESCHER_TEXT_BUFFER_MENU_LIST_CELL_H +#define ESCHER_TEXT_BUFFER_MENU_LIST_CELL_H + +#include +#include +#include +#include +#include +#include + +class TextBufferMenuListCell : public TableViewCell { +public: + TextBufferMenuListCell(char * accessoryText = nullptr); + void setHighlighted(bool highlight) override; + void setText(const char * text); + 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; + BufferTextView m_labelTextView; + PointerTextView m_accessoryView; +}; + +#endif diff --git a/escher/src/text_buffer_menu_list_cell.cpp b/escher/src/text_buffer_menu_list_cell.cpp new file mode 100644 index 000000000..b3c13b528 --- /dev/null +++ b/escher/src/text_buffer_menu_list_cell.cpp @@ -0,0 +1,54 @@ +#include +#include + +TextBufferMenuListCell::TextBufferMenuListCell(char * accessoryText) : + TableViewCell(), + m_labelTextView(BufferTextView(KDText::FontSize::Large, 0.0f, 0.5f, KDColorBlack, KDColorWhite)), + m_accessoryView(PointerTextView(KDText::FontSize::Small, accessoryText, 0.0f, 0.5f, KDColorBlack, KDColorWhite)) +{ +} + +void TextBufferMenuListCell::setHighlighted(bool highlight) { + TableViewCell::setHighlighted(highlight); + KDColor backgroundColor = highlight? Palette::Select : KDColorWhite; + m_labelTextView.setBackgroundColor(backgroundColor); + m_accessoryView.setBackgroundColor(backgroundColor); +} + +void TextBufferMenuListCell::setText(const char * text) { + m_labelTextView.setText(text); +} + +void TextBufferMenuListCell::setAccessoryText(const char * text) { + m_accessoryView.setText(text); +} + +void TextBufferMenuListCell::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 TextBufferMenuListCell::numberOfSubviews() const { + return 2; +} + +View * TextBufferMenuListCell::subviewAtIndex(int index) { + assert(index == 0 || index == 1); + if (index == 0) { + return &m_labelTextView; + } + return &m_accessoryView; +} + +void TextBufferMenuListCell::layoutSubviews() { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + m_labelTextView.setFrame(KDRect(k_separatorThickness, k_separatorThickness, width, height/2 - k_separatorThickness)); + m_accessoryView.setFrame(KDRect(k_separatorThickness, height/2, width, height/2 - k_separatorThickness)); +}