diff --git a/apps/Makefile b/apps/Makefile index 391198b36..684bcc105 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -13,6 +13,7 @@ app_objs += $(addprefix apps/,\ node_list_view_controller.o\ node_navigation_controller.o\ toolbox_controller.o\ + toolbox_leaf_cell.o\ toolbox_node.o\ variable_box_controller.o\ variable_box_node.o\ diff --git a/apps/toolbox_leaf_cell.cpp b/apps/toolbox_leaf_cell.cpp new file mode 100644 index 000000000..8d0a069b3 --- /dev/null +++ b/apps/toolbox_leaf_cell.cpp @@ -0,0 +1,53 @@ +#include "toolbox_leaf_cell.h" +#include + +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); + } diff --git a/apps/toolbox_leaf_cell.h b/apps/toolbox_leaf_cell.h new file mode 100644 index 000000000..7c8e891d6 --- /dev/null +++ b/apps/toolbox_leaf_cell.h @@ -0,0 +1,21 @@ +#ifndef APPS_TOOLBOX_LEAF_CELL_H +#define APPS_TOOLBOX_LEAF_CELL_H + +#include + +class ToolboxLeafCell : public TableViewCell { +public: + ToolboxLeafCell(); + void reloadCell() override; + void setLabel(const char * text); + void setSubtitle(const char * text); + void drawRect(KDContext * ctx, KDRect rect) const override; +private: + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + PointerTextView m_labelView; + PointerTextView m_subtitleView; +}; + +#endif