mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] Create a class Bordered instead of BorderedCell: this enable
non-cell view to use it as well
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#ifndef CALCULATION_ADDITIONAL_OUTPUTS_ILLUSTRATION_CELL_H
|
||||
#define CALCULATION_ADDITIONAL_OUTPUTS_ILLUSTRATION_CELL_H
|
||||
|
||||
#include <escher/bordered_cell.h>
|
||||
#include <escher/bordered.h>
|
||||
#include <escher/highlight_cell.h>
|
||||
|
||||
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(); }
|
||||
|
||||
@@ -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 \
|
||||
|
||||
16
escher/include/escher/bordered.h
Normal file
16
escher/include/escher/bordered.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef ESCHER_BORDERED_H
|
||||
#define ESCHER_BORDERED_H
|
||||
|
||||
#include <escher/metric.h>
|
||||
#include <kandinsky/context.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#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,9 +1,10 @@
|
||||
#ifndef ESCHER_TABLE_CELL_H
|
||||
#define ESCHER_TABLE_CELL_H
|
||||
|
||||
#include <escher/bordered_cell.h>
|
||||
#include <escher/bordered.h>
|
||||
#include <escher/highlight_cell.h>
|
||||
|
||||
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.
|
||||
|
||||
15
escher/src/bordered.cpp
Normal file
15
escher/src/bordered.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <escher/bordered.h>
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#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,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user