[apps/graph] Hideable cells in values controller

This commit is contained in:
Léa Saviot
2019-09-05 10:24:40 +02:00
parent aa1d1165e8
commit af3d1456e0
7 changed files with 81 additions and 11 deletions

View File

@@ -32,8 +32,36 @@ ValuesController::ValuesController(Responder * parentResponder, InputEventHandle
}
void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
Shared::ValuesController::willDisplayCellAtLocation(cell, i, j);
// Handle hidden cells
int typeAtLoc = typeAtLocation(i,j);
if (typeAtLoc == k_editableValueCellType) {
StoreCell * storeCell = (StoreCell *)cell;
storeCell->setSeparatorLeft(i > 0);
}
const int numberOfElementsInCol = numberOfElementsInColumn(i);
if (j == numberOfElementsInCol+1) {
if (typeAtLoc == k_notEditableValueCellType) {
Shared::HideableEvenOddBufferTextCell * myCell = static_cast<Shared::HideableEvenOddBufferTextCell *>(cell);
myCell->setText("");
} else if (typeAtLoc == k_editableValueCellType) {
StoreCell * myCell = static_cast<StoreCell *>(cell);
myCell->editableTextCell()->textField()->setText("");
}
return;
}
if (j > numberOfElementsInCol + 1) {
if (typeAtLoc == k_notEditableValueCellType) {
Shared::HideableEvenOddBufferTextCell * myCell = static_cast<Shared::HideableEvenOddBufferTextCell *>(cell);
myCell->setHide(true);
} else if (typeAtLoc == k_editableValueCellType) {
StoreCell * myCell = static_cast<StoreCell *>(cell);
myCell->setHide(true);
}
return;
}
Shared::ValuesController::willDisplayCellAtLocation(cell, i, j);
if (typeAtLoc == k_abscissaTitleCellType) {
AbscissaTitleCell * myTitleCell = (AbscissaTitleCell *)cell;
Ion::Storage::Record record = recordAtColumn(i+1);
@@ -58,10 +86,7 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in
myFunctionCell->setColor(function->color());
return;
}
if (typeAtLoc == k_editableValueCellType) {
StoreCell * storeCell = (StoreCell *)cell;
storeCell->setSeparatorLeft(i > 0);
}
}
int ValuesController::typeAtLocation(int i, int j) {

View File

@@ -3,6 +3,7 @@
#include "../cartesian_function_store.h"
#include "../../shared/buffer_function_title_cell.h"
#include "../../shared/hideable_even_odd_buffer_text_cell.h"
#include "../../shared/values_controller.h"
#include "../../shared/interval_parameter_controller.h"
#include "../../shared/store_cell.h"
@@ -54,7 +55,7 @@ private:
int m_numberOfColumnsForType[Shared::CartesianFunction::k_numberOfPlotTypes];
Shared::BufferFunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions];
EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells];
Shared::HideableEvenOddBufferTextCell m_floatCells[k_maxNumberOfCells];
AbscissaTitleCell m_abscissaTitleCells[Shared::CartesianFunction::k_numberOfPlotTypes];
Shared::StoreCell m_abscissaCells[k_maxNumberOfAbscissaCells];
FunctionParameterController m_functionParameterController;

View File

@@ -37,6 +37,7 @@ app_shared_src = $(addprefix apps/shared/,\
function_store.cpp \
function_title_cell.cpp \
go_to_parameter_controller.cpp \
hideable_even_odd_buffer_text_cell.cpp \
hideable_even_odd_cell.cpp \
hideable_even_odd_editable_text_cell.cpp \
initialisation_parameter_controller.cpp \

View File

@@ -0,0 +1,20 @@
#include "hideable_even_odd_buffer_text_cell.h"
namespace Shared {
KDColor HideableEvenOddBufferTextCell::backgroundColor() const {
if (hidden()) {
return hideColor();
}
return EvenOddBufferTextCell::backgroundColor();
}
void HideableEvenOddBufferTextCell::setHide(bool hide) {
if (hidden() != hide) {
Hideable::setHide(hide);
m_bufferTextView.setBackgroundColor(backgroundColor());
reloadCell();
}
}
}

View File

@@ -0,0 +1,22 @@
#ifndef APPS_SHARED_HIDEABLE_EVEN_ODD_BUFFER_TEXT_CELL_H
#define APPS_SHARED_HIDEABLE_EVEN_ODD_BUFFER_TEXT_CELL_H
#include <escher/even_odd_buffer_text_cell.h>
#include <escher/palette.h>
#include "hideable.h"
namespace Shared {
class HideableEvenOddBufferTextCell : public EvenOddBufferTextCell, public Hideable {
public:
HideableEvenOddBufferTextCell() :
EvenOddBufferTextCell(),
Hideable()
{}
KDColor backgroundColor() const override;
void setHide(bool hide) override;
};
}
#endif

View File

@@ -15,11 +15,12 @@ int Interval::numberOfElements() {
}
void Interval::deleteElementAtIndex(int index) {
m_numberOfElements--;
for (int k = index; k < m_numberOfElements; k++) {
assert(!m_needCompute);
assert(m_numberOfElements > 0);
for (int k = index; k < m_numberOfElements-1; k++) {
m_intervalBuffer[k] = m_intervalBuffer[k+1];
}
m_intervalBuffer[m_numberOfElements] = 0.0f;
m_numberOfElements--;
}
double Interval::element(int i) {
@@ -70,7 +71,7 @@ void Interval::computeElements() {
if (!m_needCompute) {
return;
}
if ( m_start > m_end) {
if (m_start > m_end) {
m_numberOfElements = 0;
} else {
m_numberOfElements = m_step > 0 ? 1 + (m_end - m_start)/m_step : k_maxNumberOfElements;

View File

@@ -55,6 +55,7 @@ protected:
virtual void updateNumberOfColumns();
virtual FunctionStore * functionStore() const;
virtual Ion::Storage::Record recordAtColumn(int i);
int numberOfElementsInColumn(int columnIndex) override;
int m_numberOfColumns;
bool m_numberOfColumnsNeedUpdate;
private:
@@ -62,7 +63,6 @@ private:
SelectableTableView * selectableTableView() override { return &m_selectableTableView; }
bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override;
double dataAtLocation(int columnIndex, int rowIndex) override;
int numberOfElementsInColumn(int columnIndex) override;
virtual Interval * intervalAtColumn(int columnIndex) = 0;
int maxNumberOfElements() const override {
return Interval::k_maxNumberOfElements;