diff --git a/apps/shared/Makefile b/apps/shared/Makefile index 52777d509..1187839ce 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -41,9 +41,11 @@ app_objs += $(addprefix apps/shared/,\ round_cursor_view.o\ simple_interactive_curve_view_controller.o\ expression_layout_field_delegate.o\ + store_cell.o\ store_controller.o\ store_parameter_controller.o\ store_selectable_table_view.o\ + store_title_cell.o\ sum_graph_controller.o\ tab_table_controller.o\ text_field_delegate.o\ diff --git a/apps/shared/buffer_function_title_cell.cpp b/apps/shared/buffer_function_title_cell.cpp index f6e43d529..28050f2b2 100644 --- a/apps/shared/buffer_function_title_cell.cpp +++ b/apps/shared/buffer_function_title_cell.cpp @@ -38,11 +38,15 @@ View * BufferFunctionTitleCell::subviewAtIndex(int index) { } void BufferFunctionTitleCell::layoutSubviews() { + m_bufferTextView.setFrame(bufferTextViewFrame()); +} + +KDRect BufferFunctionTitleCell::bufferTextViewFrame() const { KDRect textFrame(0, k_colorIndicatorThickness, bounds().width(), bounds().height() - k_colorIndicatorThickness); if (m_orientation == Orientation::VerticalIndicator){ textFrame = KDRect(k_colorIndicatorThickness, 0, bounds().width() - k_colorIndicatorThickness, bounds().height()-k_separatorThickness); } - m_bufferTextView.setFrame(textFrame); + return textFrame; } } diff --git a/apps/shared/buffer_function_title_cell.h b/apps/shared/buffer_function_title_cell.h index dab68686c..e99aee2ec 100644 --- a/apps/shared/buffer_function_title_cell.h +++ b/apps/shared/buffer_function_title_cell.h @@ -15,6 +15,9 @@ public: int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews() override; +protected: + KDRect bufferTextViewFrame() const; + EvenOddBufferTextCell * bufferTextView() { return &m_bufferTextView; } private: EvenOddBufferTextCell m_bufferTextView; }; diff --git a/apps/shared/hideable_even_odd_editable_text_cell.cpp b/apps/shared/hideable_even_odd_editable_text_cell.cpp index c9f5b1ed1..e060e08a1 100644 --- a/apps/shared/hideable_even_odd_editable_text_cell.cpp +++ b/apps/shared/hideable_even_odd_editable_text_cell.cpp @@ -4,7 +4,7 @@ namespace Shared { KDColor HideableEvenOddEditableTextCell::backgroundColor() const { if (m_hide) { - return Palette::WallScreenDark; + return hideColor(); } return EvenOddEditableTextCell::backgroundColor(); } diff --git a/apps/shared/hideable_even_odd_editable_text_cell.h b/apps/shared/hideable_even_odd_editable_text_cell.h index 0103a9e85..ce36bf478 100644 --- a/apps/shared/hideable_even_odd_editable_text_cell.h +++ b/apps/shared/hideable_even_odd_editable_text_cell.h @@ -2,6 +2,7 @@ #define APPS_SHARED_HIDEABLE_EVEN_ODD_EDITABLE_TEXT_CELL_H #include +#include namespace Shared { @@ -12,6 +13,7 @@ public: m_hide(false) {} KDColor backgroundColor() const override; + static KDColor hideColor() { return Palette::WallScreenDark; } void setHide(bool hide); private: bool m_hide; diff --git a/apps/shared/store_cell.cpp b/apps/shared/store_cell.cpp new file mode 100644 index 000000000..a2329b753 --- /dev/null +++ b/apps/shared/store_cell.cpp @@ -0,0 +1,26 @@ +#include "store_cell.h" + +namespace Shared { + +void StoreCell::setSeparatorRight(bool separator) { + if (m_separatorRight != separator) { + m_separatorRight = separator; + reloadCell(); + } +} + +void StoreCell::drawRect(KDContext * ctx, KDRect rect) const { + HideableEvenOddEditableTextCell::drawRect(ctx, rect); + // Draw the separator + if (m_separatorRight) { + ctx->fillRect(KDRect(bounds().width() - k_separatorThickness, 0, k_separatorThickness, bounds().height()), HideableEvenOddEditableTextCell::hideColor()); + } +} + +void StoreCell::layoutSubviews() { + KDRect boundsThis = bounds(); + editableTextCell()->setFrame(KDRect(boundsThis.topLeft(), boundsThis.width() - k_separatorThickness, boundsThis.height())); +} + +} + diff --git a/apps/shared/store_cell.h b/apps/shared/store_cell.h new file mode 100644 index 000000000..ea0acfa05 --- /dev/null +++ b/apps/shared/store_cell.h @@ -0,0 +1,24 @@ +#ifndef APPS_SHARED_STORE_CELL_H +#define APPS_SHARED_STORE_CELL_H + +#include "hideable_even_odd_editable_text_cell.h" + +namespace Shared { + +class StoreCell : public HideableEvenOddEditableTextCell { +public: + StoreCell(Responder * parentResponder = nullptr, TextFieldDelegate * delegate = nullptr, char * draftTextBuffer = nullptr) : + HideableEvenOddEditableTextCell(parentResponder, delegate, draftTextBuffer), + m_separatorRight(false) + {} + void setSeparatorRight(bool separator); + void drawRect(KDContext * ctx, KDRect rect) const override; + void layoutSubviews() override; +private: + static constexpr KDCoordinate k_separatorThickness = 2; + bool m_separatorRight; +}; + +} + +#endif diff --git a/apps/shared/store_controller.cpp b/apps/shared/store_controller.cpp index a24454b63..c243a3813 100644 --- a/apps/shared/store_controller.cpp +++ b/apps/shared/store_controller.cpp @@ -79,9 +79,14 @@ int StoreController::typeAtLocation(int i, int j) { } void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { + // Handle the separator + if (cellAtLocationIsEditable(i, j)) { + bool shoudHaveRightSeparator = i % FloatPairStore::k_numberOfColumnsPerSeries == 1; + static_cast(cell)->setSeparatorRight(shoudHaveRightSeparator); + } // Handle empty cells if (j > 0 && j > m_store->numberOfPairsOfSeries(seriesAtColumn(i)) && j < numberOfRows()) { - HideableEvenOddEditableTextCell * myCell = static_cast(cell); + StoreCell * myCell = static_cast(cell); myCell->editableTextCell()->textField()->setText(""); if (cellShouldBeTransparent(i,j)) { myCell->setHide(true); @@ -92,7 +97,7 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int return; } if (cellAtLocationIsEditable(i, j)) { - static_cast(cell)->setHide(false); + static_cast(cell)->setHide(false); } willDisplayCellAtLocationWithDisplayMode(cell, i, j, PrintFloat::Mode::Decimal); } @@ -173,7 +178,7 @@ View * StoreController::loadView() { tableView->setVerticalCellOverlap(0); for (int i = 0; i < k_maxNumberOfEditableCells; i++) { - m_editableCells[i] = new HideableEvenOddEditableTextCell(tableView, this, m_draftTextBuffer); + m_editableCells[i] = new StoreCell(tableView, this, m_draftTextBuffer); } tableView->setMargins(k_margin); return tableView; diff --git a/apps/shared/store_controller.h b/apps/shared/store_controller.h index 19cab4e36..7ae903b9a 100644 --- a/apps/shared/store_controller.h +++ b/apps/shared/store_controller.h @@ -4,7 +4,7 @@ #include #include "editable_cell_table_view_controller.h" #include "float_pair_store.h" -#include "hideable_even_odd_editable_text_cell.h" +#include "store_cell.h" #include "store_parameter_controller.h" namespace Shared { @@ -51,7 +51,7 @@ protected: virtual HighlightCell * titleCells(int index) = 0; char m_draftTextBuffer[TextField::maxBufferSize()]; int seriesAtColumn(int column) const { return column / FloatPairStore::k_numberOfColumnsPerSeries; } - HideableEvenOddEditableTextCell * m_editableCells[k_maxNumberOfEditableCells]; + StoreCell * m_editableCells[k_maxNumberOfEditableCells]; FloatPairStore * m_store; StoreParameterController m_storeParameterController; private: diff --git a/apps/shared/store_title_cell.cpp b/apps/shared/store_title_cell.cpp new file mode 100644 index 000000000..e0246bdb6 --- /dev/null +++ b/apps/shared/store_title_cell.cpp @@ -0,0 +1,29 @@ +#include "store_title_cell.h" +#include "hideable_even_odd_editable_text_cell.h" + +namespace Shared { + +void StoreTitleCell::setSeparatorRight(bool separator) { + if (m_separatorRight != separator) { + m_separatorRight = separator; + reloadCell(); + } +} + +void StoreTitleCell::drawRect(KDContext * ctx, KDRect rect) const { + BufferFunctionTitleCell::drawRect(ctx, rect); + // Draw the separator + KDRect separatorRect(bounds().width() - k_separatorThickness, m_separatorRight ? 0 : k_colorIndicatorThickness, k_separatorThickness, bounds().height()); + if (m_separatorRight) { + ctx->fillRect(separatorRect, HideableEvenOddEditableTextCell::hideColor()); + } else { + ctx->fillRect(separatorRect, backgroundColor()); + } +} + +void StoreTitleCell::layoutSubviews() { + KDRect textFrame = bufferTextViewFrame(); + bufferTextView()->setFrame(KDRect(textFrame.topLeft(), textFrame.width() - k_separatorThickness, textFrame.height() )); +} + +} diff --git a/apps/shared/store_title_cell.h b/apps/shared/store_title_cell.h new file mode 100644 index 000000000..884346705 --- /dev/null +++ b/apps/shared/store_title_cell.h @@ -0,0 +1,24 @@ +#ifndef SHARED_STORE_TITLE_CELL_H +#define SHARED_STORE_TITLE_CELL_H + +#include "buffer_function_title_cell.h" + +namespace Shared { + +class StoreTitleCell : public BufferFunctionTitleCell { +public: + StoreTitleCell(Orientation orientation, KDText::FontSize size = KDText::FontSize::Large) : + BufferFunctionTitleCell(orientation, size), + m_separatorRight(false) + {} + void setSeparatorRight(bool separator); + void drawRect(KDContext * ctx, KDRect rect) const override; + void layoutSubviews() override; +private: + static constexpr KDCoordinate k_separatorThickness = 2; + bool m_separatorRight; +}; + +} + +#endif diff --git a/apps/statistics/store_controller.cpp b/apps/statistics/store_controller.cpp index 95ef251b3..f917ea312 100644 --- a/apps/statistics/store_controller.cpp +++ b/apps/statistics/store_controller.cpp @@ -21,7 +21,8 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int if (cellAtLocationIsEditable(i, j)) { return; } - Shared::BufferFunctionTitleCell * mytitleCell = (Shared::BufferFunctionTitleCell *)cell; + Shared::StoreTitleCell * mytitleCell = static_cast(cell); + mytitleCell->setSeparatorRight(i % Store::k_numberOfColumnsPerSeries == 1); int seriesIndex = i/Store::k_numberOfColumnsPerSeries; bool valuesColumn = i%Store::k_numberOfColumnsPerSeries == 0; assert(seriesIndex >= 0 && seriesIndex < FloatPairStore::k_numberOfSeries); @@ -55,7 +56,7 @@ bool StoreController::setDataAtLocation(double floatBody, int columnIndex, int r View * StoreController::loadView() { for (int i = 0; i < k_numberOfTitleCells; i++) { - m_titleCells[i] = new Shared::BufferFunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small); + m_titleCells[i] = new Shared::StoreTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small); } return Shared::StoreController::loadView(); } diff --git a/apps/statistics/store_controller.h b/apps/statistics/store_controller.h index 34bb91cd0..8427ab5af 100644 --- a/apps/statistics/store_controller.h +++ b/apps/statistics/store_controller.h @@ -4,7 +4,7 @@ #include #include "store.h" #include "../shared/store_controller.h" -#include "../shared/buffer_function_title_cell.h" +#include "../shared/store_title_cell.h" namespace Statistics { @@ -17,7 +17,7 @@ private: HighlightCell * titleCells(int index) override; View * loadView() override; void unloadView(View * view) override; - Shared::BufferFunctionTitleCell * m_titleCells[k_numberOfTitleCells]; + Shared::StoreTitleCell * m_titleCells[k_numberOfTitleCells]; }; }