From 3fa4e0838a3da13eed9db249a9c18ce0d28509fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 16 Jan 2020 10:28:09 +0100 Subject: [PATCH] [escher] Create a class Bordered instead of BorderedCell: this enable non-cell view to use it as well --- .../additional_outputs/illustration_cell.cpp | 4 ++++ .../additional_outputs/illustration_cell.h | 7 ++++--- escher/Makefile | 2 +- escher/include/escher/bordered.h | 16 ++++++++++++++++ escher/include/escher/bordered_cell.h | 16 ---------------- escher/include/escher/table_cell.h | 5 +++-- escher/src/bordered.cpp | 15 +++++++++++++++ escher/src/bordered_cell.cpp | 12 ------------ escher/src/table_cell.cpp | 11 +++++------ 9 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 escher/include/escher/bordered.h delete mode 100644 escher/include/escher/bordered_cell.h create mode 100644 escher/src/bordered.cpp delete mode 100644 escher/src/bordered_cell.cpp diff --git a/apps/calculation/additional_outputs/illustration_cell.cpp b/apps/calculation/additional_outputs/illustration_cell.cpp index 638bc6616..bd2471710 100644 --- a/apps/calculation/additional_outputs/illustration_cell.cpp +++ b/apps/calculation/additional_outputs/illustration_cell.cpp @@ -9,4 +9,8 @@ void IllustrationCell::layoutSubviews(bool force) { view()->setFrame(KDRect(Metric::CellSeparatorThickness, Metric::CellSeparatorThickness, bounds().width() - 2*Metric::CellSeparatorThickness, bounds().height() - 2*Metric::CellSeparatorThickness), force); } +void IllustrationCell::drawRect(KDContext * ctx, KDRect rect) const { + drawBorderOfRect(ctx, bounds(), Palette::GreyBright); +} + } diff --git a/apps/calculation/additional_outputs/illustration_cell.h b/apps/calculation/additional_outputs/illustration_cell.h index 1421357a2..5878053e3 100644 --- a/apps/calculation/additional_outputs/illustration_cell.h +++ b/apps/calculation/additional_outputs/illustration_cell.h @@ -1,14 +1,15 @@ #ifndef CALCULATION_ADDITIONAL_OUTPUTS_ILLUSTRATION_CELL_H #define CALCULATION_ADDITIONAL_OUTPUTS_ILLUSTRATION_CELL_H -#include +#include +#include namespace Calculation { -class IllustrationCell : public BorderedCell { +class IllustrationCell : public Bordered, public HighlightCell { public: - using BorderedCell::BorderedCell; void setHighlighted(bool highlight) override { return; } + void drawRect(KDContext * ctx, KDRect rect) const override; private: int numberOfSubviews() const override { return 1; } View * subviewAtIndex(int index) override { return view(); } diff --git a/escher/Makefile b/escher/Makefile index f21b2daf3..f68cbc8df 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -4,7 +4,7 @@ escher_src += $(addprefix escher/src/,\ alternate_empty_view_controller.cpp \ app.cpp \ bank_view_controller.cpp \ - bordered_cell.cpp \ + bordered.cpp \ buffer_text_view.cpp \ burger_menu_view.cpp \ button.cpp \ diff --git a/escher/include/escher/bordered.h b/escher/include/escher/bordered.h new file mode 100644 index 000000000..84a80f235 --- /dev/null +++ b/escher/include/escher/bordered.h @@ -0,0 +1,16 @@ +#ifndef ESCHER_BORDERED_H +#define ESCHER_BORDERED_H + +#include +#include + +class Bordered { +public: + void drawBorderOfRect(KDContext * ctx, KDRect rect, KDColor borderColor) const; + void drawInnerRect(KDContext * ctx, KDRect rect, KDColor backgroundColor) const; +protected: + constexpr static KDCoordinate k_separatorThickness = Metric::CellSeparatorThickness; +}; + +#endif + diff --git a/escher/include/escher/bordered_cell.h b/escher/include/escher/bordered_cell.h deleted file mode 100644 index d1e02a651..000000000 --- a/escher/include/escher/bordered_cell.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef ESCHER_BORDERED_CELL_H -#define ESCHER_BORDERED_CELL_H - -#include -#include - -class BorderedCell : public HighlightCell { -public: - using HighlightCell::HighlightCell; - void drawRect(KDContext * ctx, KDRect rect) const override; -protected: - constexpr static KDCoordinate k_separatorThickness = Metric::CellSeparatorThickness; -}; - -#endif - diff --git a/escher/include/escher/table_cell.h b/escher/include/escher/table_cell.h index 12393e46e..e46da7bf6 100644 --- a/escher/include/escher/table_cell.h +++ b/escher/include/escher/table_cell.h @@ -1,9 +1,10 @@ #ifndef ESCHER_TABLE_CELL_H #define ESCHER_TABLE_CELL_H -#include +#include +#include -class TableCell : public BorderedCell { +class TableCell : public Bordered, public HighlightCell { public: /* Layout enum class determines the way subviews are layouted. * We can split the cell vertically or horizontally. diff --git a/escher/src/bordered.cpp b/escher/src/bordered.cpp new file mode 100644 index 000000000..f64c3f495 --- /dev/null +++ b/escher/src/bordered.cpp @@ -0,0 +1,15 @@ +#include + +void Bordered::drawBorderOfRect(KDContext * ctx, KDRect rect, KDColor borderColor) const { + KDCoordinate width = rect.width(); + KDCoordinate height = rect.height(); + // Draw rectangle around cell + ctx->fillRect(KDRect(0, 0, width, k_separatorThickness), borderColor); + ctx->fillRect(KDRect(0, k_separatorThickness, k_separatorThickness, height-k_separatorThickness), borderColor); + ctx->fillRect(KDRect(width-k_separatorThickness, k_separatorThickness, k_separatorThickness, height-k_separatorThickness), borderColor); + ctx->fillRect(KDRect(0, height-k_separatorThickness, width, k_separatorThickness), borderColor); + } + +void Bordered::drawInnerRect(KDContext * ctx, KDRect rect, KDColor backgroundColor) const { + ctx->fillRect(KDRect(k_separatorThickness, k_separatorThickness, rect.width()-2*k_separatorThickness, rect.height()-k_separatorThickness), backgroundColor); +} diff --git a/escher/src/bordered_cell.cpp b/escher/src/bordered_cell.cpp deleted file mode 100644 index 1902ad3c1..000000000 --- a/escher/src/bordered_cell.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -void BorderedCell::drawRect(KDContext * ctx, KDRect rect) const { - KDCoordinate width = bounds().width(); - KDCoordinate height = bounds().height(); - // Draw rectangle around cell - 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); - ctx->fillRect(KDRect(0, height-k_separatorThickness, width, k_separatorThickness), Palette::GreyBright); - } diff --git a/escher/src/table_cell.cpp b/escher/src/table_cell.cpp index 196927436..d812f47eb 100644 --- a/escher/src/table_cell.cpp +++ b/escher/src/table_cell.cpp @@ -6,7 +6,8 @@ static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { retur static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } TableCell::TableCell(Layout layout) : - BorderedCell(), + Bordered(), + HighlightCell(), m_layout(layout) { } @@ -165,9 +166,7 @@ void TableCell::layoutSubviews(bool force) { } void TableCell::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); - BorderedCell::drawRect(ctx, rect); - } + drawInnerRect(ctx, bounds(), backgroundColor); + drawBorderOfRect(ctx, bounds(), Palette::GreyBright); +}