[apps/settings] Use a MessageTableCellWithGaugeWithSeparator in the main

controller to mimic two tables
This commit is contained in:
Émilie Feral
2019-10-04 14:21:17 +02:00
committed by Léa Saviot
parent 953c9dfe64
commit f7fc8da94d
3 changed files with 41 additions and 6 deletions

View File

@@ -90,15 +90,25 @@ int MainController::numberOfRows() const {
};
KDCoordinate MainController::rowHeight(int j) {
if (j == k_indexOfBrightnessCell) {
return Metric::ParameterCellHeight + CellWithSeparator::k_margin;
}
return Metric::ParameterCellHeight;
}
KDCoordinate MainController::cumulatedHeightFromIndex(int j) {
return j*rowHeight(0);
KDCoordinate height = j * rowHeight(0);
if (j > k_indexOfBrightnessCell) {
height += CellWithSeparator::k_margin;
}
return height;
}
int MainController::indexFromCumulatedHeight(KDCoordinate offsetY) {
return offsetY/rowHeight(0);
if (offsetY < rowHeight(0)*k_indexOfBrightnessCell + CellWithSeparator::k_margin) {
return offsetY/rowHeight(0);
}
return (offsetY - CellWithSeparator::k_margin)/rowHeight(0);
}
HighlightCell * MainController::reusableCell(int index, int type) {
@@ -135,14 +145,16 @@ int MainController::typeAtLocation(int i, int j) {
void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) {
GlobalPreferences * globalPreferences = GlobalPreferences::sharedGlobalPreferences();
Preferences * preferences = Preferences::sharedPreferences();
MessageTableCell * myCell = (MessageTableCell *)cell;
myCell->setMessage(model()->children(index)->label());
I18n::Message title = model()->children(index)->label();
if (index == k_indexOfBrightnessCell) {
MessageTableCellWithGauge * myGaugeCell = (MessageTableCellWithGauge *)cell;
MessageTableCellWithGaugeWithSeparator * myGaugeCell = (MessageTableCellWithGaugeWithSeparator *)cell;
myGaugeCell->setMessage(title);
GaugeView * myGauge = (GaugeView *)myGaugeCell->accessoryView();
myGauge->setLevel((float)globalPreferences->brightnessLevel()/(float)Ion::Backlight::MaxBrightness);
return;
}
MessageTableCell * myCell = (MessageTableCell *)cell;
myCell->setMessage(title);
if (index == k_indexOfLanguageCell) {
int index = (int)globalPreferences->language()-1;
static_cast<MessageTableCellWithChevronAndMessage *>(cell)->setSubtitle(I18n::LanguageNames[index]);

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#include "settings_message_tree.h"
#include "message_table_cell_with_gauge_with_separator.h"
#include "sub_menu/about_controller.h"
#include "sub_menu/display_mode_controller.h"
#include "sub_menu/exam_mode_controller.h"
@@ -47,7 +48,7 @@ private:
bool hasPrompt() const { return promptMessage() != I18n::Message::Default; }
constexpr static int k_numberOfSimpleChevronCells = 7;
MessageTableCellWithChevronAndMessage m_cells[k_numberOfSimpleChevronCells];
MessageTableCellWithGauge m_brightnessCell;
MessageTableCellWithGaugeWithSeparator m_brightnessCell;
MessageTableCellWithSwitch m_popUpCell;
SelectableTableView m_selectableTableView;
PreferencesController m_preferencesController;

View File

@@ -0,0 +1,22 @@
#ifndef SETTINGS_MESSAGE_TABLE_WITH_GAUGE_WITH_SEPARATOR_H
#define SETTINGS_MESSAGE_TABLE_WITH_GAUGE_WITH_SEPARATOR_H
#include "cell_with_separator.h"
namespace Settings {
class MessageTableCellWithGaugeWithSeparator : public CellWithSeparator {
public:
MessageTableCellWithGaugeWithSeparator(I18n::Message message, const KDFont * font) :
CellWithSeparator(true),
m_cell(message, font) {}
View * accessoryView() const { return m_cell.accessoryView(); }
void setMessage(I18n::Message message) { return m_cell.setMessage(message); }
private:
HighlightCell * cell() override { return &m_cell; }
MessageTableCellWithGauge m_cell;
};
}
#endif