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