[escher] Make table view accept only table view cell

Change-Id: I393375d0887e692a85747198d5b42d26d207dc83
This commit is contained in:
Émilie Feral
2016-10-24 18:17:14 +02:00
parent 9ffb74fcca
commit f809d089d6
42 changed files with 132 additions and 121 deletions

View File

@@ -72,7 +72,7 @@ int HistoryController::numberOfRows() {
};
View * HistoryController::reusableCell(int index, int type) {
TableViewCell * HistoryController::reusableCell(int index, int type) {
assert(type == 0);
assert(index >= 0);
assert(index < k_maxNumberOfDisplayedRows);
@@ -84,7 +84,7 @@ int HistoryController::reusableCellCount(int type) {
return k_maxNumberOfDisplayedRows;
}
void HistoryController::willDisplayCellForIndex(View * cell, int index) {
void HistoryController::willDisplayCellForIndex(TableViewCell * cell, int index) {
HistoryViewCell * myCell = (HistoryViewCell *)cell;
myCell->setCalculation(m_calculationStore->calculationAtIndex(index));
}

View File

@@ -22,9 +22,9 @@ public:
void reload();
void setActiveCell(int index);
int numberOfRows() override;
View * reusableCell(int index, int type) override;
TableViewCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
void willDisplayCellForIndex(View * cell, int index) override;
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;

View File

@@ -6,7 +6,6 @@ namespace Calculation {
HistoryViewCell::HistoryViewCell() :
m_calculation(nullptr),
m_highlighted(false),
m_result(BufferTextView(1.0f, 0.5f))
{
}
@@ -39,16 +38,15 @@ void HistoryViewCell::setCalculation(Calculation * calculation) {
m_result.setText(buffer);
}
void HistoryViewCell::setHighlighted(bool highlight) {
m_highlighted = highlight;
KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
void HistoryViewCell::reloadCell() {
KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_result.setBackgroundColor(backgroundColor);
markRectAsDirty(bounds());
TableViewCell::reloadCell();
}
void HistoryViewCell::drawRect(KDContext * ctx, KDRect rect) const {
// Select background color
KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
ctx->fillRect(rect, backgroundColor);
// Draw the pretty print
if (m_calculation && m_calculation->layout() != nullptr) {

View File

@@ -6,19 +6,18 @@
namespace Calculation {
class HistoryViewCell : public View {
class HistoryViewCell : public TableViewCell {
public:
HistoryViewCell();
void reloadCell() override;
BufferTextView * result();
void setCalculation(Calculation * calculation);
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:
Calculation * m_calculation;
bool m_highlighted;
BufferTextView m_result;
};

View File

@@ -7,8 +7,7 @@ constexpr KDColor EvenOddCell::k_oddLineBackgroundColor;
constexpr KDColor EvenOddCell::k_selectedLineBackgroundColor;
EvenOddCell::EvenOddCell() :
View(),
m_highlighted(false),
TableViewCell(),
m_even(false)
{
}
@@ -18,23 +17,13 @@ void EvenOddCell::setEven(bool even) {
reloadCell();
}
void EvenOddCell::setHighlighted(bool highlight) {
m_highlighted = highlight;
reloadCell();
}
void EvenOddCell::reloadCell() {
markRectAsDirty(bounds());
}
KDColor EvenOddCell::backgroundColor() const {
// Select the background color according to the even line and the cursor selection
KDColor background = m_even ? EvenOddCell::k_evenLineBackgroundColor : EvenOddCell::k_oddLineBackgroundColor;
background = m_highlighted ? EvenOddCell::k_selectedLineBackgroundColor : background;
background = isHighlighted() ? EvenOddCell::k_selectedLineBackgroundColor : background;
return background;
}
void EvenOddCell::drawRect(KDContext * ctx, KDRect rect) const {
KDColor background = backgroundColor();
ctx->fillRect(rect, background);

View File

@@ -5,12 +5,10 @@
namespace Graph {
class EvenOddCell : public View {
class EvenOddCell : public TableViewCell {
public:
EvenOddCell();
void setEven(bool even);
void setHighlighted(bool highlight);
virtual void reloadCell();
KDColor backgroundColor() const;
void drawRect(KDContext * ctx, KDRect rect) const override;
@@ -19,7 +17,6 @@ public:
static constexpr KDColor k_selectedLineBackgroundColor = KDColor(0xC0D3EA);
private:
bool m_highlighted;
bool m_even;
};

View File

@@ -235,7 +235,7 @@ int ListController::typeAtLocation(int i, int j) {
return i;
}
View * ListController::reusableCell(int index, int type) {
TableViewCell * ListController::reusableCell(int index, int type) {
assert(index >= 0);
assert(index < k_maxNumberOfRows);
switch (type) {
@@ -260,7 +260,7 @@ int ListController::reusableCellCount(int type) {
return k_maxNumberOfRows;
}
void ListController::willDisplayCellAtLocation(View * cell, int i, int j) {
void ListController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) {
if (j < numberOfRows() - 1) {
if (i == 0) {
FunctionTitleCell * myFunctionCell = (FunctionTitleCell *)cell;

View File

@@ -23,14 +23,14 @@ public:
int numberOfRows() override;
int numberOfColumns() override;
void willDisplayCellAtLocation(View * cell, int i, int j) override;
void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override;
KDCoordinate columnWidth(int i) override;
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedWidthFromIndex(int i) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
View * reusableCell(int index, int type) override;
TableViewCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;
void configureFunction(Function * function);

View File

@@ -28,7 +28,7 @@ void ParameterController::didBecomeFirstResponder() {
setActiveCell(0);
}
void ParameterController::willDisplayCellForIndex(View * cell, int index) {
void ParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) {
if (cell == &m_enableCell) {
SwitchView * switchView = (SwitchView *)m_enableCell.contentView();
switchView->setState(m_function->isActive());
@@ -105,10 +105,10 @@ int ParameterController::numberOfRows() {
};
View * ParameterController::reusableCell(int index) {
TableViewCell * ParameterController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_totalNumberOfCell);
View * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell};
TableViewCell * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell};
return cells[index];
}

View File

@@ -20,9 +20,9 @@ public:
void setActiveCell(int index);
int numberOfRows() override;
KDCoordinate cellHeight() override;
View * reusableCell(int index) override;
TableViewCell * reusableCell(int index) override;
int reusableCellCount() override;
void willDisplayCellForIndex(View * cell, int index) override;
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
private:
bool handleEnter();
constexpr static int k_totalNumberOfCell = 3;

View File

@@ -85,10 +85,10 @@ int AbscissaParameterController::numberOfRows() {
return k_totalNumberOfCell;
};
View * AbscissaParameterController::reusableCell(int index) {
TableViewCell * AbscissaParameterController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_totalNumberOfCell);
View * cells[] = {&m_deleteColumn, &m_copyColumn, &m_setInterval};
TableViewCell * cells[] = {&m_deleteColumn, &m_copyColumn, &m_setInterval};
return cells[index];
}

View File

@@ -17,7 +17,7 @@ public:
void setActiveCell(int index);
int numberOfRows() override;
KDCoordinate cellHeight() override;
View * reusableCell(int index) override;
TableViewCell * reusableCell(int index) override;
int reusableCellCount() override;
private:
bool handleEnter();

View File

@@ -87,10 +87,10 @@ int DerivativeParameterController::numberOfRows() {
return k_totalNumberOfCell;
};
View * DerivativeParameterController::reusableCell(int index) {
TableViewCell * DerivativeParameterController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_totalNumberOfCell);
View * cells[] = {&m_hideColumn, &m_copyColumn};
TableViewCell * cells[] = {&m_hideColumn, &m_copyColumn};
return cells[index];
}

View File

@@ -17,7 +17,7 @@ public:
void setActiveCell(int index);
int numberOfRows() override;
KDCoordinate cellHeight() override;
View * reusableCell(int index) override;
TableViewCell * reusableCell(int index) override;
int reusableCellCount() override;
void setFunction(Function * function);

View File

@@ -86,10 +86,10 @@ int FunctionParameterController::numberOfRows() {
return k_totalNumberOfCell;
};
View * FunctionParameterController::reusableCell(int index) {
TableViewCell * FunctionParameterController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_totalNumberOfCell);
View * cells[] = {&m_displayDerivativeColumn, &m_copyColumn};
TableViewCell * cells[] = {&m_displayDerivativeColumn, &m_copyColumn};
return cells[index];
}
@@ -101,7 +101,7 @@ KDCoordinate FunctionParameterController::cellHeight() {
return 35;
}
void FunctionParameterController::willDisplayCellForIndex(View * cell, int index) {
void FunctionParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) {
if (cell == &m_displayDerivativeColumn) {
SwitchView * switchView = (SwitchView *)m_displayDerivativeColumn.contentView();
switchView->setState(m_function->displayDerivative());

View File

@@ -17,9 +17,9 @@ public:
void setActiveCell(int index);
int numberOfRows() override;
KDCoordinate cellHeight() override;
View * reusableCell(int index) override;
TableViewCell * reusableCell(int index) override;
int reusableCellCount() override;
void willDisplayCellForIndex(View * cell, int index) override;
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
void setFunction(Function * function);
private:

View File

@@ -341,7 +341,7 @@ int ValuesController::typeAtLocation(int i, int j) {
return 2;
}
View * ValuesController::reusableCell(int index, int type) {
TableViewCell * ValuesController::reusableCell(int index, int type) {
assert(index >= 0);
switch (type) {
case 0:
@@ -373,7 +373,7 @@ int ValuesController::reusableCellCount(int type) {
}
}
void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) {
void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) {
EvenOddCell * myCell = (EvenOddCell *)cell;
myCell->setEven(j%2 == 0);
// The cell is a title cell:

View File

@@ -35,14 +35,14 @@ public:
int numberOfRows() override;
int numberOfColumns() override;
void willDisplayCellAtLocation(View * cell, int i, int j) override;
void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override;
KDCoordinate columnWidth(int i) override;
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedWidthFromIndex(int i) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
View * reusableCell(int index, int type) override;
TableViewCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;

View File

@@ -36,7 +36,7 @@ int ValuesParameterController::activeCell() {
return m_activeCell;
}
void ValuesParameterController::willDisplayCellForIndex(View * cell, int index) {
void ValuesParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) {
TextListViewCell * myCell = (TextListViewCell *) cell;
char buffer[14];
switch (index) {
@@ -142,10 +142,10 @@ int ValuesParameterController::numberOfRows() {
return k_totalNumberOfCell;
};
View * ValuesParameterController::reusableCell(int index) {
TableViewCell * ValuesParameterController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_totalNumberOfCell);
View * cells[] = {&m_intervalStartCell, &m_intervalEndCell, &m_intervalStepCell};
TableViewCell * cells[] = {&m_intervalStartCell, &m_intervalEndCell, &m_intervalStepCell};
return cells[index];
}

View File

@@ -21,9 +21,9 @@ public:
void setActiveCell(int index);
int numberOfRows() override;
KDCoordinate cellHeight() override;
View * reusableCell(int index) override;
TableViewCell * reusableCell(int index) override;
int reusableCellCount() override;
void willDisplayCellForIndex(View * cell, int index) override;
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
private:
constexpr static int k_totalNumberOfCell = 3;
Interval * m_interval;

View File

@@ -4,9 +4,8 @@
namespace Home {
AppCell::AppCell() :
View(),
m_visible(true),
m_active(false)
TableViewCell(),
m_visible(true)
{
}
@@ -38,13 +37,9 @@ void AppCell::setVisible(bool visible) {
}
}
void AppCell::setActive(bool active) {
if (m_active != active) {
m_active = active;
m_nameView.setBackgroundColor(m_active ? KDColorRed : KDColorWhite);
markRectAsDirty(bounds());
}
void AppCell::reloadCell() {
TableViewCell::reloadCell();
m_nameView.setBackgroundColor(isHighlighted() ? KDColorRed : KDColorWhite);
}
}

View File

@@ -5,7 +5,7 @@
namespace Home {
class AppCell : public View {
class AppCell : public TableViewCell {
public:
AppCell();
@@ -14,14 +14,13 @@ public:
void layoutSubviews() override;
void setVisible(bool visible);
void setActive(bool active);
void reloadCell() override;
void setApp(::App * app);
private:
static constexpr KDCoordinate k_iconSize = 32;
ImageView m_iconView;
PointerTextView m_nameView;
bool m_visible;
bool m_active;
};
}

View File

@@ -69,7 +69,7 @@ KDCoordinate Controller::cellWidth() {
return 50;
}
View * Controller::reusableCell(int index) {
TableViewCell * Controller::reusableCell(int index) {
return &m_cells[index];
}
@@ -77,7 +77,7 @@ int Controller::reusableCellCount() {
return k_maxNumberOfCells;
}
void Controller::willDisplayCellAtLocation(View * cell, int i, int j) {
void Controller::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) {
AppCell * appCell = (AppCell *)cell;
int appIndex = (j*k_numberOfColumns+i)+1;
if (appIndex >= m_container->numberOfApps()) {
@@ -102,14 +102,14 @@ void Controller::setActiveIndex(int index) {
int j = m_activeIndex/k_numberOfColumns;
int i = m_activeIndex-j*k_numberOfColumns; // Avoid modulo
AppCell * previousCell = (AppCell *)m_tableView.cellAtLocation(i, j);
previousCell->setActive(false);
previousCell->setHighlighted(false);
m_activeIndex = index;
j = m_activeIndex/k_numberOfColumns;
i = m_activeIndex-j*k_numberOfColumns; // Avoid modulo
AppCell * nextCell = (AppCell *)m_tableView.cellAtLocation(i, j);
nextCell->setActive(true);
nextCell->setHighlighted(true);
}

View File

@@ -21,9 +21,9 @@ public:
virtual int numberOfColumns() override;
virtual KDCoordinate cellHeight() override;
virtual KDCoordinate cellWidth() override;
virtual View * reusableCell(int index) override;
virtual TableViewCell * reusableCell(int index) override;
virtual int reusableCellCount() override;
void willDisplayCellAtLocation(View * cell, int i, int j) override;
void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override;
private:
int numberOfIcons();
void setActiveIndex(int index);

View File

@@ -66,7 +66,7 @@ int Probability::LawController::numberOfRows() {
return k_totalNumberOfModels;
};
View * Probability::LawController::reusableCell(int index) {
TableViewCell * Probability::LawController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_maxNumberOfCells);
return &m_cells[index];
@@ -76,7 +76,7 @@ int Probability::LawController::reusableCellCount() {
return k_maxNumberOfCells;
}
void Probability::LawController::willDisplayCellForIndex(View * cell, int index) {
void Probability::LawController::willDisplayCellForIndex(TableViewCell * cell, int index) {
ListViewCell * myCell = (ListViewCell *)cell;
myCell->textView()->setText(m_messages[index]);
if (m_activeCell == index) {

View File

@@ -17,9 +17,9 @@ public:
void didBecomeFirstResponder() override;
int numberOfRows() override;
void willDisplayCellForIndex(View * cell, int index) override;
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
KDCoordinate cellHeight() override;
View * reusableCell(int index) override;
TableViewCell * reusableCell(int index) override;
int reusableCellCount() override;
private:
constexpr static int k_totalNumberOfModels = 7;

View File

@@ -28,6 +28,7 @@ objs += $(addprefix escher/src/,\
tab_view_cell.o\
tab_view_controller.o\
table_view.o\
table_view_cell.o\
list_view_cell.o\
table_view_data_source.o\
text_field.o\

View File

@@ -11,6 +11,7 @@
#include <escher/input_view_controller.h>
#include <escher/invocation.h>
#include <escher/list_view.h>
#include <escher/list_view_cell.h>
#include <escher/list_view_data_source.h>
#include <escher/metric.h>
#include <escher/palette.h>
@@ -29,7 +30,7 @@
#include <escher/text_view.h>
#include <escher/tab_view_controller.h>
#include <escher/table_view.h>
#include <escher/list_view_cell.h>
#include <escher/table_view_cell.h>
#include <escher/table_view_data_source.h>
#include <escher/tiled_view.h>
#include <escher/view.h>

View File

@@ -5,23 +5,20 @@
#include <escher/pointer_text_view.h>
#include <escher/palette.h>
#include <escher/metric.h>
#include <escher/table_view_cell.h>
class ListViewCell : public View {
class ListViewCell : public TableViewCell {
public:
ListViewCell(char * label = nullptr);
PointerTextView * textView();
virtual View * contentView() const;
bool isHighlighted() const;
void setHighlighted(bool highlight);
void drawRect(KDContext * ctx, KDRect rect) const override;
void reloadCell() override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
private:
constexpr static KDCoordinate k_separatorThickness = 1;
bool m_highlighted;
PointerTextView m_pointerTextView;
};

View File

@@ -2,16 +2,17 @@
#define ESCHER_LIST_VIEW_DATA_SOURCE_H
#include <escher/table_view_data_source.h>
#include <escher/table_view_cell.h>
class ListViewDataSource : public TableViewDataSource {
public:
KDCoordinate cellWidth();
KDCoordinate columnWidth(int i) override;
int numberOfColumns() override;
void willDisplayCellAtLocation(View * cell, int x, int y) override;
void willDisplayCellAtLocation(TableViewCell * cell, int x, int y) override;
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
KDCoordinate cumulatedWidthFromIndex(int i) override;
virtual void willDisplayCellForIndex(View * cell, int index);
virtual void willDisplayCellForIndex(TableViewCell * cell, int index);
};
#endif

View File

@@ -2,6 +2,7 @@
#define ESCHER_SIMPLE_LIST_VIEW_DATA_SOURCE_H
#include <escher/list_view_data_source.h>
#include <escher/table_view_cell.h>
class SimpleListViewDataSource : public ListViewDataSource {
public:
@@ -9,9 +10,9 @@ public:
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
virtual View * reusableCell(int index) = 0;
virtual TableViewCell * reusableCell(int index) = 0;
virtual int reusableCellCount() = 0;
View * reusableCell(int index, int type) override;
TableViewCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;
};

View File

@@ -2,6 +2,7 @@
#define ESCHER_SIMPLE_TABLE_VIEW_DATA_SOURCE_H
#include <escher/table_view.h>
#include <escher/table_view_cell.h>
class SimpleTableViewDataSource : public TableViewDataSource {
public:
@@ -13,9 +14,9 @@ public:
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
virtual View * reusableCell(int index) = 0;
virtual TableViewCell * reusableCell(int index) = 0;
virtual int reusableCellCount() = 0;
View * reusableCell(int index, int type) override;
TableViewCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;
};

View File

@@ -2,6 +2,7 @@
#define ESCHER_TABLE_VIEW_H
#include <escher/scroll_view.h>
#include <escher/table_view_cell.h>
#include <escher/table_view_data_source.h>
class TableView : public ScrollView {
@@ -10,7 +11,7 @@ public:
KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0);
void scrollToCell(int i, int j);
View * cellAtLocation(int i, int j);
TableViewCell * cellAtLocation(int i, int j);
void reloadData();
protected:
#if ESCHER_VIEW_LOGGING
@@ -22,7 +23,7 @@ private:
ContentView(TableView * tableView, TableViewDataSource * dataSource);
void scrollToCell(int i, int j) const;
View * cellAtLocation(int i, int j);
TableViewCell * cellAtLocation(int i, int j);
void resizeToFitContent();
protected:
#if ESCHER_VIEW_LOGGING

View File

@@ -0,0 +1,16 @@
#ifndef ESCHER_TABLE_VIEW_CELL_H
#define ESCHER_TABLE_VIEW_CELL_H
#include <escher/view.h>
class TableViewCell : public View {
public:
TableViewCell();
void setHighlighted(bool highlight);
bool isHighlighted() const;
virtual void reloadCell();
private:
bool m_highlighted;
};
#endif

View File

@@ -2,12 +2,13 @@
#define ESCHER_TABLE_VIEW_DATA_SOURCE_H
#include <escher/view.h>
#include <escher/table_view_cell.h>
class TableViewDataSource {
public:
virtual int numberOfRows() = 0;
virtual int numberOfColumns() = 0;
virtual void willDisplayCellAtLocation(View * cell, int i, int j);
virtual void willDisplayCellAtLocation(TableViewCell * cell, int i, int j);
virtual KDCoordinate columnWidth(int i) = 0;
virtual KDCoordinate rowHeight(int j) = 0;
/* return the number of pixels to include in offset to display the column i at
@@ -20,7 +21,7 @@ public:
* returns n-1. */
virtual int indexFromCumulatedWidth(KDCoordinate offsetX) = 0;
virtual int indexFromCumulatedHeight(KDCoordinate offsetY) = 0;
virtual View * reusableCell(int index, int type) = 0;
virtual TableViewCell * reusableCell(int index, int type) = 0;
virtual int reusableCellCount(int type) = 0;
virtual int typeAtLocation(int i, int j) = 0;
};

View File

@@ -4,8 +4,7 @@
constexpr KDCoordinate ListViewCell::k_separatorThickness;
ListViewCell::ListViewCell(char * label) :
View(),
m_highlighted(false),
TableViewCell(),
m_pointerTextView(PointerTextView(label, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor))
{
}
@@ -36,6 +35,12 @@ void ListViewCell::layoutSubviews() {
}
}
void ListViewCell::reloadCell() {
TableViewCell::reloadCell();
KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_pointerTextView.setBackgroundColor(backgroundColor);
}
PointerTextView * ListViewCell::textView() {
return &m_pointerTextView;
}
@@ -44,21 +49,10 @@ View * ListViewCell::contentView() const {
return nullptr;
}
bool ListViewCell::isHighlighted() const {
return m_highlighted;
}
void ListViewCell::setHighlighted(bool highlight) {
m_highlighted = highlight;
KDColor backgroundColor = highlight? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_pointerTextView.setBackgroundColor(backgroundColor);
markRectAsDirty(bounds());
}
void ListViewCell::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDColor backgroundColor = (m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor);
KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
ctx->fillRect(KDRect(k_separatorThickness, k_separatorThickness, width-2*k_separatorThickness, height-k_separatorThickness), backgroundColor);
ctx->fillRect(KDRect(0, 0, width, k_separatorThickness), Palette::LineColor);

View File

@@ -12,11 +12,11 @@ int ListViewDataSource::numberOfColumns() {
return 1;
}
void ListViewDataSource::willDisplayCellAtLocation(View * cell, int x, int y) {
void ListViewDataSource::willDisplayCellAtLocation(TableViewCell * cell, int x, int y) {
willDisplayCellForIndex(cell, y);
}
void ListViewDataSource::willDisplayCellForIndex(View * cell, int index) {
void ListViewDataSource::willDisplayCellForIndex(TableViewCell * cell, int index) {
}
KDCoordinate ListViewDataSource::cumulatedWidthFromIndex(int i) {

View File

@@ -17,7 +17,7 @@ int SimpleListViewDataSource::indexFromCumulatedHeight(KDCoordinate offsetY) {
return (offsetY - 1) / height;
}
View * SimpleListViewDataSource::reusableCell(int index, int type) {
TableViewCell * SimpleListViewDataSource::reusableCell(int index, int type) {
assert(type == 0);
return reusableCell(index);
}

View File

@@ -37,7 +37,7 @@ int SimpleTableViewDataSource::indexFromCumulatedHeight(KDCoordinate offsetY) {
return (offsetY - 1) / height;
}
View * SimpleTableViewDataSource::reusableCell(int index, int type) {
TableViewCell * SimpleTableViewDataSource::reusableCell(int index, int type) {
assert(type == 0);
return reusableCell(index);
}

View File

@@ -20,7 +20,7 @@ void TableView::scrollToCell(int i, int j) {
m_contentView.scrollToCell(i, j);
}
View * TableView::cellAtLocation(int i, int j) {
TableViewCell * TableView::cellAtLocation(int i, int j) {
return m_contentView.cellAtLocation(i, j);
}
@@ -112,7 +112,7 @@ int TableView::ContentView::typeIndexFromSubviewIndex(int index, int type) const
return typeIndex;
}
View * TableView::ContentView::cellAtLocation(int x, int y) {
TableViewCell * TableView::ContentView::cellAtLocation(int x, int y) {
int relativeX = x-columnsScrollingOffset();
int relativeY = y-rowsScrollingOffset();
int type = m_dataSource->typeAtLocation(x, y);
@@ -168,7 +168,7 @@ void TableView::ContentView::layoutSubviews() {
cell->setFrame(cellFrame);
m_dataSource->willDisplayCellAtLocation(cell, i, j);
m_dataSource->willDisplayCellAtLocation((TableViewCell *)cell, i, j);
}
}

View File

@@ -0,0 +1,20 @@
#include <escher/table_view_cell.h>
TableViewCell::TableViewCell() :
View(),
m_highlighted(false)
{
}
void TableViewCell::setHighlighted(bool highlight) {
m_highlighted = highlight;
reloadCell();
}
bool TableViewCell::isHighlighted() const {
return m_highlighted;
}
void TableViewCell::reloadCell() {
markRectAsDirty(bounds());
}

View File

@@ -1,4 +1,4 @@
#include <escher/table_view_data_source.h>
void TableViewDataSource::willDisplayCellAtLocation(View * cell, int i, int j) {
void TableViewDataSource::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) {
}