From dbf1597ef3e05e08f9f9799e34b35a62be65ae72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 29 May 2018 10:02:11 +0200 Subject: [PATCH] [apps/stats] Display or not the formula input view --- .../buffer_text_view_with_text_field.cpp | 5 +++- .../shared/buffer_text_view_with_text_field.h | 3 +- apps/shared/store_controller.cpp | 29 +++++++++++++++---- apps/shared/store_controller.h | 7 +++-- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/apps/shared/buffer_text_view_with_text_field.cpp b/apps/shared/buffer_text_view_with_text_field.cpp index 7a0138d8c..112ca1216 100644 --- a/apps/shared/buffer_text_view_with_text_field.cpp +++ b/apps/shared/buffer_text_view_with_text_field.cpp @@ -9,6 +9,7 @@ BufferTextViewWithTextField::BufferTextViewWithTextField(Responder * parentRespo m_textField(this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, delegate, false, size, 0.0f, 0.5f), m_textFieldBuffer{} { + m_bufferTextView.setText("TODO"); } KDSize BufferTextViewWithTextField::minimalSizeForOptimalDisplay() const { @@ -21,6 +22,8 @@ void BufferTextViewWithTextField::setBufferText(const char * text) { void BufferTextViewWithTextField::didBecomeFirstResponder() { app()->setFirstResponder(&m_textField); + m_textField.setEditing(true, true); + markRectAsDirty(bounds()); } View * BufferTextViewWithTextField::subviewAtIndex(int index) { @@ -31,7 +34,7 @@ View * BufferTextViewWithTextField::subviewAtIndex(int index) { void BufferTextViewWithTextField::layoutSubviews() { m_bufferTextView.setFrame(KDRect(0, 0, k_height, k_bufferTextWidth)); - m_textField.setFrame(KDRect(k_bufferTextWidth, 0, k_height, bounds().width() - k_bufferTextWidth)); + m_textField.setFrame(KDRect(k_bufferTextWidth, 0, bounds().width() - k_bufferTextWidth, k_height)); } } diff --git a/apps/shared/buffer_text_view_with_text_field.h b/apps/shared/buffer_text_view_with_text_field.h index b6f8c5006..4f6f69709 100644 --- a/apps/shared/buffer_text_view_with_text_field.h +++ b/apps/shared/buffer_text_view_with_text_field.h @@ -9,6 +9,7 @@ public: constexpr static KDCoordinate k_height = 50; //TODO BufferTextViewWithTextField(Responder * parentResponder, TextFieldDelegate * delegate = nullptr, KDText::FontSize size = KDText::FontSize::Large); KDSize minimalSizeForOptimalDisplay() const override; + TextField * textField() { return &m_textField; } void setBufferText(const char * text); void setTextFieldText(const char * text); @@ -16,7 +17,7 @@ public: void didBecomeFirstResponder() override; private: constexpr static int k_textFieldBufferSize = TextField::maxBufferSize(); - constexpr static KDCoordinate k_bufferTextWidth = 70; //TODO + constexpr static KDCoordinate k_bufferTextWidth = 50; //TODO int numberOfSubviews() const override { return 2; } View * subviewAtIndex(int index) override; void layoutSubviews() override; diff --git a/apps/shared/store_controller.cpp b/apps/shared/store_controller.cpp index 72ca5aa91..54bc7138a 100644 --- a/apps/shared/store_controller.cpp +++ b/apps/shared/store_controller.cpp @@ -13,15 +13,23 @@ StoreController::ContentView::ContentView(FloatPairStore * store, Responder * pa Responder(parentResponder), m_dataView(store, this, dataSource, selectionDataSource), m_formulaInputView(this, textFieldDelegate), - m_displayInputFormulaView(false) + m_displayFormulaInputView(false) { m_dataView.setBackgroundColor(Palette::WallScreenDark); m_dataView.setVerticalCellOverlap(0); m_dataView.setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin); } +void StoreController::ContentView::displayFormulaInput(bool display) { + if (m_displayFormulaInputView != display) { + m_displayFormulaInputView = display; + layoutSubviews(); + markRectAsDirty(bounds()); + } +} + void StoreController::ContentView::didBecomeFirstResponder() { - app()->setFirstResponder(&m_dataView); + app()->setFirstResponder(m_displayFormulaInputView ? static_cast(&m_formulaInputView) : static_cast(&m_dataView)); } View * StoreController::ContentView::subviewAtIndex(int index) { @@ -31,10 +39,13 @@ View * StoreController::ContentView::subviewAtIndex(int index) { } void StoreController::ContentView::layoutSubviews() { - KDRect dataViewFrame(0, 0, bounds().width(), bounds().height() - (m_displayInputFormulaView ? BufferTextViewWithTextField::k_height : 0)); + KDRect dataViewFrame(0, 0, bounds().width(), bounds().height() - (m_displayFormulaInputView ? BufferTextViewWithTextField::k_height : 0)); m_dataView.setFrame(dataViewFrame); - KDRect formulaFrame(0, bounds().height() - BufferTextViewWithTextField::k_height, bounds().width(), m_displayInputFormulaView ? BufferTextViewWithTextField::k_height : 0); - m_formulaInputView.setFrame(formulaFrame); + m_formulaInputView.setFrame(formulaFrame()); +} + +KDRect StoreController::ContentView::formulaFrame() const { + return KDRect(0, bounds().height() - BufferTextViewWithTextField::k_height, bounds().width(), m_displayFormulaInputView ? BufferTextViewWithTextField::k_height : 0); } StoreController::StoreController(Responder * parentResponder, FloatPairStore * store, ButtonRowController * header) : @@ -47,10 +58,16 @@ StoreController::StoreController(Responder * parentResponder, FloatPairStore * s } void StoreController::displayFormulaInput() { - + contentView()->displayFormulaInput(true); } bool StoreController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { + if (textField == contentView()->formulaInputView()->textField()) { + // Handle formula input + contentView()->displayFormulaInput(false); + app()->setFirstResponder(contentView()); + return true; + } AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container(); Context * globalContext = appsContainer->globalContext(); double floatBody = Expression::approximateToScalar(text, *globalContext); diff --git a/apps/shared/store_controller.h b/apps/shared/store_controller.h index cddad9805..aa6b6e5e1 100644 --- a/apps/shared/store_controller.h +++ b/apps/shared/store_controller.h @@ -50,17 +50,20 @@ protected: public: ContentView(FloatPairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, TextFieldDelegate * textFieldDelegate); StoreSelectableTableView * dataView() { return &m_dataView; } + BufferTextViewWithTextField * formulaInputView() { return &m_formulaInputView; } + void displayFormulaInput(bool display); // Responder void didBecomeFirstResponder() override; private: static constexpr KDCoordinate k_margin = 8; static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin; - int numberOfSubviews() const override { return 1 + m_displayInputFormulaView; } + int numberOfSubviews() const override { return 1 + m_displayFormulaInputView; } View * subviewAtIndex(int index) override; void layoutSubviews() override; + KDRect formulaFrame() const; StoreSelectableTableView m_dataView; BufferTextViewWithTextField m_formulaInputView; - bool m_displayInputFormulaView; + bool m_displayFormulaInputView; }; Responder * tabController() const override;