[escher] Create a class text buffer menu list cell

Change-Id: I31fb8e2a0f842e7080ddde7d717511ff1e4b7ab5
This commit is contained in:
Émilie Feral
2017-02-08 11:55:46 +01:00
parent 9d6a945fbe
commit b5b0cef18a
4 changed files with 83 additions and 0 deletions

View File

@@ -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\

View File

@@ -43,6 +43,7 @@
#include <escher/switch_menu_list_cell.h>
#include <escher/text_field.h>
#include <escher/text_field_delegate.h>
#include <escher/text_buffer_menu_list_cell.h>
#include <escher/text_menu_list_cell.h>
#include <escher/text_view.h>
#include <escher/tab_view_controller.h>

View File

@@ -0,0 +1,27 @@
#ifndef ESCHER_TEXT_BUFFER_MENU_LIST_CELL_H
#define ESCHER_TEXT_BUFFER_MENU_LIST_CELL_H
#include <escher/view.h>
#include <escher/buffer_text_view.h>
#include <escher/pointer_text_view.h>
#include <escher/palette.h>
#include <escher/metric.h>
#include <escher/table_view_cell.h>
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

View File

@@ -0,0 +1,54 @@
#include <escher/text_buffer_menu_list_cell.h>
#include <assert.h>
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));
}