Files
Upsilon/apps/toolbox_leaf_cell.cpp
Émilie Feral 0df7d64dce [apps] create a class toolbox leaf cell
Change-Id: Iee2efaab85646329700078ebd83079a82e5a31f6
2016-11-14 17:06:55 +01:00

54 lines
1.8 KiB
C++

#include "toolbox_leaf_cell.h"
#include <assert.h>
ToolboxLeafCell::ToolboxLeafCell() :
TableViewCell(),
m_labelView(PointerTextView(nullptr, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor)),
m_subtitleView(PointerTextView(nullptr, 0, 0.5, Palette::DesactiveTextColor, Palette::CellBackgroundColor))
{
}
int ToolboxLeafCell::numberOfSubviews() const {
return 2;
}
View * ToolboxLeafCell::subviewAtIndex(int index) {
assert(index == 0 || index == 1);
if (index == 0) {
return &m_labelView;
}
return &m_subtitleView;
}
void ToolboxLeafCell::layoutSubviews() {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
m_labelView.setFrame(KDRect(1, 1, width-2, height/2 - 1));
m_subtitleView.setFrame(KDRect(1, height/2, width-2, height/2 - 1));
}
void ToolboxLeafCell::reloadCell() {
TableViewCell::reloadCell();
KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_labelView.setBackgroundColor(backgroundColor);
m_subtitleView.setBackgroundColor(backgroundColor);
}
void ToolboxLeafCell::setLabel(const char * text) {
m_labelView.setText(text);
}
void ToolboxLeafCell::setSubtitle(const char * text) {
m_subtitleView.setText(text);
}
void ToolboxLeafCell::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
ctx->fillRect(KDRect(1, 0, width-2, height-1), backgroundColor);
ctx->fillRect(KDRect(0, height-1, width, 1), Palette::LineColor);
ctx->fillRect(KDRect(0, 0, 1, height-1), Palette::LineColor);
ctx->fillRect(KDRect(width-1, 0, 1, height-1), Palette::LineColor);
}