Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a change function color parameter for issue #151 #153

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/graph/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ app_graph_src = $(addprefix apps/graph/,\
list/text_field_function_title_cell.cpp \
list/type_helper.cpp \
list/type_parameter_controller.cpp \
list/color_parameter_controller.cpp \
list/color_list.cpp \
values/abscissa_title_cell.cpp \
values/derivative_parameter_controller.cpp \
values/function_parameter_controller.cpp \
Expand Down
8 changes: 8 additions & 0 deletions apps/graph/base.de.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Spalte der Ableitungsfunktion"
HideDerivativeColumn = "Ableitungsfunktion ausblenden"
AllowedCharactersAZaz09 = "Erlaubt: A..Z, a..z, 0..9, _"
ReservedName = "Reserviertes Wort"
FunctionColorBlack = "schwarz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to start the colors with a capital letter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do that 🤣 no i'm joking but you think this pr is still valid ? bc it is not very compact 🤔 as said @RedGl0w

Copy link
Member

@Lauryy06 Lauryy06 Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do that

Just change the text...

Suggested change
FunctionColorBlack = "schwarz"
FunctionColorBlack = "Schwarz"

(and add a line at the end of each file please)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the name of the colors, instead of somehow duplicating them, couldn't you rather use the pythonColors ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to move the Python colour names in the shared i18n file in this case to can build without the Python app.

FunctionColorBlue = "blau"
FunctionColorRed = "rot"
FunctionColorPurple = "lila"
FunctionColorGreen = "grün"
FunctionColorOrange = "Orange"
FunctionColorYellow = "gelb"
FunctionColorWhite = "weiß"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add carriage return (for all files which don't have it)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay i do that

8 changes: 8 additions & 0 deletions apps/graph/base.en.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Derivative function column"
HideDerivativeColumn = "Hide the derivative function"
AllowedCharactersAZaz09 = "Allowed characters: A.Z, a..z, 0..9, _"
ReservedName = "Reserved name"
FunctionColorBlack = "black"
FunctionColorBlue = "blue"
FunctionColorRed = "red"
FunctionColorPurple = "purple"
FunctionColorGreen = "green"
FunctionColorOrange = "orange"
FunctionColorYellow = "yellow"
FunctionColorWhite = "white"
8 changes: 8 additions & 0 deletions apps/graph/base.es.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Columna de la derivada"
HideDerivativeColumn = "Ocultar la derivada"
AllowedCharactersAZaz09 = "Caracteres permitidos : A..Z, a..z, 0..9, _"
ReservedName = "Nombre reservado"
FunctionColorBlack = "negro"
FunctionColorBlue = "azul"
FunctionColorRed = "rojo"
FunctionColorPurple = "púrpura"
FunctionColorGreen = "verde"
FunctionColorOrange = "naranja"
FunctionColorYellow = "amarillo"
FunctionColorWhite = "blanco"
8 changes: 8 additions & 0 deletions apps/graph/base.fr.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Colonne de la fonction dérivée"
HideDerivativeColumn = "Masquer la fonction dérivée"
AllowedCharactersAZaz09 = "Caractères autorisés : A..Z, a..z, 0..9, _"
ReservedName = "Nom réservé"
FunctionColorBlack = "noir"
FunctionColorBlue = "bleu"
FunctionColorRed = "rouge"
FunctionColorPurple = "violet"
FunctionColorGreen = "vert"
FunctionColorOrange = "orange"
FunctionColorYellow = "jaune"
FunctionColorWhite = "blanc"
8 changes: 8 additions & 0 deletions apps/graph/base.hu.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "A derivált fügvény oszlopa"
HideDerivativeColumn = "A derivált függvény oszlop elrejtése"
AllowedCharactersAZaz09 = "Engedélyezett karakterek: A..Z, a..z, 0..9, _"
ReservedName = "Fenntartott név"
FunctionColorBlack = "fekete"
FunctionColorBlue = "kék"
FunctionColorRed = "piros"
FunctionColorPurple = "lila"
FunctionColorGreen = "zöld"
FunctionColorOrange = "narancs"
FunctionColorYellow = "sárga"
FunctionColorWhite = "fehér"
8 changes: 8 additions & 0 deletions apps/graph/base.it.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Colonna della funzione derivata"
HideDerivativeColumn = "Nascondere la funzione derivata"
AllowedCharactersAZaz09 = "Caratteri consentiti : A-Z, a-z, 0-9, _"
ReservedName = "Nome riservato"
FunctionColorBlack = "nero"
FunctionColorBlue = "blu"
FunctionColorRed = "rosso"
FunctionColorPurple = "viola"
FunctionColorGreen = "verde"
FunctionColorOrange = "arancione"
FunctionColorYellow = "giallo"
FunctionColorWhite = "bianco"
8 changes: 8 additions & 0 deletions apps/graph/base.nl.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Afgeleide functie kolom"
HideDerivativeColumn = "Verberg de afgeleide functie"
AllowedCharactersAZaz09 = "Toegestane tekens: A-Z, a-z, 0-9, _"
ReservedName = "Gereserveerde naam"
FunctionColorBlack = "zwart"
FunctionColorBlue = "blauw"
FunctionColorRed = "rood"
FunctionColorPurple = "paars"
FunctionColorGreen = "groen"
FunctionColorOrange = "oranje"
FunctionColorYellow = "geel"
FunctionColorWhite = "wit"
8 changes: 8 additions & 0 deletions apps/graph/base.pt.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Coluna da função derivada"
HideDerivativeColumn = "Esconder função derivada"
AllowedCharactersAZaz09 = "Caracteres permitidos : A..Z, a..z, 0..9, _"
ReservedName = "Nome reservado"
FunctionColorBlack = "preto"
FunctionColorBlue = "azul"
FunctionColorRed = "vermelho"
FunctionColorPurple = "roxo"
FunctionColorGreen = "verde"
FunctionColorOrange = "laranja"
FunctionColorYellow = "amarelo"
FunctionColorWhite = "branco"
44 changes: 44 additions & 0 deletions apps/graph/list/color_list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "color_list.h"
#include "apps/i18n.h"

namespace Graph {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't indent after namespace (for all files)

namespace FunctionColors {
Yaya-Cout marked this conversation as resolved.
Show resolved Hide resolved
I18n::Message Message(int index) {
static constexpr I18n::Message message[NumberOfColors] = {
I18n::Message::FunctionColorBlack,
I18n::Message::FunctionColorBlue,
I18n::Message::FunctionColorRed,
I18n::Message::FunctionColorPurple,
I18n::Message::FunctionColorGreen,
I18n::Message::FunctionColorOrange,
I18n::Message::FunctionColorYellow,
I18n::Message::FunctionColorWhite
};
return message[index];
}
KDColor color(int index) {
switch(index) {
case 0: return KDColorBlack;
case 1: return KDColorBlue;
case 2: return KDColorRed;
case 3: return KDColorPurple;
case 4: return KDColorGreen;
case 5: return KDColorOrange;
case 6: return KDColorYellow;
case 7: return KDColorWhite;
default: return KDColorRed;
}
}
I18n::Message currentColor(KDColor color) {
if(color == KDColorBlack) return Message(0);
if(color == KDColorBlue) return Message(1);
if(color == KDColorRed) return Message(2);
if(color == KDColorPurple) return Message(3);
if(color == KDColorGreen) return Message(4);
if(color == KDColorOrange) return Message(5);
if(color == KDColorYellow) return Message(6);
if(color == KDColorWhite) return Message(7);
return Message(2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a switch here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I had this idea but sometimes in the code you use many if(...) instead of a switch so I thought it was what I had to do but 🤔 but i correct it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally I tried the switch but I've got an error : error: call to non-‘constexpr’ function ‘KDColor::operator uint16_t() const’
case KDColorWhite: return Message(7);
So for now, I remove it :p

}
}
}
14 changes: 14 additions & 0 deletions apps/graph/list/color_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#pragma once
#ifndef GRAPH_COLOR_LIST_H
#define GRAPH_COLOR_LIST_H

This should be done in all header


#include <escher/i18n.h>
#include <escher.h>
#include "color_parameter_controller.h"

namespace Graph {
namespace FunctionColors {
constexpr static int NumberOfColors = NUMBER_OF_COLORS_AVAILABLE;
I18n::Message Message(int index);
KDColor color(int index);
I18n::Message currentColor(KDColor color);
}
}
72 changes: 72 additions & 0 deletions apps/graph/list/color_parameter_controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "color_parameter_controller.h"
#include <apps/i18n.h>
#include "../app.h"
#include "color_list.h"
#include <assert.h>

namespace Graph {
ColorParameterController::ColorParameterController(Responder * parentResponder) :
ViewController(parentResponder),
m_selectableTableView(this, this, this, nullptr),
m_record()
{
}

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

bool ColorParameterController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
assert(!m_record.isNull());
App * myApp = App::app();
assert(!m_record.isNull());
Shared::ExpiringPointer<Shared::ContinuousFunction> function = myApp->functionStore()->modelForRecord(m_record);
function->changeColor(FunctionColors::color(selectedRow()));
StackViewController * stack = stackController();
stack->pop();
stack->pop();
return true;
}
if (event == Ion::Events::Left && !m_record.isNull()) {
stackController()->pop();
return true;
}
return false;
}

const char * ColorParameterController::title() {
return I18n::translate(I18n::Message::FunctionColor);
}

void ColorParameterController::viewWillAppear() {
ViewController::viewWillAppear();
App * myApp = App::app();
assert(!m_record.isNull());
Shared::ExpiringPointer<Shared::ContinuousFunction> function = myApp->functionStore()->modelForRecord(m_record);
int row = static_cast<int>(function->plotType());
selectCellAtLocation(0, row);
m_selectableTableView.reloadData();
}

KDCoordinate ColorParameterController::rowHeight(int j) {
return 30;
}

void ColorParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
assert(0 <= index && index < k_numberOfTypes);
MessageTableCellWithExpression * myCell = static_cast<MessageTableCellWithExpression *>(cell);
myCell->setMessage(FunctionColors::Message(index));
myCell->setTextColor(FunctionColors::color(index));
}

MessageTableCellWithExpression * ColorParameterController::reusableCell(int index, int type) {
assert(0 <= index && index < reusableCellCount(type));
return &m_cells[index];
}

StackViewController * ColorParameterController::stackController() const {
return static_cast<StackViewController *>(parentResponder());
}

}
44 changes: 44 additions & 0 deletions apps/graph/list/color_parameter_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <escher/view_controller.h>
#include <escher/list_view_data_source.h>
#include <escher/selectable_table_view.h>
#include <escher/message_table_cell_with_expression.h>
#include <escher/stack_view_controller.h>
#include <ion/storage.h>

