[apps/settings] Create a parent class CellWithSeparator to

MessageTableCellWithEditableTextWithSeparator for future factorization
This commit is contained in:
Émilie Feral
2019-10-04 14:19:59 +02:00
committed by Léa Saviot
parent 3627dc0c0f
commit 953c9dfe64
6 changed files with 65 additions and 48 deletions

View File

@@ -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 \
)

View File

@@ -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);
}
}

View File

@@ -0,0 +1,27 @@
#ifndef SETTINGS_CELL_WITH_SEPARATOR_H
#define SETTINGS_CELL_WITH_SEPARATOR_H
#include <escher.h>
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

View File

@@ -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 <escher.h>
#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;
};

View File

@@ -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 {

View File

@@ -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);
}
}