[escher] Create a BorderedCell that draws the border around a cell and

use it in TableCell
This commit is contained in:
Émilie Feral
2020-01-15 16:28:40 +01:00
committed by Léa Saviot
parent 404c0945f9
commit 235b03a923
5 changed files with 33 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ escher_src += $(addprefix escher/src/,\
alternate_empty_view_controller.cpp \
app.cpp \
bank_view_controller.cpp \
bordered_cell.cpp \
buffer_text_view.cpp \
burger_menu_view.cpp \
button.cpp \

View File

@@ -0,0 +1,16 @@
#ifndef ESCHER_BORDERED_CELL_H
#define ESCHER_BORDERED_CELL_H
#include <escher/highlight_cell.h>
#include <escher/metric.h>
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

View File

@@ -1,10 +1,9 @@
#ifndef ESCHER_TABLE_CELL_H
#define ESCHER_TABLE_CELL_H
#include <escher/highlight_cell.h>
#include <escher/metric.h>
#include <escher/bordered_cell.h>
class TableCell : public HighlightCell {
class TableCell : public BorderedCell {
public:
/* Layout enum class determines the way subviews are layouted.
* We can split the cell vertically or horizontally.
@@ -28,7 +27,6 @@ protected:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews(bool force = false) override;
constexpr static KDCoordinate k_separatorThickness = Metric::CellSeparatorThickness;
constexpr static KDCoordinate k_verticalMargin = Metric::TableCellVerticalMargin;
constexpr static KDCoordinate k_horizontalMargin = Metric::TableCellHorizontalMargin;
private:

View File

@@ -0,0 +1,12 @@
#include <escher/bordered_cell.h>
#include <escher/palette.h>
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);
}

View File

@@ -6,7 +6,7 @@ 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) :
HighlightCell(),
BorderedCell(),
m_layout(layout)
{
}
@@ -169,9 +169,5 @@ void TableCell::drawRect(KDContext * ctx, KDRect rect) const {
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);
// 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);
BorderedCell::drawRect(ctx, rect);
}