-
Notifications
You must be signed in to change notification settings - Fork 61
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,11 @@ DerivativeFunctionColumn = "Spalte der Ableitungsfunktion" | |
HideDerivativeColumn = "Ableitungsfunktion ausblenden" | ||
AllowedCharactersAZaz09 = "Erlaubt: A..Z, a..z, 0..9, _" | ||
ReservedName = "Reserviertes Wort" | ||
FunctionColorBlack = "schwarz" | ||
FunctionColorBlue = "blau" | ||
FunctionColorRed = "rot" | ||
FunctionColorPurple = "lila" | ||
FunctionColorGreen = "grün" | ||
FunctionColorOrange = "Orange" | ||
FunctionColorYellow = "gelb" | ||
FunctionColorWhite = "weiß" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add carriage return (for all files which don't have it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay i do that |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "color_list.h" | ||
#include "apps/i18n.h" | ||
|
||
namespace Graph { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use a switch here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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’ |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||
#pragma once | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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); | ||||||||
} | ||||||||
} |
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()); | ||
} | ||
|
||
} |
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; | ||
}; | ||
|
||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just change the text...
(and add a line at the end of each file please)
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.