From 163513dfc039a4b2953c5fd8a7437514ce7849b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 5 Jun 2018 17:37:59 +0200 Subject: [PATCH] [apps/stats/reg] More beautiful formul input view --- .../buffer_text_view_with_text_field.cpp | 30 +++++++++++++++++-- .../shared/buffer_text_view_with_text_field.h | 8 +++-- apps/shared/store_controller.cpp | 4 +-- apps/shared/store_controller.h | 1 + 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/apps/shared/buffer_text_view_with_text_field.cpp b/apps/shared/buffer_text_view_with_text_field.cpp index 1f27faaef..3de524f41 100644 --- a/apps/shared/buffer_text_view_with_text_field.cpp +++ b/apps/shared/buffer_text_view_with_text_field.cpp @@ -1,11 +1,12 @@ #include "buffer_text_view_with_text_field.h" +#include namespace Shared { BufferTextViewWithTextField::BufferTextViewWithTextField(Responder * parentResponder, TextFieldDelegate * delegate, KDText::FontSize size) : View(), Responder(parentResponder), - m_bufferTextView(size, 1.0f, 0.5f), + m_bufferTextView(size, 0.0f, 0.5f), m_textField(this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, delegate, false, size, 0.0f, 0.5f), m_textFieldBuffer{} { @@ -19,6 +20,25 @@ void BufferTextViewWithTextField::setBufferText(const char * text) { m_bufferTextView.setText(text); } +void BufferTextViewWithTextField::drawRect(KDContext * ctx, KDRect rect) const { + KDRect textFieldRect = textFieldFrame(); + + // Fill margins with white + // Left margin + ctx->fillRect(KDRect(0, 0, Metric::TitleBarExternHorizontalMargin, bounds().height()), KDColorWhite); + ctx->fillRect(KDRect(bounds().width() - Metric::TitleBarExternHorizontalMargin, 0, Metric::TitleBarExternHorizontalMargin, bounds().height()), KDColorWhite); + // Right margin + ctx->fillRect(KDRect(bounds().width() - Metric::TitleBarExternHorizontalMargin, 0, Metric::TitleBarExternHorizontalMargin, bounds().height()), KDColorWhite); + // Above the text field + ctx->fillRect(KDRect(textFieldRect.x() - k_borderWidth, 0, textFieldRect.width() + 2*k_borderWidth, bounds().height()), KDColorWhite); + // Under the text field + ctx->fillRect(KDRect(textFieldRect.x() - k_borderWidth, textFieldRect.bottom() + k_borderWidth, textFieldRect.width() + 2*k_borderWidth, bounds().height()), KDColorWhite); + + // Draw the text field border + KDRect borderRect = KDRect(textFieldRect.x()-k_borderWidth, textFieldRect.y()-k_borderWidth, textFieldRect.width()+2*k_borderWidth, textFieldRect.height()+2*k_borderWidth); + ctx->strokeRect(borderRect, Palette::GreyMiddle); +} + void BufferTextViewWithTextField::didBecomeFirstResponder() { app()->setFirstResponder(&m_textField); m_textField.setEditing(true, true); @@ -32,8 +52,12 @@ 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, bounds().width() - k_bufferTextWidth, k_height)); + m_bufferTextView.setFrame(KDRect(Metric::TitleBarExternHorizontalMargin, 0, k_bufferTextWidth, bounds().height())); + m_textField.setFrame(textFieldFrame()); +} + +KDRect BufferTextViewWithTextField::textFieldFrame() const { + return KDRect(Metric::TitleBarExternHorizontalMargin + k_bufferTextWidth + k_borderWidth, k_textFieldVerticalMargin + k_borderWidth, bounds().width() - 2 * Metric::TitleBarExternHorizontalMargin - k_bufferTextWidth - 2 * k_borderWidth, bounds().height() - 2 * k_textFieldVerticalMargin - 2 * k_borderWidth); } } diff --git a/apps/shared/buffer_text_view_with_text_field.h b/apps/shared/buffer_text_view_with_text_field.h index 4f6f69709..755efd693 100644 --- a/apps/shared/buffer_text_view_with_text_field.h +++ b/apps/shared/buffer_text_view_with_text_field.h @@ -6,21 +6,23 @@ namespace Shared { class BufferTextViewWithTextField : public View, public Responder { 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); + void drawRect(KDContext * ctx, KDRect rect) const override; // Responder void didBecomeFirstResponder() override; private: constexpr static int k_textFieldBufferSize = TextField::maxBufferSize(); - constexpr static KDCoordinate k_bufferTextWidth = 50; //TODO + constexpr static KDCoordinate k_bufferTextWidth = 35; + constexpr static KDCoordinate k_textFieldVerticalMargin = 3; + constexpr static KDCoordinate k_borderWidth = 1; int numberOfSubviews() const override { return 2; } View * subviewAtIndex(int index) override; void layoutSubviews() override; + KDRect textFieldFrame() const; BufferTextView m_bufferTextView; TextField m_textField; char m_textFieldBuffer[k_textFieldBufferSize]; diff --git a/apps/shared/store_controller.cpp b/apps/shared/store_controller.cpp index 5879ddb89..fad5b0a30 100644 --- a/apps/shared/store_controller.cpp +++ b/apps/shared/store_controller.cpp @@ -39,13 +39,13 @@ View * StoreController::ContentView::subviewAtIndex(int index) { } void StoreController::ContentView::layoutSubviews() { - KDRect dataViewFrame(0, 0, bounds().width(), bounds().height() - (m_displayFormulaInputView ? BufferTextViewWithTextField::k_height : 0)); + KDRect dataViewFrame(0, 0, bounds().width(), bounds().height() - (m_displayFormulaInputView ? k_formulaInputHeight : 0)); m_dataView.setFrame(dataViewFrame); 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); + return KDRect(0, bounds().height() - k_formulaInputHeight, bounds().width(), m_displayFormulaInputView ? k_formulaInputHeight : 0); } StoreController::StoreController(Responder * parentResponder, DoublePairStore * store, ButtonRowController * header) : diff --git a/apps/shared/store_controller.h b/apps/shared/store_controller.h index a99191040..c8498ad17 100644 --- a/apps/shared/store_controller.h +++ b/apps/shared/store_controller.h @@ -60,6 +60,7 @@ protected: private: static constexpr KDCoordinate k_margin = 8; static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin; + static constexpr KDCoordinate k_formulaInputHeight = 31; int numberOfSubviews() const override { return 1 + m_displayFormulaInputView; } View * subviewAtIndex(int index) override; void layoutSubviews() override;