From 1e7069f00e3f68220297cf54c2865b2ceed3f1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 30 May 2018 10:00:51 +0200 Subject: [PATCH] [apps/stats] Fix margins and column widths --- apps/shared/store_cell.cpp | 2 +- apps/shared/store_cell.h | 1 + apps/shared/store_controller.h | 4 ++-- apps/statistics/Makefile | 1 + apps/statistics/box_controller.cpp | 8 +++++--- apps/statistics/calculation_cell.cpp | 2 +- apps/statistics/calculation_cell.h | 2 ++ apps/statistics/calculation_controller.cpp | 6 +++--- apps/statistics/calculation_controller.h | 5 +++-- apps/statistics/calculation_title_cell.cpp | 10 ++++++++++ apps/statistics/calculation_title_cell.h | 20 ++++++++++++++++++++ 11 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 apps/statistics/calculation_title_cell.cpp create mode 100644 apps/statistics/calculation_title_cell.h diff --git a/apps/shared/store_cell.cpp b/apps/shared/store_cell.cpp index cee473f52..57a62bbdf 100644 --- a/apps/shared/store_cell.cpp +++ b/apps/shared/store_cell.cpp @@ -21,7 +21,7 @@ void StoreCell::drawRect(KDContext * ctx, KDRect rect) const { void StoreCell::layoutSubviews() { KDRect boundsThis = bounds(); - editableTextCell()->setFrame(KDRect(boundsThis.left() + Metric::TableSeparatorThickness, boundsThis.top(), boundsThis.width() - Metric::TableSeparatorThickness, boundsThis.height())); + editableTextCell()->setFrame(KDRect(boundsThis.left() + Metric::TableSeparatorThickness, boundsThis.top(), boundsThis.width() - Metric::TableSeparatorThickness - k_rightMargin, boundsThis.height())); } } diff --git a/apps/shared/store_cell.h b/apps/shared/store_cell.h index cecf7dc55..9e0f70064 100644 --- a/apps/shared/store_cell.h +++ b/apps/shared/store_cell.h @@ -15,6 +15,7 @@ public: void drawRect(KDContext * ctx, KDRect rect) const override; void layoutSubviews() override; private: + static constexpr KDCoordinate k_rightMargin = 2; bool m_separatorLeft; }; diff --git a/apps/shared/store_controller.h b/apps/shared/store_controller.h index d6d7342ef..59ed0bea8 100644 --- a/apps/shared/store_controller.h +++ b/apps/shared/store_controller.h @@ -34,11 +34,11 @@ public: void didBecomeFirstResponder() override; protected: - static constexpr KDCoordinate k_cellWidth = 80; //TODO + static constexpr KDCoordinate k_cellWidth = 116; static constexpr KDCoordinate k_margin = 8; static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin; constexpr static int k_maxNumberOfEditableCells = 22 * FloatPairStore::k_numberOfSeries; - constexpr static int k_numberOfTitleCells = FloatPairStore::k_numberOfColumnsPerSeries * FloatPairStore::k_numberOfSeries; // TODO Put finer number of cells + constexpr static int k_numberOfTitleCells = 4; static constexpr int k_titleCellType = 0; static constexpr int k_editableCellType = 1; Responder * tabController() const override; diff --git a/apps/statistics/Makefile b/apps/statistics/Makefile index 24cc6b475..f1d5a02b3 100644 --- a/apps/statistics/Makefile +++ b/apps/statistics/Makefile @@ -11,6 +11,7 @@ app_objs += $(addprefix apps/statistics/,\ calculation_cell.o\ calculation_controller.o\ calculation_selectable_table_view.o\ + calculation_title_cell.o\ histogram_banner_view.o\ histogram_controller.o\ histogram_parameter_controller.o\ diff --git a/apps/statistics/box_controller.cpp b/apps/statistics/box_controller.cpp index 3e34c0838..29d0b55e0 100644 --- a/apps/statistics/box_controller.cpp +++ b/apps/statistics/box_controller.cpp @@ -40,7 +40,7 @@ void BoxController::reloadBannerView() { // Set series name char seriesChar = '0' + selectedSeries() + 1; - char bufferName[] = {'V', seriesChar, '/', 'N', seriesChar, 0}; + char bufferName[] = {' ', 'V', seriesChar, '/', 'N', seriesChar, 0}; m_view.editableBannerView()->setLegendAtIndex(bufferName, 0); @@ -49,11 +49,13 @@ void BoxController::reloadBannerView() { m_view.editableBannerView()->setMessageAtIndex(calculationName[selectedQuantile], 1); // Set calculation result - char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; + char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits) + 1]; CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile, &Store::maxValue}; double calculation = (m_store->*calculationMethods[selectedQuantile])(selectedSeries()); - PrintFloat::convertFloatToText(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + int numberOfChar = PrintFloat::convertFloatToText(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + buffer[numberOfChar++] = ' '; + buffer[numberOfChar] = 0; m_view.editableBannerView()->setLegendAtIndex(buffer, 2); } diff --git a/apps/statistics/calculation_cell.cpp b/apps/statistics/calculation_cell.cpp index 8a7e3f1bd..ccb886a26 100644 --- a/apps/statistics/calculation_cell.cpp +++ b/apps/statistics/calculation_cell.cpp @@ -13,7 +13,7 @@ void CalculationCell::drawRect(KDContext * ctx, KDRect rect) const { void CalculationCell::layoutSubviews() { KDRect boundsThis = bounds(); - m_bufferTextView.setFrame(KDRect(boundsThis.left() + Metric::TableSeparatorThickness, boundsThis.top(), boundsThis.width() - Metric::TableSeparatorThickness, boundsThis.height())); + m_bufferTextView.setFrame(KDRect(boundsThis.left() + Metric::TableSeparatorThickness, boundsThis.top(), boundsThis.width() - Metric::TableSeparatorThickness - k_rightMargin, boundsThis.height())); } } diff --git a/apps/statistics/calculation_cell.h b/apps/statistics/calculation_cell.h index bc33745ae..a4ca0a4bc 100644 --- a/apps/statistics/calculation_cell.h +++ b/apps/statistics/calculation_cell.h @@ -10,6 +10,8 @@ public: using EvenOddBufferTextCell::EvenOddBufferTextCell; void drawRect(KDContext * ctx, KDRect rect) const override; void layoutSubviews() override; +private: + constexpr static KDCoordinate k_rightMargin = 2; }; } diff --git a/apps/statistics/calculation_controller.cpp b/apps/statistics/calculation_controller.cpp index b9cb84ea4..269598328 100644 --- a/apps/statistics/calculation_controller.cpp +++ b/apps/statistics/calculation_controller.cpp @@ -75,8 +75,8 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int I18n::Message::Sum, I18n::Message::SquareSum, I18n::Message::SampleStandardDeviationS}; - EvenOddMessageTextCell * evenOddMessageCell = static_cast(cell); - evenOddMessageCell->setMessage(titles[j-1]); + CalculationTitleCell * calcTitleCell = static_cast(cell); + calcTitleCell->setMessage(titles[j-1]); return; } // Display a calculation cell @@ -205,7 +205,7 @@ View * CalculationController::loadView() { m_seriesTitleCells[i]->setSeparatorLeft(true); } for (int i = 0; i < k_numberOfCalculationTitleCells; i++) { - m_calculationTitleCells[i] = new EvenOddMessageTextCell(KDText::FontSize::Small); + m_calculationTitleCells[i] = new CalculationTitleCell(KDText::FontSize::Small); m_calculationTitleCells[i]->setAlignment(1.0f, 0.5f); } for (int i = 0; i < k_numberOfCalculationCells; i++) { diff --git a/apps/statistics/calculation_controller.h b/apps/statistics/calculation_controller.h index cb88b0f3a..90a25dfb1 100644 --- a/apps/statistics/calculation_controller.h +++ b/apps/statistics/calculation_controller.h @@ -4,6 +4,7 @@ #include #include "store.h" #include "calculation_cell.h" +#include "calculation_title_cell.h" #include "../shared/hideable_even_odd_cell.h" #include "../shared/store_title_cell.h" #include "../shared/tab_table_controller.h" @@ -53,7 +54,7 @@ private: static constexpr int k_hideableCellType = 3; static constexpr KDCoordinate k_cellHeight = 20; static constexpr KDCoordinate k_calculationTitleCellWidth = 175; - static constexpr KDCoordinate k_calculationCellWidth = 70; + static constexpr KDCoordinate k_calculationCellWidth = 84; static constexpr KDCoordinate k_margin = 8; static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin; @@ -62,7 +63,7 @@ private: void unloadView(View * view) override; Shared::StoreTitleCell * m_seriesTitleCells[k_numberOfSeriesTitleCells]; - EvenOddMessageTextCell * m_calculationTitleCells[k_numberOfCalculationTitleCells]; + CalculationTitleCell * m_calculationTitleCells[k_numberOfCalculationTitleCells]; CalculationCell * m_calculationCells[k_numberOfCalculationCells]; Shared::HideableEvenOddCell * m_hideableCell; Store * m_store; diff --git a/apps/statistics/calculation_title_cell.cpp b/apps/statistics/calculation_title_cell.cpp new file mode 100644 index 000000000..fcfb58bec --- /dev/null +++ b/apps/statistics/calculation_title_cell.cpp @@ -0,0 +1,10 @@ +#include "calculation_title_cell.h" + +namespace Statistics { + +void CalculationTitleCell::layoutSubviews() { + m_messageTextView.setFrame(KDRect(bounds().topLeft(), bounds().width() - k_rightMargin, bounds().height())); +} + +} + diff --git a/apps/statistics/calculation_title_cell.h b/apps/statistics/calculation_title_cell.h new file mode 100644 index 000000000..22a5f85e6 --- /dev/null +++ b/apps/statistics/calculation_title_cell.h @@ -0,0 +1,20 @@ +#ifndef APPS_STATISTICS_CALCULATION_TITLE_CELL_H +#define APPS_STATISTICS_CALCULATION_TITLE_CELL_H + +#include + +namespace Statistics { + +class CalculationTitleCell : public EvenOddMessageTextCell { +public: + CalculationTitleCell(KDText::FontSize size = KDText::FontSize::Small) : + EvenOddMessageTextCell(size) + {} + void layoutSubviews() override; +private: + constexpr static KDCoordinate k_rightMargin = 2; +}; + +} + +#endif