From 953c9dfe64c7b20b4dd9ccb7e9d85607ca9488f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 4 Oct 2019 14:19:59 +0200 Subject: [PATCH] [apps/settings] Create a parent class CellWithSeparator to MessageTableCellWithEditableTextWithSeparator for future factorization --- apps/settings/Makefile | 2 +- apps/settings/cell_with_separator.cpp | 30 ++++++++++++++++ apps/settings/cell_with_separator.h | 27 +++++++++++++++ ...e_cell_with_editable_text_with_separator.h | 18 ++++------ .../sub_menu/display_mode_controller.h | 2 +- ...cell_with_editable_text_with_separator.cpp | 34 ------------------- 6 files changed, 65 insertions(+), 48 deletions(-) create mode 100644 apps/settings/cell_with_separator.cpp create mode 100644 apps/settings/cell_with_separator.h rename apps/settings/{sub_menu => }/message_table_cell_with_editable_text_with_separator.h (50%) delete mode 100644 apps/settings/sub_menu/message_table_cell_with_editable_text_with_separator.cpp diff --git a/apps/settings/Makefile b/apps/settings/Makefile index 5726653c7..1170109a9 100644 --- a/apps/settings/Makefile +++ b/apps/settings/Makefile @@ -3,6 +3,7 @@ app_headers += apps/settings/app.h app_settings_src = $(addprefix apps/settings/,\ app.cpp \ + cell_with_separator.cpp \ main_controller.cpp \ settings_message_tree.cpp \ sub_menu/about_controller.cpp \ @@ -10,7 +11,6 @@ app_settings_src = $(addprefix apps/settings/,\ sub_menu/exam_mode_controller.cpp \ sub_menu/generic_sub_controller.cpp \ sub_menu/language_controller.cpp \ - sub_menu/message_table_cell_with_editable_text_with_separator.cpp \ sub_menu/preferences_controller.cpp \ ) diff --git a/apps/settings/cell_with_separator.cpp b/apps/settings/cell_with_separator.cpp new file mode 100644 index 000000000..c7a51605b --- /dev/null +++ b/apps/settings/cell_with_separator.cpp @@ -0,0 +1,30 @@ +#include "cell_with_separator.h" + +namespace Settings { + +void CellWithSeparator::setHighlighted(bool highlight) { + cell()->setHighlighted(highlight); + HighlightCell::setHighlighted(highlight); +} + +void CellWithSeparator::drawRect(KDContext * ctx, KDRect rect) const { + //ctx->fillRect(KDRect(0, 0, bounds().width(), k_separatorThickness), Palette::GreyBright); + KDCoordinate height = bounds().height(); + ctx->fillRect(KDRect(0, m_separatorBelow ? height - k_margin : Metric::CellSeparatorThickness, bounds().width(), k_margin), Palette::WallScreen); +} + +int CellWithSeparator::numberOfSubviews() const { + return 1; +} + +View * CellWithSeparator::subviewAtIndex(int index) { + assert(index == 0); + return cell(); +} + +void CellWithSeparator::layoutSubviews(bool force) { + KDRect frame = KDRect(0, m_separatorBelow ? 0 : k_margin, bounds().width(), bounds().height()-k_margin); + cell()->setFrame(frame, force); +} + +} diff --git a/apps/settings/cell_with_separator.h b/apps/settings/cell_with_separator.h new file mode 100644 index 000000000..978ad7aee --- /dev/null +++ b/apps/settings/cell_with_separator.h @@ -0,0 +1,27 @@ +#ifndef SETTINGS_CELL_WITH_SEPARATOR_H +#define SETTINGS_CELL_WITH_SEPARATOR_H + +#include + +namespace Settings { + +class CellWithSeparator : public HighlightCell { +public: + CellWithSeparator(bool separatorBelow) : + m_separatorBelow(separatorBelow) {} + void setHighlighted(bool highlight) override; + void drawRect(KDContext * ctx, KDRect rect) const override; + void reloadCell() override { cell()->reloadCell(); } + Responder * responder() override { return cell()->responder(); } + constexpr static KDCoordinate k_margin = 10; +private: + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews(bool force = false) override; + virtual HighlightCell * cell() = 0; + bool m_separatorBelow; +}; + +} + +#endif diff --git a/apps/settings/sub_menu/message_table_cell_with_editable_text_with_separator.h b/apps/settings/message_table_cell_with_editable_text_with_separator.h similarity index 50% rename from apps/settings/sub_menu/message_table_cell_with_editable_text_with_separator.h rename to apps/settings/message_table_cell_with_editable_text_with_separator.h index 49e2c8ef0..2146bb982 100644 --- a/apps/settings/sub_menu/message_table_cell_with_editable_text_with_separator.h +++ b/apps/settings/message_table_cell_with_editable_text_with_separator.h @@ -1,26 +1,20 @@ #ifndef SETTINGS_MESSAGE_TABLE_CELL_WITH_EDITABLE_TEXT_WITH_SEPARATOR_H #define SETTINGS_MESSAGE_TABLE_CELL_WITH_EDITABLE_TEXT_WITH_SEPARATOR_H -#include +#include "cell_with_separator.h" namespace Settings { -class MessageTableCellWithEditableTextWithSeparator : public HighlightCell { +class MessageTableCellWithEditableTextWithSeparator : public CellWithSeparator { public: - MessageTableCellWithEditableTextWithSeparator(Responder * parentResponder = nullptr, InputEventHandlerDelegate * inputEventHandlerDelegate = nullptr, TextFieldDelegate * textFieldDelegate = nullptr, I18n::Message message = (I18n::Message)0); - void drawRect(KDContext * ctx, KDRect rect) const override; - void setHighlighted(bool highlight) override; - void reloadCell() override { m_cell.reloadCell(); } - Responder * responder() override { return m_cell.responder(); } + MessageTableCellWithEditableTextWithSeparator(Responder * parentResponder = nullptr, InputEventHandlerDelegate * inputEventHandlerDelegate = nullptr, TextFieldDelegate * textFieldDelegate = nullptr, I18n::Message message = (I18n::Message)0) : + CellWithSeparator(false), + m_cell(parentResponder, inputEventHandlerDelegate, textFieldDelegate, message) {} const char * text() const override { return m_cell.text(); } Poincare::Layout layout() const override{ return m_cell.layout(); } MessageTableCellWithEditableText * messageTableCellWithEditableText() { return &m_cell; } - constexpr static KDCoordinate k_margin = 10; private: - constexpr static KDCoordinate k_separatorThickness = Metric::CellSeparatorThickness; - int numberOfSubviews() const override; - View * subviewAtIndex(int index) override; - void layoutSubviews(bool force = false) override; + HighlightCell * cell() override { return &m_cell; } MessageTableCellWithEditableText m_cell; }; diff --git a/apps/settings/sub_menu/display_mode_controller.h b/apps/settings/sub_menu/display_mode_controller.h index fc0a8ef6d..1d58a9f1b 100644 --- a/apps/settings/sub_menu/display_mode_controller.h +++ b/apps/settings/sub_menu/display_mode_controller.h @@ -2,7 +2,7 @@ #define SETTINGS_DISPLAY_MODE_CONTROLLER_H #include "preferences_controller.h" -#include "message_table_cell_with_editable_text_with_separator.h" +#include "../message_table_cell_with_editable_text_with_separator.h" #include "../../shared/parameter_text_field_delegate.h" namespace Settings { diff --git a/apps/settings/sub_menu/message_table_cell_with_editable_text_with_separator.cpp b/apps/settings/sub_menu/message_table_cell_with_editable_text_with_separator.cpp deleted file mode 100644 index 4057f005c..000000000 --- a/apps/settings/sub_menu/message_table_cell_with_editable_text_with_separator.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "message_table_cell_with_editable_text_with_separator.h" - -namespace Settings { - -MessageTableCellWithEditableTextWithSeparator::MessageTableCellWithEditableTextWithSeparator(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * textFieldDelegate, I18n::Message message) : - HighlightCell(), - m_cell(parentResponder, inputEventHandlerDelegate, textFieldDelegate, message) -{ -} - -void MessageTableCellWithEditableTextWithSeparator::setHighlighted(bool highlight) { - m_cell.setHighlighted(highlight); - HighlightCell::setHighlighted(highlight); -} - -void MessageTableCellWithEditableTextWithSeparator::drawRect(KDContext * ctx, KDRect rect) const { - ctx->fillRect(KDRect(0, 0, bounds().width(), k_separatorThickness), Palette::GreyBright); - ctx->fillRect(KDRect(0, k_separatorThickness, bounds().width(), k_margin-k_separatorThickness), Palette::WallScreen); -} - -int MessageTableCellWithEditableTextWithSeparator::numberOfSubviews() const { - return 1; -} - -View * MessageTableCellWithEditableTextWithSeparator::subviewAtIndex(int index) { - assert(index == 0); - return &m_cell; -} - -void MessageTableCellWithEditableTextWithSeparator::layoutSubviews(bool force) { - m_cell.setFrame(KDRect(0, k_margin, bounds().width(), bounds().height()-k_margin), force); -} - -}