[apps/calculation] Moved input buffer to snapshot

The cacheBuffer from EditExpressionController has been moved in the
snapshot, to act as a zone where layout information can be kept while
the app is inactive.

Change-Id: If9206abf77f37d6b984826e5f09658848381a75f
This commit is contained in:
Gabriel Ozouf
2020-06-11 11:03:56 +02:00
committed by Émilie Feral
parent 3db1cad18b
commit 0927ffca29
4 changed files with 23 additions and 6 deletions

View File

@@ -27,6 +27,8 @@ App * App::Snapshot::unpack(Container * container) {
void App::Snapshot::reset() {
m_calculationStore.deleteAll();
m_cacheBuffer[0] = 0;
m_cacheBufferInformation = 0;
}
App::Descriptor * App::Snapshot::descriptor() {
@@ -41,7 +43,7 @@ App::Snapshot::Snapshot() : m_calculationStore(m_calculationBuffer, k_calculatio
App::App(Snapshot * snapshot) :
ExpressionFieldDelegateApp(snapshot, &m_editExpressionController),
m_historyController(&m_editExpressionController, snapshot->calculationStore()),
m_editExpressionController(&m_modalViewController, this, &m_historyController, snapshot->calculationStore())
m_editExpressionController(&m_modalViewController, this, snapshot->cacheBuffer(), snapshot->cacheBufferInformationAddress(), &m_historyController, snapshot->calculationStore())
{
}

View File

@@ -24,11 +24,15 @@ public:
void reset() override;
Descriptor * descriptor() override;
CalculationStore * calculationStore() { return &m_calculationStore; }
char * cacheBuffer() { return m_cacheBuffer; }
size_t * cacheBufferInformationAddress() { return &m_cacheBufferInformation; }
private:
CalculationStore m_calculationStore;
// Set the size of the buffer needed to store the calculations
static constexpr int k_calculationBufferSize = 10 * (sizeof(Calculation) + Calculation::k_numberOfExpressions * Constant::MaxSerializedExpressionSize + sizeof(Calculation *));
char m_calculationBuffer[k_calculationBufferSize];
char m_cacheBuffer[EditExpressionController::k_cacheBufferSize];
size_t m_cacheBufferInformation;
};
static App * app() {
return static_cast<App *>(Container::activeApp());

View File

@@ -38,13 +38,14 @@ void EditExpressionController::ContentView::reload() {
markRectAsDirty(bounds());
}
EditExpressionController::EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, HistoryController * historyController, CalculationStore * calculationStore) :
EditExpressionController::EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, char * cacheBuffer, size_t * cacheBufferInformation, HistoryController * historyController, CalculationStore * calculationStore) :
ViewController(parentResponder),
m_cacheBuffer(cacheBuffer),
m_cacheBufferInformation(cacheBufferInformation),
m_historyController(historyController),
m_calculationStore(calculationStore),
m_contentView(this, static_cast<CalculationSelectableTableView *>(m_historyController->view()), inputEventHandlerDelegate, this, this)
{
m_cacheBuffer[0] = 0;
}
void EditExpressionController::insertTextBody(const char * text) {

View File

@@ -14,7 +14,17 @@ namespace Calculation {
/* TODO: implement a split view */
class EditExpressionController : public ViewController, public Shared::TextFieldDelegate, public Shared::LayoutFieldDelegate {
public:
EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, HistoryController * historyController, CalculationStore * calculationStore);
EditExpressionController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, char * cacheBuffer, size_t * cacheBufferInformation, HistoryController * historyController, CalculationStore * calculationStore);
/* k_layoutBufferMaxSize dictates the size under which the expression being
* edited can be remembered when the user leaves Calculation. */
static constexpr int k_layoutBufferMaxSize = 1024;
/* k_cacheBufferSize is the size of the array to which m_cacheBuffer points.
* It is used both as a way to buffer expression when pushing them the
* CalculationStore, and as a storage for the current input when leaving the
* application. */
static constexpr int k_cacheBufferSize = (k_layoutBufferMaxSize < Constant::MaxSerializedExpressionSize) ? Constant::MaxSerializedExpressionSize : k_layoutBufferMaxSize;
View * view() override { return &m_contentView; }
void didBecomeFirstResponder() override;
void viewWillAppear() override;
@@ -49,8 +59,8 @@ private:
bool inputViewDidReceiveEvent(Ion::Events::Event event, bool shouldDuplicateLastCalculation);
bool inputViewDidFinishEditing(const char * text, Poincare::Layout layoutR);
bool inputViewDidAbortEditing(const char * text);
static constexpr int k_cacheBufferSize = Constant::MaxSerializedExpressionSize;
char m_cacheBuffer[k_cacheBufferSize];
char * m_cacheBuffer;
size_t * m_cacheBufferInformation;
HistoryController * m_historyController;
CalculationStore * m_calculationStore;
ContentView m_contentView;