mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-25 16:50:50 +01:00
[apps/graph] make the function title cells consistent
Change-Id: Ib59f3d5f8a679cddd8a88e16711138425a6e9ecb
This commit is contained in:
@@ -4,19 +4,17 @@ app_objs += $(addprefix apps/graph/,\
|
||||
evaluate_context.o\
|
||||
function.o\
|
||||
function_store.o\
|
||||
function_title_cell.o\
|
||||
graph/cursor_view.o\
|
||||
graph/graph_controller.o\
|
||||
graph/graph_view.o\
|
||||
list/function_cell.o\
|
||||
list/function_expression_view.o\
|
||||
list/function_name_view.o\
|
||||
list/new_function_cell.o\
|
||||
list/list_controller.o\
|
||||
list/parameter_controller.o\
|
||||
values/abscissa_parameter_controller.o\
|
||||
values/derivative_parameter_controller.o\
|
||||
values/function_parameter_controller.o\
|
||||
values/function_title_cell.o\
|
||||
values/interval.o\
|
||||
values/title_cell.o\
|
||||
values/value_cell.o\
|
||||
|
||||
52
apps/graph/function_title_cell.cpp
Normal file
52
apps/graph/function_title_cell.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "function_title_cell.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Graph {
|
||||
|
||||
FunctionTitleCell::FunctionTitleCell() :
|
||||
EvenOddCell(),
|
||||
m_bufferTextView(0.5f, 0.5f)
|
||||
{
|
||||
}
|
||||
|
||||
void FunctionTitleCell::reloadCell() {
|
||||
EvenOddCell::reloadCell();
|
||||
m_bufferTextView.setBackgroundColor(backgroundColor());
|
||||
}
|
||||
|
||||
void FunctionTitleCell::setText(const char * title) {
|
||||
m_bufferTextView.setText(title);
|
||||
}
|
||||
|
||||
void FunctionTitleCell::setColor(KDColor color) {
|
||||
m_functionColor = color;
|
||||
m_bufferTextView.setTextColor(color);
|
||||
}
|
||||
|
||||
void FunctionTitleCell::setOrientation(Orientation orientation) {
|
||||
m_orientation = orientation;
|
||||
}
|
||||
|
||||
int FunctionTitleCell::numberOfSubviews() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
View * FunctionTitleCell::subviewAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return &m_bufferTextView;
|
||||
}
|
||||
|
||||
void FunctionTitleCell::layoutSubviews() {
|
||||
m_bufferTextView.setFrame(bounds());
|
||||
}
|
||||
|
||||
void FunctionTitleCell::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
EvenOddCell::drawRect(ctx, rect);
|
||||
if (m_orientation == Orientation::VerticalIndicator){
|
||||
ctx->fillRect(KDRect(0, 0, k_colorIndicatorThickness, bounds().height()), m_functionColor);
|
||||
} else {
|
||||
ctx->fillRect(KDRect(0, 0, bounds().width(), k_colorIndicatorThickness), m_functionColor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
32
apps/graph/function_title_cell.h
Normal file
32
apps/graph/function_title_cell.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef GRAPH_FUNCTION_TITLE_CELL_H
|
||||
#define GRAPH_FUNCTION_TITLE_CELL_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "even_odd_cell.h"
|
||||
|
||||
namespace Graph {
|
||||
class FunctionTitleCell : public EvenOddCell {
|
||||
public:
|
||||
enum class Orientation {
|
||||
HorizontalIndicator,
|
||||
VerticalIndicator
|
||||
};
|
||||
FunctionTitleCell();
|
||||
void setColor(KDColor color);
|
||||
void setOrientation(Orientation orientation);
|
||||
void setText(const char * textContent);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void reloadCell() override;
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_colorIndicatorThickness = 2;
|
||||
KDColor m_functionColor;
|
||||
BufferTextView m_bufferTextView;
|
||||
Orientation m_orientation;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "function_cell.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
constexpr KDColor FunctionCell::k_desactiveTextColor;
|
||||
|
||||
FunctionCell::FunctionCell() :
|
||||
EvenOddCell(),
|
||||
m_function(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void FunctionCell::setFunction(Function * f) {
|
||||
m_function = f;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
Function * FunctionCell::function() {
|
||||
return m_function;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef GRAPH_FUNCTION_CELL_H
|
||||
#define GRAPH_FUNCTION_CELL_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "../function.h"
|
||||
#include "../even_odd_cell.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class FunctionCell : public EvenOddCell {
|
||||
public:
|
||||
FunctionCell();
|
||||
void setFunction(Function * f);
|
||||
Function * function();
|
||||
|
||||
static constexpr KDColor k_desactiveTextColor = KDColor(0x646464);
|
||||
|
||||
protected:
|
||||
Function * m_function;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -2,13 +2,27 @@
|
||||
|
||||
namespace Graph {
|
||||
|
||||
constexpr KDColor FunctionExpressionView::k_separatorColor;
|
||||
|
||||
FunctionExpressionView::FunctionExpressionView() :
|
||||
FunctionCell()
|
||||
EvenOddCell(),
|
||||
m_function(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void FunctionExpressionView::setFunction(Function * f) {
|
||||
m_function = f;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
Function * FunctionExpressionView::function() {
|
||||
return m_function;
|
||||
}
|
||||
|
||||
void FunctionExpressionView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
EvenOddCell::drawRect(ctx, rect);
|
||||
// Color the separator
|
||||
ctx->fillRect(KDRect(0, 0, k_separatorThickness, bounds().height()), k_separatorColor);
|
||||
if (m_function->layout() == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -16,10 +30,10 @@ void FunctionExpressionView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
KDColor background = backgroundColor();
|
||||
// Select text color according to the state of the function
|
||||
bool active = m_function->isActive();
|
||||
KDColor text = active ? KDColorBlack : FunctionCell::k_desactiveTextColor;
|
||||
KDColor text = active ? KDColorBlack : Palette::k_desactiveTextColor;
|
||||
//Position the origin of expression
|
||||
KDSize expressionSize = m_function->layout()->size();
|
||||
KDPoint origin(0, 0.5f*(m_frame.height() - expressionSize.height()));
|
||||
KDPoint origin(k_separatorThickness, 0.5f*(m_frame.height() - expressionSize.height()));
|
||||
m_function->layout()->draw(ctx, origin, text, background);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,23 @@
|
||||
#define GRAPH_FUNCTION_EXPRESSION_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "function_cell.h"
|
||||
#include "../even_odd_cell.h"
|
||||
#include "../function.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class FunctionCell;
|
||||
|
||||
class FunctionExpressionView : public FunctionCell {
|
||||
class FunctionExpressionView : public EvenOddCell {
|
||||
public:
|
||||
FunctionExpressionView();
|
||||
void setFunction(Function * f);
|
||||
Function * function();
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
constexpr static KDColor k_separatorColor = KDColor(0xEFF2F4);
|
||||
constexpr static KDCoordinate k_separatorThickness = 1;
|
||||
Function * m_function;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "function_name_view.h"
|
||||
#include "../function_store.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
constexpr KDColor FunctionNameView::k_separatorColor;
|
||||
|
||||
FunctionNameView::FunctionNameView() :
|
||||
FunctionCell()
|
||||
{
|
||||
}
|
||||
|
||||
void FunctionNameView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
EvenOddCell::drawRect(ctx, rect);
|
||||
|
||||
KDCoordinate height = bounds().height();
|
||||
KDCoordinate width = bounds().width();
|
||||
// Color the color indicator
|
||||
KDColor functionColor = m_function->color();
|
||||
ctx->fillRect(KDRect(0, 0, k_colorIndicatorThickness, height), functionColor);
|
||||
// Color the separator
|
||||
ctx->fillRect(KDRect(width - k_separatorThickness, 0, k_separatorThickness, height), k_separatorColor);
|
||||
// Select function name color and the text color according to the state of the function
|
||||
bool active = m_function->isActive();
|
||||
KDColor textColor = active ? KDColorBlack : FunctionCell::k_desactiveTextColor;
|
||||
KDColor functionNameColor = active ? functionColor : FunctionCell::k_desactiveTextColor;
|
||||
// Select the background color according to the even line and the cursor selection
|
||||
KDColor background = backgroundColor();
|
||||
// Position the name of the function
|
||||
const char * functionName = m_function->name();
|
||||
KDSize textSize = KDText::stringSize(functionName);
|
||||
KDCoordinate baseline = textSize.height();
|
||||
KDSize expressionSize = textSize;
|
||||
if (m_function->layout()) {
|
||||
baseline = m_function->layout()->baseline();
|
||||
expressionSize = m_function->layout()->size();
|
||||
}
|
||||
KDPoint origin(0.5f*(k_colorIndicatorThickness + m_frame.width() - 4*textSize.width()),
|
||||
baseline-textSize.height()+0.5f*(m_frame.height() - expressionSize.height()));
|
||||
ctx->drawString(functionName, origin, functionNameColor, background);
|
||||
ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), textColor, background);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef GRAPH_FUNCTION_NAME_VIEW_H
|
||||
#define GRAPH_FUNCTION_NAME_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "function_cell.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class FunctionNameView : public FunctionCell {
|
||||
public:
|
||||
FunctionNameView();
|
||||
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_colorIndicatorThickness = 2;
|
||||
constexpr static KDCoordinate k_separatorThickness = 1;
|
||||
constexpr static KDColor k_separatorColor = KDColor(0xEFF2F4);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -203,8 +203,7 @@ bool ListController::handleEnter() {
|
||||
if (m_activeCelly == numberOfRows() - 1) {
|
||||
return true;
|
||||
}
|
||||
FunctionNameView * functionCell = (FunctionNameView *)(m_tableView.cellAtLocation(m_activeCellx, m_activeCelly));
|
||||
configureFunction(functionCell->function());
|
||||
configureFunction(m_functionStore->functionAtIndex(m_activeCelly));
|
||||
return true;
|
||||
}
|
||||
case 1:
|
||||
@@ -241,7 +240,7 @@ View * ListController::reusableCell(int index, int type) {
|
||||
assert(index < k_maxNumberOfRows);
|
||||
switch (type) {
|
||||
case 0:
|
||||
return &m_nameCells[index];
|
||||
return &m_functionTitleCells[index];
|
||||
case 1:
|
||||
return &m_expressionCells[index];
|
||||
case 2:
|
||||
@@ -263,8 +262,19 @@ int ListController::reusableCellCount(int type) {
|
||||
|
||||
void ListController::willDisplayCellAtLocation(View * cell, int i, int j) {
|
||||
if (j < numberOfRows() - 1) {
|
||||
FunctionCell * myCell = (FunctionCell *)cell;
|
||||
myCell->setFunction(m_functionStore->functionAtIndex(j));
|
||||
if (i == 0) {
|
||||
FunctionTitleCell * myFunctionCell = (FunctionTitleCell *)cell;
|
||||
Function * function = m_functionStore->functionAtIndex(j);
|
||||
char bufferName[5] = "*(x)";
|
||||
bufferName[0] = *function->name();
|
||||
myFunctionCell->setText(bufferName);
|
||||
KDColor functionNameColor = function->isActive() ? function->color() : Palette::k_desactiveTextColor;
|
||||
myFunctionCell->setColor(functionNameColor);
|
||||
myFunctionCell->setOrientation(FunctionTitleCell::Orientation::VerticalIndicator);
|
||||
} else {
|
||||
FunctionExpressionView * myCell = (FunctionExpressionView *)cell;
|
||||
myCell->setFunction(m_functionStore->functionAtIndex(j));
|
||||
}
|
||||
}
|
||||
EvenOddCell * myCell = (EvenOddCell *)cell;
|
||||
myCell->setEven(j%2 == 0);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "../function_store.h"
|
||||
#include "function_name_view.h"
|
||||
#include "../function_title_cell.h"
|
||||
#include "function_expression_view.h"
|
||||
#include "new_function_cell.h"
|
||||
#include "parameter_controller.h"
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
constexpr static int k_maxNumberOfRows = 6;
|
||||
// !!! CAUTION: The order here is important
|
||||
// The cells should be initialized *before* the TableView!
|
||||
FunctionNameView m_nameCells[k_maxNumberOfRows];
|
||||
FunctionTitleCell m_functionTitleCells[k_maxNumberOfRows];
|
||||
FunctionExpressionView m_expressionCells[k_maxNumberOfRows];
|
||||
EvenOddCell m_emptyCell;
|
||||
NewFunctionCell m_addNewFunction;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "function_title_cell.h"
|
||||
#include "../function.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
void FunctionTitleCell::setColor(KDColor color) {
|
||||
m_functionColor = color;
|
||||
}
|
||||
|
||||
void FunctionTitleCell::setDerivative(bool derivative) {
|
||||
m_derivative = derivative;
|
||||
PointerTextView * pointerTextView = (PointerTextView *)subviewAtIndex(0);
|
||||
int textwidth = KDText::stringSize("f").width();
|
||||
// Here we compute the right horizontal alignment to center "f(x)" or "f'(x)"
|
||||
if (derivative) {
|
||||
pointerTextView->setAlignment(0.5f*(m_frame.width() - 5*textwidth)/(m_frame.width() - textwidth), 0.5f);
|
||||
} else {
|
||||
pointerTextView->setAlignment(0.5f*(m_frame.width() - 4*textwidth)/(m_frame.width() - textwidth), 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionTitleCell::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
EvenOddCell::drawRect(ctx, rect);
|
||||
// Write the "(x)"
|
||||
KDColor background = backgroundColor();
|
||||
KDSize textSize = KDText::stringSize("f");
|
||||
KDPoint origin(0.5f*(m_frame.width() - 4*textSize.width()), 0.5f*(m_frame.height() - textSize.height()));
|
||||
if (m_derivative) {
|
||||
origin = KDPoint(0.5f*(m_frame.width() - 5*textSize.width()), 0.5f*(m_frame.height() - textSize.height()));
|
||||
ctx->drawString("'", origin.translatedBy(KDPoint(textSize.width(), 0)), m_functionColor , background);
|
||||
ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(2*textSize.width(), 0)), m_functionColor , background);
|
||||
} else {
|
||||
ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), m_functionColor , background);
|
||||
}
|
||||
// Color the color indicator
|
||||
ctx->fillRect(KDRect(0, 0, bounds().width(), k_colorIndicatorThickness), m_functionColor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef GRAPH_FUNCTION_TITLE_CELL_H
|
||||
#define GRAPH_FUNCTION_TITLE_CELL_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "title_cell.h"
|
||||
|
||||
namespace Graph {
|
||||
class FunctionTitleCell : public TitleCell {
|
||||
public:
|
||||
void setColor(KDColor color);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setDerivative(bool derivative);
|
||||
private:
|
||||
constexpr static KDCoordinate k_colorIndicatorThickness = 2;
|
||||
KDColor m_functionColor;
|
||||
bool m_derivative;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -384,13 +384,16 @@ void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) {
|
||||
}
|
||||
FunctionTitleCell * myFunctionCell = (FunctionTitleCell *)cell;
|
||||
Function * function = functionAtColumn(i);
|
||||
char bufferName[6] = "f'(x)";
|
||||
bufferName[1] = *function->name();
|
||||
myFunctionCell->setText(bufferName + 1);
|
||||
myFunctionCell->setColor(function->color());
|
||||
myFunctionCell->setOrientation(FunctionTitleCell::Orientation::HorizontalIndicator);
|
||||
if (isDerivativeColumn(i)) {
|
||||
myFunctionCell->setDerivative(true);
|
||||
} else {
|
||||
myFunctionCell->setDerivative(false);
|
||||
bufferName[0] = bufferName[1];
|
||||
bufferName[1] = '\'';
|
||||
myFunctionCell->setText(bufferName);
|
||||
}
|
||||
myFunctionCell->setText(function->name(), function->color());
|
||||
return;
|
||||
}
|
||||
// The cell is a value cell:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher.h>
|
||||
#include "../function_store.h"
|
||||
#include "../evaluate_context.h"
|
||||
#include "function_title_cell.h"
|
||||
#include "../function_title_cell.h"
|
||||
#include "value_cell.h"
|
||||
#include "title_cell.h"
|
||||
#include "interval.h"
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
constexpr static KDColor BackgroundColor = KDColor(0xF0F3F5);
|
||||
constexpr static KDColor CellBackgroundColor = KDColor(0xFCFCFC);
|
||||
constexpr static KDColor FocusCellBackgroundColor = KDColor(0xBFD3EB);
|
||||
constexpr static KDColor k_desactiveTextColor = KDColor(0x646464);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,4 +3,5 @@
|
||||
constexpr KDColor Palette::LineColor;
|
||||
constexpr KDColor Palette::BackgroundColor;
|
||||
constexpr KDColor Palette::CellBackgroundColor;
|
||||
constexpr KDColor Palette::FocusCellBackgroundColor;
|
||||
constexpr KDColor Palette::FocusCellBackgroundColor;
|
||||
constexpr KDColor Palette::k_desactiveTextColor;
|
||||
|
||||
Reference in New Issue
Block a user