[apps/shared] Draw separators between series in Store data

This commit is contained in:
Léa Saviot
2018-05-24 15:12:20 +02:00
parent 70fa8d658e
commit 2717e8ebef
13 changed files with 131 additions and 11 deletions

View File

@@ -41,9 +41,11 @@ app_objs += $(addprefix apps/shared/,\
round_cursor_view.o\
simple_interactive_curve_view_controller.o\
expression_layout_field_delegate.o\
store_cell.o\
store_controller.o\
store_parameter_controller.o\
store_selectable_table_view.o\
store_title_cell.o\
sum_graph_controller.o\
tab_table_controller.o\
text_field_delegate.o\

View File

@@ -38,11 +38,15 @@ View * BufferFunctionTitleCell::subviewAtIndex(int index) {
}
void BufferFunctionTitleCell::layoutSubviews() {
m_bufferTextView.setFrame(bufferTextViewFrame());
}
KDRect BufferFunctionTitleCell::bufferTextViewFrame() const {
KDRect textFrame(0, k_colorIndicatorThickness, bounds().width(), bounds().height() - k_colorIndicatorThickness);
if (m_orientation == Orientation::VerticalIndicator){
textFrame = KDRect(k_colorIndicatorThickness, 0, bounds().width() - k_colorIndicatorThickness, bounds().height()-k_separatorThickness);
}
m_bufferTextView.setFrame(textFrame);
return textFrame;
}
}

View File

@@ -15,6 +15,9 @@ public:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
protected:
KDRect bufferTextViewFrame() const;
EvenOddBufferTextCell * bufferTextView() { return &m_bufferTextView; }
private:
EvenOddBufferTextCell m_bufferTextView;
};

View File

