mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] change structure of table view cell and define label view
Change-Id: Iaeb3f567c4e1be6dfea3076ee7465c21e5ad98e9
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
#include "parameter_controller.h"
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
static const char * sMessages[] = {
|
||||
"Couleur de la fonction",
|
||||
"Activer/Desactiver",
|
||||
"Supprimer la fonction"
|
||||
};
|
||||
|
||||
ParameterController::ParameterController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_colorCell(TableViewCell("Couleur de la fonction")),
|
||||
m_enableCell(TableViewCell("Activer/Desactiver")),
|
||||
m_deleteCell(TableViewCell("Supprimer la fonction")),
|
||||
m_tableView(TableView(this)),
|
||||
m_activeCell(0)
|
||||
{
|
||||
m_messages = sMessages;
|
||||
}
|
||||
|
||||
const char * ParameterController::title() const {
|
||||
@@ -33,12 +28,12 @@ void ParameterController::setActiveCell(int index) {
|
||||
return;
|
||||
}
|
||||
TableViewCell * previousCell = (TableViewCell *)(m_tableView.cellAtIndex(m_activeCell));
|
||||
previousCell->setFocused(false);
|
||||
previousCell->setHighlighted(false);
|
||||
|
||||
m_activeCell = index;
|
||||
m_tableView.scrollToRow(index);
|
||||
TableViewCell * cell = (TableViewCell *)(m_tableView.cellAtIndex(index));
|
||||
cell->setFocused(true);
|
||||
cell->setHighlighted(true);
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +51,7 @@ bool ParameterController::handleEvent(Ion::Events::Event event) {
|
||||
setActiveCell(m_activeCell-1);
|
||||
return true;
|
||||
case Ion::Events::Event::ENTER:
|
||||
switch (m_activeCell) {
|
||||
/*switch (m_activeCell) {
|
||||
case 0:
|
||||
return true;
|
||||
case 1:
|
||||
@@ -64,7 +59,7 @@ bool ParameterController::handleEvent(Ion::Events::Event event) {
|
||||
return true;
|
||||
case 2:
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -78,18 +73,14 @@ int ParameterController::numberOfCells() {
|
||||
View * ParameterController::reusableCell(int index) {
|
||||
assert(index >= 0);
|
||||
assert(index < k_totalNumberOfCell);
|
||||
return &m_cells[index];
|
||||
View * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell};
|
||||
return cells[index];
|
||||
}
|
||||
|
||||
int ParameterController::reusableCellCount() {
|
||||
return k_totalNumberOfCell;
|
||||
}
|
||||
|
||||
void ParameterController::willDisplayCellForIndex(View * cell, int index) {
|
||||
TableViewCell * myCell = (TableViewCell *)cell;
|
||||
myCell->setMessage(m_messages[index]);
|
||||
}
|
||||
|
||||
KDCoordinate ParameterController::cellHeight() {
|
||||
return 35;
|
||||
}
|
||||
|
||||
@@ -17,18 +17,16 @@ public:
|
||||
|
||||
void setActiveCell(int index);
|
||||
int numberOfCells() override;
|
||||
void willDisplayCellForIndex(View * cell, int index) override;
|
||||
KDCoordinate cellHeight() override;
|
||||
View * reusableCell(int index) override;
|
||||
int reusableCellCount() override;
|
||||
|
||||
private:
|
||||
constexpr static int k_totalNumberOfCell = 3;
|
||||
// !!! CAUTION: The order here is important
|
||||
// The cells should be initialized *before* the tableview!
|
||||
TableViewCell m_cells[k_totalNumberOfCell];
|
||||
TableViewCell m_colorCell;
|
||||
TableViewCell m_enableCell;
|
||||
TableViewCell m_deleteCell;
|
||||
TableView m_tableView;
|
||||
const char ** m_messages;
|
||||
int m_activeCell;
|
||||
Graph::Function * m_function;
|
||||
Graph::FunctionStore * m_functionStore;
|
||||
|
||||
@@ -5,6 +5,7 @@ objs += $(addprefix escher/src/,\
|
||||
childless_view.o\
|
||||
container.o\
|
||||
invocation.o\
|
||||
label_view.o\
|
||||
palette.o\
|
||||
responder.o\
|
||||
scroll_view.o\
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <escher/app.h>
|
||||
#include <escher/container.h>
|
||||
#include <escher/invocation.h>
|
||||
#include <escher/label_view.h>
|
||||
#include <escher/palette.h>
|
||||
#include <escher/responder.h>
|
||||
#include <escher/scroll_view.h>
|
||||
|
||||
20
escher/include/escher/label_view.h
Normal file
20
escher/include/escher/label_view.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef ESCHER_LABEL_VIEW_H
|
||||
#define ESCHER_LABEL_VIEW_H
|
||||
|
||||
#include <escher/childless_view.h>
|
||||
#include <kandinsky/color.h>
|
||||
|
||||
class LabelView : public ChildlessView {
|
||||
|
||||
public:
|
||||
LabelView(const char * label, KDColor backgroundColor = KDColorWhite, KDColor textColor = KDColorBlack);
|
||||
void setBackgroundColor(KDColor backgroundColor);
|
||||
void setTextColor(KDColor textColor);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
const char * m_label;
|
||||
KDColor m_backgroundColor;
|
||||
KDColor m_textColor;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,7 @@
|
||||
class TableViewDataSource {
|
||||
public:
|
||||
virtual int numberOfCells() = 0;
|
||||
virtual void willDisplayCellForIndex(View * cell, int index) = 0;
|
||||
virtual void willDisplayCellForIndex(View * cell, int index);
|
||||
virtual KDCoordinate cellHeight() = 0;
|
||||
virtual View * reusableCell(int index) = 0;
|
||||
virtual int reusableCellCount() = 0;
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
#ifndef ESCHER_TABLE_VIEW_CELL_H
|
||||
#define ESCHER_TABLE_VIEW_CELL_H
|
||||
|
||||
#include <escher.h>
|
||||
#include <escher/view.h>
|
||||
#include <escher/label_view.h>
|
||||
#include <escher/palette.h>
|
||||
|
||||
class TableViewCell : public ChildlessView {
|
||||
|
||||
class TableViewCell : public View {
|
||||
public:
|
||||
TableViewCell();
|
||||
void setMessage(const char * message);
|
||||
bool isFocused() const;
|
||||
void setFocused(bool focused);
|
||||
TableViewCell(char * label);
|
||||
LabelView * labelView();
|
||||
virtual View * contentView() const;
|
||||
bool isHighlighted() const;
|
||||
void setHighlighted(bool highlight);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() 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;
|
||||
bool m_highlighted;
|
||||
LabelView m_labelView;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
22
escher/src/label_view.cpp
Normal file
22
escher/src/label_view.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <escher/label_view.h>
|
||||
#include <escher/table_view_cell.h>
|
||||
|
||||
LabelView::LabelView(const char * label, KDColor backgroundColor, KDColor textColor) :
|
||||
ChildlessView(),
|
||||
m_label(label),
|
||||
m_backgroundColor(backgroundColor),
|
||||
m_textColor(textColor)
|
||||
{
|
||||
}
|
||||
|
||||
void LabelView::setBackgroundColor(KDColor backgroundColor) {
|
||||
m_backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
void LabelView::setTextColor(KDColor textColor) {
|
||||
m_textColor = textColor;
|
||||
}
|
||||
|
||||
void LabelView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->drawString(m_label, KDPointZero, m_textColor, m_backgroundColor);
|
||||
}
|
||||
@@ -5,6 +5,10 @@ extern "C" {
|
||||
|
||||
#define MIN(x,y) ((x)<(y) ? (x) : (y))
|
||||
|
||||
void TableViewDataSource::willDisplayCellForIndex(View * cell, int index) {
|
||||
}
|
||||
|
||||
|
||||
TableView::TableView(TableViewDataSource * dataSource) :
|
||||
ScrollView(&m_contentView),
|
||||
m_contentView(TableView::ContentView(this, dataSource))
|
||||
|
||||
@@ -1,46 +1,69 @@
|
||||
#include <escher/table_view_cell.h>
|
||||
#include <assert.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)
|
||||
TableViewCell::TableViewCell(char * label) :
|
||||
View(),
|
||||
m_highlighted(false),
|
||||
m_labelView(LabelView(label, Palette::CellBackgroundColor, KDColorBlack))
|
||||
{
|
||||
}
|
||||
|
||||
bool TableViewCell::isFocused() const {
|
||||
return m_focused;
|
||||
int TableViewCell::numberOfSubviews() const {
|
||||
if (contentView() == nullptr) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
void TableViewCell::setFocused(bool focused) {
|
||||
m_focused = focused;
|
||||
markRectAsDirty(bounds());
|
||||
View * TableViewCell::subviewAtIndex(int index) {
|
||||
if (index == 0) {
|
||||
return &m_labelView;
|
||||
}
|
||||
assert(numberOfSubviews() == 2 && index == 1);
|
||||
return contentView();
|
||||
}
|
||||
|
||||
void TableViewCell::setMessage(const char * message) {
|
||||
m_message = message;
|
||||
void TableViewCell::layoutSubviews() {
|
||||
KDCoordinate width = bounds().width();
|
||||
KDCoordinate height = bounds().height();
|
||||
m_labelView.setFrame(KDRect(k_margin + k_marginLabel, k_marginLabel, 3*width/4, height));
|
||||
View * content = contentView();
|
||||
if (content) {
|
||||
content->setFrame(KDRect(k_margin + k_marginLabel + 3*width/4, k_marginLabel, width/4-k_margin, height-k_marginLabel));
|
||||
}
|
||||
}
|
||||
|
||||
LabelView * TableViewCell::labelView() {
|
||||
return &m_labelView;
|
||||
}
|
||||
|
||||
View * TableViewCell::contentView() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool TableViewCell::isHighlighted() const {
|
||||
return m_highlighted;
|
||||
}
|
||||
|
||||
void TableViewCell::setHighlighted(bool highlight) {
|
||||
m_highlighted = highlight;
|
||||
KDColor backgroundColor = highlight? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
|
||||
m_labelView.setBackgroundColor(backgroundColor);
|
||||
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);
|
||||
KDColor backgroundColor = (m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor);
|
||||
|
||||
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);
|
||||
ctx->fillRect(KDRect(0,0,k_margin,height), Palette::BackgroundColor);
|
||||
ctx->fillRect(KDRect(k_margin,0,width-2*k_margin,1), Palette::LineColor);
|
||||
ctx->fillRect(KDRect(k_margin,0,1,height), Palette::LineColor);
|
||||
ctx->fillRect(KDRect(width-k_margin,0,1,height), Palette::LineColor);
|
||||
ctx->fillRect(KDRect(width-k_margin+1,0,k_margin, height), Palette::BackgroundColor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user