Skip to content

Commit

Permalink
[apps/graph] Added a color menu in graph and list (#189)
Browse files Browse the repository at this point in the history
* Revert "[github/workflows] Update Metrics to remove NumWorksBot"

This reverts commit 110f333.

* Added a color menu in graph and list

* Fixed color select display issue and build issue

* Changed color_cell to a circle

* Revert "Changed color_cell to a circle"

This reverts commit 28dddb4.

* Color_cell with mask

* Fixed build issue

* Color selection : Added right handle and color name display in menu

* Fixed constexpr static colorMask

* Changed font in color_parameter_controller

* Fix building without debug

* Re-Fix building without debug

* Update colors

Co-authored-by: Hugo Saint-Vignes <[email protected]>
Co-authored-by: Joachim LF <[email protected]>
  • Loading branch information
3 people authored Mar 23, 2022
1 parent 8ac969d commit 3b293c8
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 52 deletions.
2 changes: 1 addition & 1 deletion apps/graph/list/list_parameter_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) {
}
if (event == Ion::Events::Right) {
int selectedR = selectedRow();
if (selectedR == 0 || selectedR == 1) {
if (selectedR == 0 || selectedR == 1 || selectedR == 3) {
// Go in the submenu
return handleEnterOnRow(selectedR);
}
Expand Down
22 changes: 1 addition & 21 deletions apps/sequence/list/list_parameter_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,18 @@ const char * ListParameterController::title() {

bool ListParameterController::handleEvent(Ion::Events::Event event) {
bool hasAdditionalRow = hasInitialRankRow();
#if FUNCTION_COLOR_CHOICE
if (event == Ion::Events::OK || event == Ion::Events::EXE || (event == Ion::Events::Right && selectedRow() == 1)) {
#else
if (event == Ion::Events::OK || event == Ion::Events::EXE || (event == Ion::Events::Right && selectedRow() == 0)) {
#endif
int selectedRowIndex = selectedRow();
#if FUNCTION_COLOR_CHOICE
if (selectedRowIndex == 0) {
return handleEnterOnRow(selectedRowIndex);
}
if (selectedRowIndex == 1) {
#else
if (selectedRowIndex == 0) {
#endif
StackViewController * stack = (StackViewController *)(parentResponder());
m_typeParameterController.setRecord(m_record);
stack->push(&m_typeParameterController);
return true;
}
#if FUNCTION_COLOR_CHOICE
if (selectedRowIndex == 2+hasAdditionalRow) {

#else
if (selectedRowIndex == 1+hasAdditionalRow) {
#endif
if (selectedRowIndex == 1+hasAdditionalRow || selectedRowIndex == 2+hasAdditionalRow) {
return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1);
}
#if FUNCTION_COLOR_CHOICE
if (selectedRowIndex == 3+hasAdditionalRow) {
#else
if (selectedRowIndex == 2+hasAdditionalRow) {
#endif
App::app()->localContext()->resetCache();
return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1);
}
Expand Down
4 changes: 0 additions & 4 deletions apps/sequence/list/list_parameter_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ class ListParameterController : public Shared::ListParameterController, public S
HighlightCell * reusableCell(int index, int type) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
private:
#if FUNCTION_COLOR_CHOICE
constexpr static int k_totalNumberOfCell = 5;
#else
constexpr static int k_totalNumberOfCell = 4;
#endif
int totalNumberOfCells() const override;
Shared::Sequence * sequence() { return static_cast<Shared::Sequence *>(function().pointer()); }
bool hasInitialRankRow() const;
Expand Down
7 changes: 7 additions & 0 deletions apps/shared.de.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Kein Symbol "
ExamModeModeNoSymNoText = "Kein Symbol kein Text "
ExamModeModeDutch = "Niederländisch "
ColorRed = "Rot "
ColorBlue = "Blau "
ColorGreen = "Grün "
ColorYellow = "Gelb "
ColorPurple = "Violett "
ColorPink = "Rosa "
ColorOrange = "Orange "
7 changes: 7 additions & 0 deletions apps/shared.en.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "No sym "
ExamModeModeNoSymNoText = "No sym no text "
ExamModeModeDutch = "Dutch "
ColorRed = "Red "
ColorBlue = "Blue "
ColorGreen = "Green "
ColorYellow = "Yellow "
ColorPurple = "Purple "
ColorPink = "Pink "
ColorOrange = "Orange "
7 changes: 7 additions & 0 deletions apps/shared.es.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Estándar "
ExamModeModeNoSym = "Sin simbólico "
ExamModeModeNoSymNoText = "Sin simbólico sin texto "
ExamModeModeDutch = "Holandés "
ColorRed = "Rojo "
ColorBlue = "Azul "
ColorGreen = "Verde "
ColorYellow = "Amarillo "
ColorPurple = "Púrpura "
ColorPink = "Rosa "
ColorOrange = "Naranja "
7 changes: 7 additions & 0 deletions apps/shared.fr.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Sans symbolique "
ExamModeModeNoSymNoText = "Sans symbolique ni texte "
ExamModeModeDutch = "Dutch "
ColorRed = "Rouge "
ColorBlue = "Bleu "
ColorGreen = "Vert "
ColorYellow = "Jaune "
ColorPurple = "Violet "
ColorPink = "Rose "
ColorOrange = "Orange "
7 changes: 7 additions & 0 deletions apps/shared.hu.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Normál "
ExamModeModeNoSym = "Szimbólikus nélkül "
ExamModeModeNoSymNoText = "Szimbólikus és szöveg nélkül "
ExamModeModeDutch = "Holland "
ColorRed = "Piros "
ColorBlue = "Kék "
ColorGreen = "Zöld "
ColorYellow = "Sárga "
ColorPurple = "Lila "
ColorPink = "Rózsaszín "
ColorOrange = "Narancssárga "
7 changes: 7 additions & 0 deletions apps/shared.it.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Nessun simbolo "
ExamModeModeNoSymNoText = "Nessun simbolo nessun testo "
ExamModeModeDutch = "Olandese "
ColorRed = "Rosso "
ColorBlue = "Blu "
ColorGreen = "Verde "
ColorYellow = "Giallo "
ColorPurple = "Viola "
ColorPink = "Rosa "
ColorOrange = "Arancia "
7 changes: 7 additions & 0 deletions apps/shared.nl.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Standaard "
ExamModeModeNoSym = "Geen sym "
ExamModeModeNoSymNoText = "Geen sym geen tekst "
ExamModeModeDutch = "Nederlands "
ColorRed = "rood"
ColorBlue = "Blauw"
ColorGreen = "Groente"
ColorYellow = "Geel"
ColorPurple = "Purper"
ColorPink = "Roze"
ColorOrange = "Oranje"
7 changes: 7 additions & 0 deletions apps/shared.pt.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ ExamModeModeStandard = "Padrão "
ExamModeModeNoSym = "Sem sym "
ExamModeModeNoSymNoText = "Sem sym sem texto "
ExamModeModeDutch = "holandês "
ColorRed = "Vermelho "
ColorBlue = "Azul "
ColorGreen = "Verde "
ColorYellow = "Amarelo "
ColorPurple = "Roxa "
ColorPink = "Cor de rosa "
ColorOrange = "Laranja "
2 changes: 2 additions & 0 deletions apps/shared/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ app_shared_src = $(addprefix apps/shared/,\
buffer_function_title_cell.cpp \
buffer_text_view_with_text_field.cpp \
button_with_separator.cpp \
color_cell.cpp \
color_parameter_controller.cpp \
cursor_view.cpp \
editable_cell_table_view_controller.cpp \
expression_field_delegate_app.cpp \
Expand Down
51 changes: 51 additions & 0 deletions apps/shared/color_cell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "color_cell.h"

namespace Shared {

constexpr const I18n::Message MessageTableCellWithColor::k_textForIndex[Palette::numberOfDataColors()];

constexpr const uint8_t colorMask[MessageTableCellWithColor::ColorView::k_colorSize][MessageTableCellWithColor::ColorView::k_colorSize] = { // FIXME Can't link with constexpr static
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF, 0xFF},
{0xFF, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1, 0xFF},
{0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xFF},
{0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},
{0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},
{0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xFF},
{0xFF, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1, 0xFF},
{0xFF, 0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
};

MessageTableCellWithColor::MessageTableCellWithColor() :
MessageTableCell(),
m_accessoryView()
{}

View * MessageTableCellWithColor::accessoryView() const {
return (View *)&m_accessoryView;
}

void MessageTableCellWithColor::setColor(int i) {
m_accessoryView.setColor(i);
MessageTextView * label = (MessageTextView*)(labelView());
return label->setMessage(k_textForIndex[i]);
}

MessageTableCellWithColor::ColorView::ColorView() :
m_index(0)
{}

void MessageTableCellWithColor::ColorView::drawRect(KDContext * ctx, KDRect rect) const {
KDColor Buffer[MessageTableCellWithColor::ColorView::k_colorSize*MessageTableCellWithColor::ColorView::k_colorSize];
KDRect Frame(bounds().x(), bounds().y() + bounds().height()/2 - k_colorSize/2, k_colorSize, k_colorSize);
ctx->blendRectWithMask(Frame, Palette::DataColor[m_index], (const uint8_t *)colorMask, Buffer);
}

KDSize MessageTableCellWithColor::ColorView::minimalSizeForOptimalDisplay() const {
return KDSize(k_colorSize, k_colorSize);
}

}
42 changes: 42 additions & 0 deletions apps/shared/color_cell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef SHARED_COLOR_CELL_CONTROLLER_H
#define SHARED_COLOR_CELL_CONTROLLER_H

#include <escher.h>
#include <apps/i18n.h>

namespace Shared {

class MessageTableCellWithColor : public MessageTableCell {
public:
MessageTableCellWithColor();
View * accessoryView() const override;
void setColor(int i);
int color() { return m_accessoryView.color(); }
constexpr static I18n::Message k_textForIndex[Palette::numberOfDataColors()] = {
I18n::Message::ColorRed,
I18n::Message::ColorBlue,
I18n::Message::ColorGreen,
I18n::Message::ColorYellow,
I18n::Message::ColorPurple,
I18n::Message::ColorBlue,
I18n::Message::ColorPink,
I18n::Message::ColorOrange
};
class ColorView : public TransparentView {
public:
ColorView();
void setColor(int i) { m_index = i; }
int color() { return m_index; }
void drawRect(KDContext * ctx, KDRect rect) const override;
KDSize minimalSizeForOptimalDisplay() const override;
constexpr static KDCoordinate k_colorSize = 12;
private:
int m_index;
};
private:
ColorView m_accessoryView;
};

}

#endif
86 changes: 86 additions & 0 deletions apps/shared/color_parameter_controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "color_parameter_controller.h"

#include "function_app.h"
#include "../apps_container.h"
#include <assert.h>

namespace Shared {

ColorParameterController::ColorParameterController(Responder * parentResponder, I18n::Message title) :
ViewController(parentResponder),
m_selectableTableView(this),
m_record(),
m_title(title)
{}

void ColorParameterController::viewWillAppear() {
ViewController::viewWillAppear();
// Restore the selected color
KDColor FunctionColor = function()->color();
uint8_t cellXPosition = 0;
// TODO: Improve this if possible
for (uint8_t i = 0; i < sizeof(Palette::DataColor)/sizeof(Palette::DataColor[0]); i++) {
if (Palette::DataColor[i] == FunctionColor) {
cellXPosition = i;
break;
}
}
assert(Palette::DataColor[cellXPosition] == FunctionColor);
selectCellAtLocation(0, cellXPosition);
m_selectableTableView.reloadData();
}

void ColorParameterController::didBecomeFirstResponder() {
Container::activeApp()->setFirstResponder(&m_selectableTableView);
}

bool ColorParameterController::handleEvent(Ion::Events::Event event) {
StackViewController * stack = (StackViewController *)(parentResponder());
if (event == Ion::Events::Left) {
stack->pop();
return true;
}
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
handleEnterOnRow(selectedRow());
stack->pop();
return true;
}
return false;
}

KDCoordinate ColorParameterController::cellHeight() {
return Metric::ParameterCellHeight;
}

HighlightCell * ColorParameterController::reusableCell(int index) {
assert(index < numberOfRows());
return &m_cells[index];
}

void ColorParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
MessageTableCellWithColor * myCell = (MessageTableCellWithColor *)cell;
myCell->setColor(index);
myCell->setMessageFont(KDFont::LargeFont);
cell->reloadCell();
}

bool ColorParameterController::handleEnterOnRow(int rowIndex) {
function()->setColor(Palette::DataColor[rowIndex]);
return true;
}

void ColorParameterController::setRecord(Ion::Storage::Record record) {
m_record = record;
selectCellAtLocation(0, 0);
}

ExpiringPointer<Function> ColorParameterController::function() {
return functionStore()->modelForRecord(m_record);
}

FunctionStore * ColorParameterController::functionStore() {
return FunctionApp::app()->functionStore();
}


}
44 changes: 44 additions & 0 deletions apps/shared/color_parameter_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef SHARED_COLOR_PARAM_CONTROLLER_H
#define SHARED_COLOR_PARAM_CONTROLLER_H

#include <escher.h>
#include "function_store.h"
#include "color_cell.h"
#include <apps/i18n.h>

namespace Shared {

class ColorParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource {
public:
ColorParameterController(Responder * parentResponder, I18n::Message title);

View * view() override { return &m_selectableTableView; }
void viewWillAppear() override;
void didBecomeFirstResponder() override;

const char * title() override { return I18n::translate(m_title); }

bool handleEvent(Ion::Events::Event event) override;

TELEMETRY_ID("ColorParameter");

void setRecord(Ion::Storage::Record record);

int numberOfRows() const override { return Palette::numberOfDataColors(); }
KDCoordinate cellHeight() override;
HighlightCell * reusableCell(int index) override;
int reusableCellCount() const override { return Palette::numberOfDataColors(); } // FIXME Display issue
void willDisplayCellForIndex(HighlightCell * cell, int index);
private:
bool handleEnterOnRow(int rowIndex);
FunctionStore * functionStore();
ExpiringPointer<Function> function();
SelectableTableView m_selectableTableView;
Ion::Storage::Record m_record;
I18n::Message m_title;
MessageTableCellWithColor m_cells[Palette::numberOfDataColors()];
};

}

#endif
4 changes: 4 additions & 0 deletions apps/shared/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ void Function::setActive(bool active) {
}
}

void Function::setColor(KDColor color) {
recordData()->setColor(color);
}

int Function::printValue(double cursorT, double cursorX, double cursorY, char * buffer, int bufferSize, int precision, Poincare::Context * context) {
return PoincareHelpers::ConvertFloatToText<double>(cursorY, buffer, bufferSize, precision);
}
Expand Down
Loading

0 comments on commit 3b293c8

Please sign in to comment.