forked from Omega-Numworks/Omega
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apps/graph] Added a color menu in graph and list (#189)
* 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
1 parent
8ac969d
commit 3b293c8
Showing
20 changed files
with
312 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.