#define NUMBER_OF_COLORS_AVAILABLE 8;

namespace Graph {

class ColorParameterController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource {
public:
ColorParameterController(Responder * parentResponder);

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

// ViewController
const char * title() override;
View * view() override { return &m_selectableTableView; }
void viewWillAppear() override;
TELEMETRY_ID("ColorParameter");

// ListViewDataSource
int numberOfRows() const override { return k_numberOfTypes; }
KDCoordinate rowHeight(int j) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
MessageTableCellWithExpression * reusableCell(int index, int type) override;
int reusableCellCount(int type) override { return k_numberOfTypes; }
int typeAtLocation(int i, int j) override { return 0; }

void setRecord(Ion::Storage::Record record) { m_record = record; }
private:
constexpr static int k_numberOfTypes = NUMBER_OF_COLORS_AVAILABLE;
StackViewController * stackController() const;
SelectableTableView m_selectableTableView;
MessageTableCellWithExpression m_cells[k_numberOfTypes];
Ion::Storage::Record m_record;
};

}
22 changes: 17 additions & 5 deletions apps/graph/list/list_parameter_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../app.h"
#include <escher/metric.h>
#include <assert.h>
#include "color_list.h"

using namespace Shared;
using namespace Poincare;
Expand All @@ -16,10 +17,12 @@ ListParameterController::ListParameterController(ListController * listController
m_listController(listController),
m_typeCell(),
m_typeParameterController(this),
m_colorParameterController(this),
m_domainParameterController(nullptr, inputEventHandlerDelegate),
m_renameCell(I18n::Message::Rename)
m_renameCell(I18n::Message::Rename),
m_colorCell()
{
m_selectableTableView.setMargins(Metric::CommonTopMargin, Metric::CommonTopMargin, Metric::CommonBottomMargin, Metric::CommonTopMargin); // Reduce the margins to make te text fit
m_selectableTableView.setMargins(Metric::CommonTopMargin, Metric::CommonTopMargin, Metric::CommonBottomMargin, Metric::CommonTopMargin); // Reduce the margins to make the text fit
}

HighlightCell * ListParameterController::reusableCell(int index, int type) {
Expand All @@ -30,6 +33,8 @@ HighlightCell * ListParameterController::reusableCell(int index, int type) {
return &m_functionDomain;
case 2:
return &m_renameCell;
case 3:
return &m_colorCell;
default:
return Shared::ListParameterController::reusableCell(index, type - 3);
}
Expand All @@ -41,7 +46,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 Expand Up @@ -73,15 +78,18 @@ int writeInterval(char * buffer, int bufferSize, double min, double max, int num

void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
Shared::ListParameterController::willDisplayCellForIndex(cell, index);
if ((cell == &m_typeCell || cell == &m_functionDomain) && !m_record.isNull()) {
if ((cell == &m_typeCell || cell == &m_functionDomain || cell == &m_colorCell) && !m_record.isNull()) {
App * myApp = App::app();
assert(!m_record.isNull());
Shared::ExpiringPointer<Shared::ContinuousFunction> function = myApp->functionStore()->modelForRecord(m_record);
if (cell == &m_typeCell) {
m_typeCell.setMessage(I18n::Message::CurveType);
int row = static_cast<int>(function->plotType());
m_typeCell.setSubtitle(PlotTypeHelper::Message(row));
} else {
} else if(cell == &m_colorCell) {
m_colorCell.setMessage(I18n::Message::FunctionColor);
m_colorCell.setSubtitle(FunctionColors::currentColor(function->color()));
} else {
assert(cell == &m_functionDomain);
m_functionDomain.setMessage(I18n::Message::FunctionDomain);
double min = function->tMin();
Expand Down Expand Up @@ -112,6 +120,10 @@ bool ListParameterController::handleEnterOnRow(int rowIndex) {
case 2:
renameFunction();
return true;
case 3:
m_colorParameterController.setRecord(m_record);
stack->push(&m_colorParameterController);
return true;
default:
return Shared::ListParameterController::handleEnterOnRow(rowIndex - 3);
}
Expand Down
5 changes: 4 additions & 1 deletion apps/graph/list/list_parameter_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <apps/shared/list_parameter_controller.h>
#include "type_parameter_controller.h"
#include "color_parameter_controller.h"
#include "domain_parameter_controller.h"

namespace Graph {
Expand All @@ -20,13 +21,15 @@ class ListParameterController : public Shared::ListParameterController {
bool handleEnterOnRow(int rowIndex) override;
private:
int totalNumberOfCells() const override {
return Shared::ListParameterController::totalNumberOfCells() + 2;
return Shared::ListParameterController::totalNumberOfCells() + 3;
}
void renameFunction();
ListController * m_listController;
MessageTableCellWithChevronAndMessage m_typeCell;
MessageTableCellWithChevronAndBuffer m_functionDomain;
MessageTableCellWithChevronAndMessage m_colorCell;
TypeParameterController m_typeParameterController;
ColorParameterController m_colorParameterController;
DomainParameterController m_domainParameterController;
MessageTableCell m_renameCell;
};
Expand Down
Loading