@@ -4,7 +4,7 @@ namespace Shared {
KDColor HideableEvenOddEditableTextCell::backgroundColor() const {
if (m_hide) {
return Palette::WallScreenDark;
return hideColor();
}
return EvenOddEditableTextCell::backgroundColor();
}

View File

@@ -2,6 +2,7 @@
#define APPS_SHARED_HIDEABLE_EVEN_ODD_EDITABLE_TEXT_CELL_H
#include <escher/even_odd_editable_text_cell.h>
#include <escher/palette.h>
namespace Shared {
@@ -12,6 +13,7 @@ public:
m_hide(false)
{}
KDColor backgroundColor() const override;
static KDColor hideColor() { return Palette::WallScreenDark; }
void setHide(bool hide);
private:
bool m_hide;

View File

@@ -0,0 +1,26 @@
#include "store_cell.h"
namespace Shared {
void StoreCell::setSeparatorRight(bool separator) {
if (m_separatorRight != separator) {
m_separatorRight = separator;
reloadCell();
}
}
void StoreCell::drawRect(KDContext * ctx, KDRect rect) const {
HideableEvenOddEditableTextCell::drawRect(ctx, rect);
// Draw the separator
if (m_separatorRight) {
ctx->fillRect(KDRect(bounds().width() - k_separatorThickness, 0, k_separatorThickness, bounds().height()), HideableEvenOddEditableTextCell::hideColor());
}
}
void StoreCell::layoutSubviews() {
KDRect boundsThis = bounds();
editableTextCell()->setFrame(KDRect(boundsThis.topLeft(), boundsThis.width() - k_separatorThickness, boundsThis.height()));
}
}

24
apps/shared/store_cell.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef APPS_SHARED_STORE_CELL_H
#define APPS_SHARED_STORE_CELL_H
#include "hideable_even_odd_editable_text_cell.h"
namespace Shared {
class StoreCell : public HideableEvenOddEditableTextCell {
public:
StoreCell(Responder * parentResponder = nullptr, TextFieldDelegate * delegate = nullptr, char * draftTextBuffer = nullptr) :
HideableEvenOddEditableTextCell(parentResponder, delegate, draftTextBuffer),
m_separatorRight(false)
{}
void setSeparatorRight(bool separator);
void drawRect(KDContext * ctx, KDRect rect) const override;
void layoutSubviews() override;
private:
static constexpr KDCoordinate k_separatorThickness = 2;
bool m_separatorRight;
};
}
#endif

View File

@@ -79,9 +79,14 @@ int StoreController::typeAtLocation(int i, int j) {
}
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
// Handle the separator
if (cellAtLocationIsEditable(i, j)) {
bool shoudHaveRightSeparator = i % FloatPairStore::k_numberOfColumnsPerSeries == 1;
static_cast<StoreCell *>(cell)->setSeparatorRight(shoudHaveRightSeparator);
}
// Handle empty cells
if (j > 0 && j > m_store->numberOfPairsOfSeries(seriesAtColumn(i)) && j < numberOfRows()) {
HideableEvenOddEditableTextCell * myCell = static_cast<HideableEvenOddEditableTextCell *>(cell);
StoreCell * myCell = static_cast<StoreCell *>(cell);
myCell->editableTextCell()->textField()->setText("");
if (cellShouldBeTransparent(i,j)) {
myCell->setHide(true);
@@ -92,7 +97,7 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int
return;
}
if (cellAtLocationIsEditable(i, j)) {
static_cast<HideableEvenOddEditableTextCell *>(cell)->setHide(false);
static_cast<StoreCell *>(cell)->setHide(false);
}
willDisplayCellAtLocationWithDisplayMode(cell, i, j, PrintFloat::Mode::Decimal);
}
@@ -173,7 +178,7 @@ View * StoreController::loadView() {
tableView->setVerticalCellOverlap(0);
for (int i = 0; i < k_maxNumberOfEditableCells; i++) {
m_editableCells[i] = new HideableEvenOddEditableTextCell(tableView, this, m_draftTextBuffer);
m_editableCells[i] = new StoreCell(tableView, this, m_draftTextBuffer);
}
tableView->setMargins(k_margin);
return tableView;

View File

@@ -4,7 +4,7 @@
#include <escher.h>
#include "editable_cell_table_view_controller.h"
#include "float_pair_store.h"
#include "hideable_even_odd_editable_text_cell.h"
#include "store_cell.h"
#include "store_parameter_controller.h"
namespace Shared {
@@ -51,7 +51,7 @@ protected:
virtual HighlightCell * titleCells(int index) = 0;
char m_draftTextBuffer[TextField::maxBufferSize()];
int seriesAtColumn(int column) const { return column / FloatPairStore::k_numberOfColumnsPerSeries; }
HideableEvenOddEditableTextCell * m_editableCells[k_maxNumberOfEditableCells];
StoreCell * m_editableCells[k_maxNumberOfEditableCells];
FloatPairStore * m_store;
StoreParameterController m_storeParameterController;
private:

View File

@@ -0,0 +1,29 @@
#include "store_title_cell.h"
#include "hideable_even_odd_editable_text_cell.h"
namespace Shared {
void StoreTitleCell::setSeparatorRight(bool separator) {
if (m_separatorRight != separator) {
m_separatorRight = separator;
reloadCell();
}
}
void StoreTitleCell::drawRect(KDContext * ctx, KDRect rect) const {
BufferFunctionTitleCell::drawRect(ctx, rect);
// Draw the separator
KDRect separatorRect(bounds().width() - k_separatorThickness, m_separatorRight ? 0 : k_colorIndicatorThickness, k_separatorThickness, bounds().height());
if (m_separatorRight) {
ctx->fillRect(separatorRect, HideableEvenOddEditableTextCell::hideColor());
} else {
ctx->fillRect(separatorRect, backgroundColor());
}
}
void StoreTitleCell::layoutSubviews() {
KDRect textFrame = bufferTextViewFrame();
bufferTextView()->setFrame(KDRect(textFrame.topLeft(), textFrame.width() - k_separatorThickness, textFrame.height() ));
}
}

View File

@@ -0,0 +1,24 @@
#ifndef SHARED_STORE_TITLE_CELL_H
#define SHARED_STORE_TITLE_CELL_H
#include "buffer_function_title_cell.h"
namespace Shared {
class StoreTitleCell : public BufferFunctionTitleCell {
public:
StoreTitleCell(Orientation orientation, KDText::FontSize size = KDText::FontSize::Large) :
BufferFunctionTitleCell(orientation, size),
m_separatorRight(false)
{}
void setSeparatorRight(bool separator);
void drawRect(KDContext * ctx, KDRect rect) const override;
void layoutSubviews() override;
private:
static constexpr KDCoordinate k_separatorThickness = 2;
bool m_separatorRight;
};
}
#endif

View File

@@ -21,7 +21,8 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int
if (cellAtLocationIsEditable(i, j)) {
return;
}
Shared::BufferFunctionTitleCell * mytitleCell = (Shared::BufferFunctionTitleCell *)cell;
Shared::StoreTitleCell * mytitleCell = static_cast<Shared::StoreTitleCell *>(cell);
mytitleCell->setSeparatorRight(i % Store::k_numberOfColumnsPerSeries == 1);
int seriesIndex = i/Store::k_numberOfColumnsPerSeries;
bool valuesColumn = i%Store::k_numberOfColumnsPerSeries == 0;
assert(seriesIndex >= 0 && seriesIndex < FloatPairStore::k_numberOfSeries);
@@ -55,7 +56,7 @@ bool StoreController::setDataAtLocation(double floatBody, int columnIndex, int r
View * StoreController::loadView() {
for (int i = 0; i < k_numberOfTitleCells; i++) {
m_titleCells[i] = new Shared::BufferFunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small);
m_titleCells[i] = new Shared::StoreTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small);
}
return Shared::StoreController::loadView();
}

View File

@@ -4,7 +4,7 @@
#include <escher.h>
#include "store.h"
#include "../shared/store_controller.h"
#include "../shared/buffer_function_title_cell.h"
#include "../shared/store_title_cell.h"
namespace Statistics {
@@ -17,7 +17,7 @@ private:
HighlightCell * titleCells(int index) override;
View * loadView() override;
void unloadView(View * view) override;
Shared::BufferFunctionTitleCell * m_titleCells[k_numberOfTitleCells];
Shared::StoreTitleCell * m_titleCells[k_numberOfTitleCells];
};
}