[apps/stats] Hide empty histogram cells

This commit is contained in:
Léa Saviot
2018-05-24 11:32:11 +02:00
parent 8997a7671e
commit 2b185261b7
7 changed files with 69 additions and 10 deletions

View File

@@ -21,6 +21,7 @@ app_objs += $(addprefix apps/shared/,\
function_expression_cell.o\
function_title_cell.o\
go_to_parameter_controller.o\
hideable_even_odd_editable_text_cell.o\
initialisation_parameter_controller.o\
interactive_curve_view_controller.o\
interactive_curve_view_range.o\

View File

@@ -0,0 +1,20 @@
#include "hideable_even_odd_editable_text_cell.h"
namespace Shared {
KDColor HideableEvenOddEditableTextCell::backgroundColor() const {
if (m_hide) {
return Palette::WallScreenDark;
}
return EvenOddEditableTextCell::backgroundColor();
}
void HideableEvenOddEditableTextCell::setHide(bool hide) {
if (m_hide != hide) {
m_hide = hide;
editableTextCell()->textField()->setBackgroundColor(backgroundColor());
reloadCell();
}
}
}

View File

@@ -0,0 +1,22 @@
#ifndef APPS_SHARED_HIDEABLE_EVEN_ODD_EDITABLE_TEXT_CELL_H
#define APPS_SHARED_HIDEABLE_EVEN_ODD_EDITABLE_TEXT_CELL_H
#include <escher/even_odd_editable_text_cell.h>
namespace Shared {
class HideableEvenOddEditableTextCell : public EvenOddEditableTextCell {
public:
HideableEvenOddEditableTextCell(Responder * parentResponder = nullptr, TextFieldDelegate * delegate = nullptr, char * draftTextBuffer = nullptr) :
EvenOddEditableTextCell(parentResponder, delegate, draftTextBuffer),
m_hide(false)
{}
KDColor backgroundColor() const override;
void setHide(bool hide);
private:
bool m_hide;
};
}
#endif

View File

@@ -79,12 +79,20 @@ int StoreController::typeAtLocation(int i, int j) {
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
// Handle empty cells
if (j > 0 && j > m_store->numberOfPairsOfSeries(seriesAtColumn(i)) && j < numberOfRows() - 1) {
((EvenOddCell *)cell)->setEven(j%2 == 0);
assert(cellAtLocationIsEditable(i, j));
((EvenOddEditableTextCell *)cell)->editableTextCell()->textField()->setText("");
if (j > 0 && j > m_store->numberOfPairsOfSeries(seriesAtColumn(i)) && j < numberOfRows()) {
HideableEvenOddEditableTextCell * myCell = static_cast<HideableEvenOddEditableTextCell *>(cell);
myCell->editableTextCell()->textField()->setText("");
if (cellShouldBeTransparent(i,j)) {
myCell->setHide(true);
} else {
myCell->setEven(j%2 == 0);
myCell->setHide(false);
}
return;
}
if (cellAtLocationIsEditable(i, j)) {
static_cast<HideableEvenOddEditableTextCell *>(cell)->setHide(false);
}
willDisplayCellAtLocationWithDisplayMode(cell, i, j, PrintFloat::Mode::Decimal);
}
@@ -161,7 +169,7 @@ int StoreController::maxNumberOfElements() const {
View * StoreController::loadView() {
SelectableTableView * tableView = (SelectableTableView*)EditableCellTableViewController::loadView();
for (int i = 0; i < k_maxNumberOfEditableCells; i++) {
m_editableCells[i] = new EvenOddEditableTextCell(tableView, this, m_draftTextBuffer);
m_editableCells[i] = new HideableEvenOddEditableTextCell(tableView, this, m_draftTextBuffer);
}
tableView->setMargins(k_margin);
return tableView;
@@ -175,4 +183,9 @@ void StoreController::unloadView(View * view) {
EditableCellTableViewController::unloadView(view);
}
bool StoreController::cellShouldBeTransparent(int i, int j) {
int seriesIndex = i/k_numberOfColumnsPerSeries;
return j > 1 + m_store->numberOfPairsOfSeries(seriesIndex);
}
}

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#include "float_pair_store.h"
#include "hideable_even_odd_editable_text_cell.h"
#include "store_parameter_controller.h"
#include "editable_cell_table_view_controller.h"
@@ -52,9 +53,11 @@ protected:
virtual HighlightCell * titleCells(int index) = 0;
char m_draftTextBuffer[TextField::maxBufferSize()];
int seriesAtColumn(int column) const { return column / k_numberOfColumnsPerSeries; }
EvenOddEditableTextCell * m_editableCells[k_maxNumberOfEditableCells];
HideableEvenOddEditableTextCell * m_editableCells[k_maxNumberOfEditableCells];
FloatPairStore * m_store;
StoreParameterController m_storeParameterController;
private:
bool cellShouldBeTransparent(int i, int j);
};
}

View File

@@ -17,13 +17,13 @@ StoreController::StoreController(Responder * parentResponder, Store * store, But
}
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
::StoreController::willDisplayCellAtLocation(cell, i, j);
Shared::StoreController::willDisplayCellAtLocation(cell, i, j);
if (cellAtLocationIsEditable(i, j)) {
return;
}
Shared::BufferFunctionTitleCell * mytitleCell = (Shared::BufferFunctionTitleCell *)cell;
bool valuesColumn = i%k_numberOfColumnsPerSeries == 0;
int seriesIndex = i/k_numberOfColumnsPerSeries;
bool valuesColumn = i%k_numberOfColumnsPerSeries == 0;
assert(seriesIndex >= 0 && seriesIndex < FloatPairStore::k_numberOfSeries);
if (valuesColumn) {
I18n::Message valuesMessages[] = {I18n::Message::Values1, I18n::Message::Values2, I18n::Message::Values3};

View File

@@ -9,8 +9,8 @@ EvenOddCell::EvenOddCell() :
void EvenOddCell::setEven(bool even) {
if (even != m_even) {
m_even = even;
reloadCell();
m_even = even;
reloadCell();
}
}