mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] define class table view cell
Change-Id: I9291a9239a269cc4a85b87e9a94a00e8d8f72b03
This commit is contained in:
@@ -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\
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <escher/text_view.h>
|
||||
#include <escher/tab_view_controller.h>
|
||||
#include <escher/table_view.h>
|
||||
#include <escher/table_view_cell.h>
|
||||
#include <escher/tiled_view.h>
|
||||
#include <escher/view.h>
|
||||
#include <escher/view_controller.h>
|
||||
|
||||
24
escher/include/escher/table_view_cell.h
Normal file
24
escher/include/escher/table_view_cell.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef ESCHER_TABLE_VIEW_CELL_H
|
||||
#define ESCHER_TABLE_VIEW_CELL_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
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
|
||||
46
escher/src/table_view_cell.cpp
Normal file
46
escher/src/table_view_cell.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <escher/table_view_cell.h>
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user