[graph] TextFieldFunctionTitleCell

This commit is contained in:
Léa Saviot
2018-10-16 11:03:30 +02:00
committed by Émilie Feral
parent 00dcffbc69
commit bd65063b67
7 changed files with 84 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ app_objs += $(addprefix apps/graph/,\
graph/root_graph_controller.o\
graph/tangent_graph_controller.o\
list/storage_list_controller.o\
list/text_field_function_title_cell.o\
values/storage_derivative_parameter_controller.o\
values/storage_function_parameter_controller.o\
values/storage_values_controller.o\

View File

@@ -42,7 +42,7 @@ HighlightCell * StorageListController::expressionCells(int index) {
}
void StorageListController::willDisplayTitleCellAtIndex(HighlightCell * cell, int j) {
Shared::BufferFunctionTitleCell * myFunctionCell = (Shared::BufferFunctionTitleCell *)cell;
TextFieldFunctionTitleCell * myFunctionCell = (TextFieldFunctionTitleCell *)cell;
StorageFunction * function = m_functionStore->modelAtIndex(j);
char bufferName[BufferTextView::k_maxNumberOfChar];
function->nameWithArgument(bufferName, BufferTextView::k_maxNumberOfChar, m_functionStore->symbol());

View File

@@ -2,10 +2,11 @@
#define GRAPH_STORAGE_LIST_CONTROLLER_H
#include <escher.h>
#include "../../shared/storage_function_list_controller.h"
#include "text_field_function_title_cell.h"
#include "../storage_cartesian_function_store.h"
#include "../../shared/buffer_function_title_cell.h"
#include "../../shared/function_expression_cell.h"
#include <apps/shared/storage_function_list_controller.h>
#include <apps/shared/buffer_function_title_cell.h>
#include <apps/shared/function_expression_cell.h>
#include <apps/shared/storage_list_parameter_controller.h>
namespace Graph {
@@ -22,7 +23,7 @@ private:
void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override;
void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override;
constexpr static int k_maxNumberOfDisplayableRows = 5;
Shared::BufferFunctionTitleCell m_functionTitleCells[k_maxNumberOfDisplayableRows];
TextFieldFunctionTitleCell m_functionTitleCells[k_maxNumberOfDisplayableRows];
Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfDisplayableRows];
Shared::StorageListParameterController m_parameterController;
};

View File

@@ -0,0 +1,37 @@
#include "text_field_function_title_cell.h"
#include <assert.h>
namespace Graph {
void TextFieldFunctionTitleCell::setHighlighted(bool highlight) {
EvenOddCell::setHighlighted(highlight);
m_textField.setBackgroundColor(EvenOddCell::backgroundColor());
}
void TextFieldFunctionTitleCell::setEven(bool even) {
EvenOddCell::setEven(even);
m_textField.setBackgroundColor(EvenOddCell::backgroundColor());
}
void TextFieldFunctionTitleCell::setColor(KDColor color) {
FunctionTitleCell::setColor(color);
m_textField.setTextColor(color);
}
void TextFieldFunctionTitleCell::setText(const char * title) {
m_textField.setText(title);
}
void TextFieldFunctionTitleCell::layoutSubviews() {
m_textField.setFrame(textFieldFrame());
}
KDRect TextFieldFunctionTitleCell::textFieldFrame() const {
KDRect textFrame(0, k_colorIndicatorThickness, bounds().width(), bounds().height() - k_colorIndicatorThickness);
if (m_orientation == Orientation::VerticalIndicator){
textFrame = KDRect(k_colorIndicatorThickness, 0, bounds().width() - k_colorIndicatorThickness-k_separatorThickness, bounds().height()-k_separatorThickness);
}
return textFrame;
}
}

View File

@@ -0,0 +1,38 @@
#ifndef GRAPH_LIST_TEXT_FIELD_FUNCTION_TITLE_CELL_H
#define GRAPH_LIST_TEXT_FIELD_FUNCTION_TITLE_CELL_H
#include "../../shared/function_title_cell.h"
namespace Graph {
class TextFieldFunctionTitleCell : public Shared::FunctionTitleCell {
public:
TextFieldFunctionTitleCell(Orientation orientation = Orientation::VerticalIndicator, KDText::FontSize size = KDText::FontSize::Large) :
Shared::FunctionTitleCell(orientation),
m_textField(nullptr, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, false, size, 0.5f, 0.5f)
{}
void setEven(bool even) override;
void setHighlighted(bool highlight) override;
void setColor(KDColor color) override;
void setText(const char * textContent);
KDText::FontSize fontSize() const override { return m_textField.fontSize(); }
const char * text() const override {
return m_textField.text();
}
int numberOfSubviews() const override { return 1; }
View * subviewAtIndex(int index) override {
assert(index == 0);
return &m_textField;
}
void layoutSubviews() override;
protected:
KDRect textFieldFrame() const;
private:
constexpr static int k_textFieldBufferSize = TextField::maxBufferSize();
TextField m_textField;
char m_textFieldBuffer[k_textFieldBufferSize];
};
}
#endif

View File

@@ -29,6 +29,7 @@ public:
}
void scrollToCursor() override;
bool shouldFinishEditing(Ion::Events::Event event) override { return m_delegate->textFieldShouldFinishEditing(this, event); }
KDText::FontSize fontSize() const { return m_contentView.fontSize(); }
protected:
class ContentView : public TextInput::ContentView {
public:

View File

@@ -22,6 +22,7 @@ protected:
public:
ContentView(const KDFont * font);
void setFont(const KDFont * font);
const KDFont * font() const { return m_font; }
size_t cursorLocation() const { return m_cursorIndex; }
void setCursorLocation(int cursorLocation);
virtual const char * text() const = 0;