mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] Create a BorderedCell that draws the border around a cell and
use it in TableCell
This commit is contained in:
@@ -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 \
|
||||
|
||||
16
escher/include/escher/bordered_cell.h
Normal file
16
escher/include/escher/bordered_cell.h
Normal 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
|
||||
|
||||
@@ -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:
|
||||
|
||||
12
escher/src/bordered_cell.cpp
Normal file
12
escher/src/bordered_cell.cpp
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user