From faf438e0c43eaa143fa43f1458a8482ba6b068ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 19 Sep 2016 15:27:12 +0200 Subject: [PATCH] [escher] define class table view cell Change-Id: I9291a9239a269cc4a85b87e9a94a00e8d8f72b03 --- escher/Makefile | 1 + escher/include/escher.h | 1 + escher/include/escher/table_view_cell.h | 24 +++++++++++++ escher/src/table_view_cell.cpp | 46 +++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 escher/include/escher/table_view_cell.h create mode 100644 escher/src/table_view_cell.cpp diff --git a/escher/Makefile b/escher/Makefile index 5ee7fc651..28dca3ca9 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -15,6 +15,7 @@ objs += $(addprefix escher/src/,\ tab_view_cell.o\ tab_view_controller.o\ table_view.o\ + table_view_cell.o\ text_field.o\ text_view.o\ tiled_view.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index d539f6cb0..56676962f 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/escher/include/escher/table_view_cell.h b/escher/include/escher/table_view_cell.h new file mode 100644 index 000000000..62c38203f --- /dev/null +++ b/escher/include/escher/table_view_cell.h @@ -0,0 +1,24 @@ +#ifndef ESCHER_TABLE_VIEW_CELL_H +#define ESCHER_TABLE_VIEW_CELL_H + +#include + +class TableViewCell : public ChildlessView { +public: + TableViewCell(); + void setMessage(const char * message); + bool isFocused() const; + void setFocused(bool focused); + void drawRect(KDContext * ctx, KDRect rect) const override; +private: + constexpr static KDColor k_separatorColor = KDColor(0xB4B7B9); + constexpr static KDColor k_tableBackgroundColor = KDColor(0xF0F3F5); + constexpr static KDColor k_focusedCellBackgroundColor = KDColor(0xBFD3EB); + constexpr static KDColor k_cellBackgroundColor = KDColor(0xFCFCFC); + constexpr static KDCoordinate k_margin = 20; + constexpr static KDCoordinate k_marginLabel = 5; + const char * m_message; + bool m_focused; +}; + +#endif diff --git a/escher/src/table_view_cell.cpp b/escher/src/table_view_cell.cpp new file mode 100644 index 000000000..342ce0eaf --- /dev/null +++ b/escher/src/table_view_cell.cpp @@ -0,0 +1,46 @@ +#include + +constexpr KDColor TableViewCell::k_separatorColor; +constexpr KDColor TableViewCell::k_tableBackgroundColor; +constexpr KDColor TableViewCell::k_focusedCellBackgroundColor; +constexpr KDColor TableViewCell::k_cellBackgroundColor; +constexpr KDCoordinate TableViewCell::k_margin; +constexpr KDCoordinate TableViewCell::k_marginLabel; + +TableViewCell::TableViewCell() : + ChildlessView(), + m_focused(false), + m_message(nullptr) +{ +} + +bool TableViewCell::isFocused() const { + return m_focused; +} + +void TableViewCell::setFocused(bool focused) { + m_focused = focused; + markRectAsDirty(bounds()); +} + +void TableViewCell::setMessage(const char * message) { + m_message = message; + markRectAsDirty(bounds()); +} + +void TableViewCell::drawRect(KDContext * ctx, KDRect rect) const { + + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + KDColor backgroundColor = (m_focused ? k_focusedCellBackgroundColor : k_cellBackgroundColor); + KDColor textColor = (m_focused ? KDColorWhite : KDColorBlack); + + ctx->fillRect(KDRect(k_margin+1, 1, width-2*k_margin-1, height-1), backgroundColor); + ctx->fillRect(KDRect(0,0,k_margin,height), k_tableBackgroundColor); + ctx->fillRect(KDRect(k_margin,0,width-2*k_margin,1), k_separatorColor); + ctx->fillRect(KDRect(k_margin,0,1,height), k_separatorColor); + ctx->fillRect(KDRect(width-k_margin,0,1,height), k_separatorColor); + ctx->fillRect(KDRect(width-k_margin+1,0,k_margin, height), k_tableBackgroundColor); + + ctx->drawString(m_message, KDPoint(k_margin+k_marginLabel, k_marginLabel), textColor, backgroundColor); +}