From 978e3927ee033c07c1d2f64eb105f89f5b9f246d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 1 Dec 2016 17:36:06 +0100 Subject: [PATCH] [apps/probability] Create a class cell for the probability main menu Change-Id: I101e35a64cab6c7d5ebdee1a91b9c37e54964497 --- apps/probability/Makefile | 1 + apps/probability/cell.cpp | 66 +++++++++++++++++++++++++++++++++++++++ apps/probability/cell.h | 32 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 apps/probability/cell.cpp create mode 100644 apps/probability/cell.h diff --git a/apps/probability/Makefile b/apps/probability/Makefile index 9ccf10832..203c00f9a 100644 --- a/apps/probability/Makefile +++ b/apps/probability/Makefile @@ -1,5 +1,6 @@ app_objs += $(addprefix apps/probability/,\ app.o\ + cell.o\ law.o\ law/law_controller.o\ parameters/parameters_controller.o\ diff --git a/apps/probability/cell.cpp b/apps/probability/cell.cpp new file mode 100644 index 000000000..a9a4116b1 --- /dev/null +++ b/apps/probability/cell.cpp @@ -0,0 +1,66 @@ +#include "cell.h" +#include + +namespace Probability { + +Cell::Cell() : + TableViewCell(), + m_labelView(PointerTextView(nullptr, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor)) +{ +} + +int Cell::numberOfSubviews() const { + return 3; +} + +View * Cell::subviewAtIndex(int index) { + assert(index >= 0 && index < 3); + if (index == 0) { + return &m_labelView; + } + if (index == 1) { + return &m_iconView; + } + return &m_chevronView; +} + +void Cell::layoutSubviews() { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + m_labelView.setFrame(KDRect(1+k_iconWidth+2*k_iconMargin, 1, width-2-k_iconWidth-2*k_iconMargin - k_chevronWidth, height-2)); + m_iconView.setFrame(KDRect(1+k_iconMargin, (height - k_iconHeight)/2, k_iconWidth, k_iconHeight)); + m_chevronView.setFrame(KDRect(width-1-k_chevronWidth, 1, k_chevronWidth, height - 2)); +} + +void Cell::reloadCell() { + TableViewCell::reloadCell(); + KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; + m_labelView.setBackgroundColor(backgroundColor); + m_chevronView.setHighlighted(isHighlighted()); + if (isHighlighted()) { + m_iconView.setImage(m_focusedIcon); + } else { + m_iconView.setImage(m_icon); + } +} + +void Cell::setLabel(const char * text) { + m_labelView.setText(text); +} + +void Cell::setImage(const Image * image, const Image * focusedImage) { + m_icon = image; + m_focusedIcon = focusedImage; +} + +void Cell::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, 1, width-2, height-1), backgroundColor); + ctx->fillRect(KDRect(0, 0, width, 1), Palette::LineColor); + ctx->fillRect(KDRect(0, 1, 1, height-1), Palette::LineColor); + ctx->fillRect(KDRect(width-1, 1, 1, height-1), Palette::LineColor); + } + +} diff --git a/apps/probability/cell.h b/apps/probability/cell.h new file mode 100644 index 000000000..c12c91ec3 --- /dev/null +++ b/apps/probability/cell.h @@ -0,0 +1,32 @@ +#ifndef APPS_PROBABILITY_CELL_H +#define APPS_PROBABILITY_CELL_H + +#include + +namespace Probability { + +class Cell : public TableViewCell { +public: + Cell(); + void reloadCell() override; + void setLabel(const char * text); + void setImage(const Image * image, const Image * focusedImage); + void drawRect(KDContext * ctx, KDRect rect) const override; +private: + constexpr static KDCoordinate k_iconWidth = 35; + constexpr static KDCoordinate k_iconHeight = 19; + constexpr static KDCoordinate k_iconMargin = 10; + constexpr static KDCoordinate k_chevronWidth = 20+8; + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + PointerTextView m_labelView; + ImageView m_iconView; + const Image * m_icon; + const Image * m_focusedIcon; + ChevronView m_chevronView; +}; + +} + +#endif