[settings] In DisplayMode sub menu, separate the result format choice

from the number of significants digits
This commit is contained in:
Émilie Feral
2018-09-25 13:36:08 +02:00
committed by LeaNumworks
parent 1b9bfe6255
commit afeb987efa
5 changed files with 89 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ app_objs += $(addprefix apps/settings/,\
sub_menu/exam_mode_controller.o\
sub_menu/generic_sub_controller.o\
sub_menu/language_controller.o\
sub_menu/message_table_cell_with_editable_text_with_separator.o\
sub_menu/preferences_controller.o\
)

View File

@@ -12,8 +12,23 @@ DisplayModeController::DisplayModeController(Responder * parentResponder) :
PreferencesController(parentResponder),
m_editableCell(&m_selectableTableView, this, m_draftTextBuffer)
{
m_editableCell.setMessage(I18n::Message::SignificantFigures);
m_editableCell.setMessageFontSize(KDText::FontSize::Large);
m_editableCell.messageTableCellWithEditableText()->setMessage(I18n::Message::SignificantFigures);
m_editableCell.messageTableCellWithEditableText()->setMessageFontSize(KDText::FontSize::Large);
}
KDCoordinate DisplayModeController::rowHeight(int j) {
if (j == numberOfRows()-1) {
return Metric::ParameterCellHeight+MessageTableCellWithEditableTextWithSeparator::k_margin;
}
return Metric::ParameterCellHeight;
}
KDCoordinate DisplayModeController::cumulatedHeightFromIndex(int j) {
return TableViewDataSource::cumulatedHeightFromIndex(j);
}
int DisplayModeController::indexFromCumulatedHeight(KDCoordinate offsetY) {
return TableViewDataSource::indexFromCumulatedHeight(offsetY);
}
HighlightCell * DisplayModeController::reusableCell(int index, int type) {
@@ -43,11 +58,11 @@ int DisplayModeController::typeAtLocation(int i, int j) {
void DisplayModeController::willDisplayCellForIndex(HighlightCell * cell, int index) {
/* Number of significants figure row */
if (index == numberOfRows()-1) {
GenericSubController::willDisplayCellForIndex(cell, index);
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *)cell;
MessageTableCellWithEditableTextWithSeparator * myCell = (MessageTableCellWithEditableTextWithSeparator *)cell;
GenericSubController::willDisplayCellForIndex(myCell->messageTableCellWithEditableText(), index);
char buffer[3];
Integer(Preferences::sharedPreferences()->numberOfSignificantDigits()).serialize(buffer, 3);
myCell->setAccessoryText(buffer);
myCell->messageTableCellWithEditableText()->setAccessoryText(buffer);
return;
}
PreferencesController::willDisplayCellForIndex(cell, index);

View File

@@ -2,6 +2,7 @@
#define SETTINGS_DISPLAY_MODE_CONTROLLER_H
#include "preferences_controller.h"
#include "message_table_cell_with_editable_text_with_separator.h"
#include "../../shared/parameter_text_field_delegate.h"
namespace Settings {
@@ -9,6 +10,9 @@ namespace Settings {
class DisplayModeController : public PreferencesController, public Shared::ParameterTextFieldDelegate {
public:
DisplayModeController(Responder * parentResponder);
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;
@@ -17,7 +21,7 @@ public:
bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override;
private:
Shared::TextFieldDelegateApp * textFieldDelegateApp() override;
MessageTableCellWithEditableText m_editableCell;
MessageTableCellWithEditableTextWithSeparator m_editableCell;
char m_draftTextBuffer[MessageTableCellWithEditableText::k_bufferLength];
};

View File

@@ -0,0 +1,34 @@
#include "message_table_cell_with_editable_text_with_separator.h"
namespace Settings {
MessageTableCellWithEditableTextWithSeparator::MessageTableCellWithEditableTextWithSeparator(Responder * parentResponder, TextFieldDelegate * textFieldDelegate, char * draftTextBuffer, I18n::Message message) :
HighlightCell(),
m_cell(parentResponder, textFieldDelegate, draftTextBuffer, 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() {
m_cell.setFrame(KDRect(0, k_margin, bounds().width(), bounds().height()-k_margin));
}
}

View File

@@ -0,0 +1,29 @@
#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>
namespace Settings {
class MessageTableCellWithEditableTextWithSeparator : public HighlightCell {
public:
MessageTableCellWithEditableTextWithSeparator(Responder * parentResponder = nullptr, TextFieldDelegate * textFieldDelegate = nullptr, char * draftTextBuffer = 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(); }
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 = 1;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
MessageTableCellWithEditableText m_cell;
};
}
#endif