mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[apps/calculation] Change names: PrettyPrintView -->
ScrollableExpressionView and make result View an scrollable expression view Change-Id: I9ac85671bcb4fdbeda0e5dbc6788dc7eb93b7343
This commit is contained in:
@@ -7,7 +7,7 @@ app_objs += $(addprefix apps/calculation/,\
|
||||
history_view_cell.o\
|
||||
history_controller.o\
|
||||
edit_expression_controller.o\
|
||||
pretty_print_view.o\
|
||||
scrollable_expression_view.o\
|
||||
text_field.o\
|
||||
)
|
||||
|
||||
|
||||
@@ -43,12 +43,12 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
|
||||
EditExpressionController * editController = (EditExpressionController *)parentResponder();
|
||||
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
if (subviewType == HistoryViewCell::SubviewType::Input) {
|
||||
editController->setTextBody(calculation->text());
|
||||
} else {
|
||||
char resultText[Calculation::k_maximalExpressionTextLength];
|
||||
calculation->output()->writeTextInBuffer(resultText, Calculation::k_maximalExpressionTextLength);
|
||||
editController->setTextBody(resultText);
|
||||
char outputText[Calculation::k_maximalExpressionTextLength];
|
||||
calculation->output()->writeTextInBuffer(outputText, Calculation::k_maximalExpressionTextLength);
|
||||
editController->setTextBody(outputText);
|
||||
}
|
||||
m_selectableTableView.deselectTable();
|
||||
app()->setFirstResponder(editController);
|
||||
@@ -61,14 +61,14 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
EditExpressionController * editController = (EditExpressionController *)parentResponder();
|
||||
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
|
||||
Calculation newCalculation;
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
if (subviewType == HistoryViewCell::SubviewType::Input) {
|
||||
newCalculation = *calculation;
|
||||
} else {
|
||||
char resultText[Calculation::k_maximalExpressionTextLength];
|
||||
calculation->output()->writeTextInBuffer(resultText, Calculation::k_maximalExpressionTextLength);
|
||||
char outputText[Calculation::k_maximalExpressionTextLength];
|
||||
calculation->output()->writeTextInBuffer(outputText, Calculation::k_maximalExpressionTextLength);
|
||||
/* TODO: this will work when we will parse float */
|
||||
//App * calculationApp = (App *)app();
|
||||
//newCalculation.setContent(resultText, calculationApp->evaluateContext());
|
||||
//newCalculation.setContent(outputText, calculationApp->evaluateContext());
|
||||
}
|
||||
m_selectableTableView.deselectTable();
|
||||
m_calculationStore->push(&newCalculation);
|
||||
@@ -94,7 +94,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
} else {
|
||||
m_selectableTableView.selectCellAtLocation(0, 0);
|
||||
}
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
if (subviewType == HistoryViewCell::SubviewType::Input) {
|
||||
tableViewDidChangeSelection(&m_selectableTableView, 0, m_selectableTableView.selectedRow());
|
||||
} else {
|
||||
tableViewDidChangeSelection(&m_selectableTableView, 0, -1);
|
||||
@@ -115,13 +115,13 @@ void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)(t->selectedCell());
|
||||
selectedCell->setParentResponder(t);
|
||||
if (m_selectableTableView.selectedRow() < previousSelectedCellY) {
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Output);
|
||||
}
|
||||
if (m_selectableTableView.selectedRow() >= previousSelectedCellY) {
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::PrettyPrint);
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Input);
|
||||
}
|
||||
if (previousSelectedCellY == -1) {
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Output);
|
||||
}
|
||||
app()->setFirstResponder(selectedCell);
|
||||
selectedCell->reloadCell();
|
||||
@@ -151,9 +151,9 @@ void HistoryController::willDisplayCellForIndex(TableViewCell * cell, int index)
|
||||
|
||||
KDCoordinate HistoryController::rowHeight(int j) {
|
||||
Calculation * calculation = m_calculationStore->calculationAtIndex(j);
|
||||
KDCoordinate prettyPrintHeight = calculation->inputLayout()->size().height();
|
||||
KDCoordinate resultHeight = calculation->outputLayout()->size().height();
|
||||
return prettyPrintHeight + resultHeight + 3*HistoryViewCell::k_digitVerticalMargin;
|
||||
KDCoordinate inputHeight = calculation->inputLayout()->size().height();
|
||||
KDCoordinate outputHeight = calculation->outputLayout()->size().height();
|
||||
return inputHeight + outputHeight + 3*HistoryViewCell::k_digitVerticalMargin;
|
||||
}
|
||||
|
||||
KDCoordinate HistoryController::cumulatedHeightFromIndex(int j) {
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace Calculation {
|
||||
|
||||
HistoryViewCell::HistoryViewCell() :
|
||||
Responder(nullptr),
|
||||
m_prettyPrint(PrettyPrintView(this)),
|
||||
m_result(ExpressionView()),
|
||||
m_selectedSubviewType(HistoryViewCell::SubviewType::Result)
|
||||
m_inputView(ScrollableExpressionView(this)),
|
||||
m_outputView(ScrollableExpressionView(this)),
|
||||
m_selectedSubviewType(HistoryViewCell::SubviewType::Output)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ int HistoryViewCell::numberOfSubviews() const {
|
||||
View * HistoryViewCell::subviewAtIndex(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return &m_prettyPrint;
|
||||
return &m_inputView;
|
||||
case 1:
|
||||
return &m_result;
|
||||
return &m_outputView;
|
||||
default:
|
||||
assert(false);
|
||||
return nullptr;
|
||||
@@ -39,40 +39,45 @@ View * HistoryViewCell::subviewAtIndex(int index) {
|
||||
void HistoryViewCell::layoutSubviews() {
|
||||
KDCoordinate width = bounds().width();
|
||||
KDCoordinate height = bounds().height();
|
||||
KDSize prettyPrintSize = m_prettyPrint.minimalSizeForOptimalDisplay();
|
||||
if (prettyPrintSize.width() + k_digitHorizontalMargin > width) {
|
||||
m_prettyPrint.setFrame(KDRect(k_digitHorizontalMargin, k_digitVerticalMargin, width - k_digitHorizontalMargin, prettyPrintSize.height()));
|
||||
KDSize inputSize = m_inputView.minimalSizeForOptimalDisplay();
|
||||
if (inputSize.width() + k_digitHorizontalMargin > width) {
|
||||
m_inputView.setFrame(KDRect(k_digitHorizontalMargin, k_digitVerticalMargin, width - k_digitHorizontalMargin, inputSize.height()));
|
||||
} else {
|
||||
m_prettyPrint.setFrame(KDRect(k_digitHorizontalMargin, k_digitVerticalMargin, prettyPrintSize.width(), prettyPrintSize.height()));
|
||||
m_inputView.setFrame(KDRect(k_digitHorizontalMargin, k_digitVerticalMargin, inputSize.width(), inputSize.height()));
|
||||
}
|
||||
KDSize outputSize = m_outputView.minimalSizeForOptimalDisplay();
|
||||
if (outputSize.width() + k_digitHorizontalMargin > width) {
|
||||
m_outputView.setFrame(KDRect(k_digitHorizontalMargin, inputSize.height() + 2*k_digitVerticalMargin, width - k_digitHorizontalMargin, height - inputSize.height() - 3*k_digitVerticalMargin));
|
||||
} else {
|
||||
m_outputView.setFrame(KDRect(width - outputSize.width() - k_digitHorizontalMargin, inputSize.height() + 2*k_digitVerticalMargin, outputSize.width(), height - inputSize.height() - 3*k_digitVerticalMargin));
|
||||
}
|
||||
KDSize resultSize = m_result.minimalSizeForOptimalDisplay();
|
||||
KDRect resultFrame(width - resultSize.width() - k_digitHorizontalMargin, prettyPrintSize.height() + 2*k_digitVerticalMargin, resultSize.width(), height - prettyPrintSize.height() - 2*k_digitVerticalMargin);
|
||||
m_result.setFrame(resultFrame);
|
||||
}
|
||||
|
||||
void HistoryViewCell::setCalculation(Calculation * calculation) {
|
||||
m_prettyPrint.setExpression(calculation->inputLayout());
|
||||
m_result.setExpression(calculation->outputLayout());
|
||||
m_inputView.setExpression(calculation->inputLayout());
|
||||
m_outputView.setExpression(calculation->outputLayout());
|
||||
}
|
||||
|
||||
void HistoryViewCell::reloadCell() {
|
||||
m_result.setBackgroundColor(backgroundColor());
|
||||
m_prettyPrint.setBackgroundColor(backgroundColor());
|
||||
m_outputView.setBackgroundColor(backgroundColor());
|
||||
m_inputView.setBackgroundColor(backgroundColor());
|
||||
if (isHighlighted()) {
|
||||
if (m_selectedSubviewType == HistoryViewCell::SubviewType::Result) {
|
||||
m_result.setBackgroundColor(Palette::FocusCellBackgroundColor);
|
||||
if (m_selectedSubviewType == SubviewType::Output) {
|
||||
m_outputView.setBackgroundColor(Palette::FocusCellBackgroundColor);
|
||||
} else {
|
||||
m_prettyPrint.setBackgroundColor(Palette::FocusCellBackgroundColor);
|
||||
m_inputView.setBackgroundColor(Palette::FocusCellBackgroundColor);
|
||||
}
|
||||
}
|
||||
layoutSubviews();
|
||||
EvenOddCell::reloadCell();
|
||||
m_prettyPrint.reloadCell();
|
||||
m_inputView.reloadCell();
|
||||
}
|
||||
|
||||
void HistoryViewCell::didBecomeFirstResponder() {
|
||||
if (m_selectedSubviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
app()->setFirstResponder(&m_prettyPrint);
|
||||
if (m_selectedSubviewType == SubviewType::Input) {
|
||||
app()->setFirstResponder(&m_inputView);
|
||||
} else {
|
||||
app()->setFirstResponder(&m_outputView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,20 +90,13 @@ void HistoryViewCell::setSelectedSubviewType(HistoryViewCell::SubviewType subvie
|
||||
}
|
||||
|
||||
bool HistoryViewCell::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::Down && m_selectedSubviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
if ((event == Ion::Events::Down && m_selectedSubviewType == SubviewType::Input) ||
|
||||
(event == Ion::Events::Up && m_selectedSubviewType == SubviewType::Output)) {
|
||||
SubviewType otherSubviewType = m_selectedSubviewType == SubviewType::Input ? SubviewType::Output : SubviewType::Input;
|
||||
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
|
||||
tableView->scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType::Result, tableView->selectedColumn(), tableView->selectedRow());
|
||||
tableView->scrollToSubviewOfTypeOfCellAtLocation(otherSubviewType, tableView->selectedColumn(), tableView->selectedRow());
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
|
||||
app()->setFirstResponder(selectedCell);
|
||||
selectedCell->reloadCell();
|
||||
return true;
|
||||
}
|
||||
if (event == Ion::Events::Up && m_selectedSubviewType == HistoryViewCell::SubviewType::Result) {
|
||||
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
|
||||
tableView->scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType::PrettyPrint, tableView->selectedColumn(), tableView->selectedRow());
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::PrettyPrint);
|
||||
selectedCell->setSelectedSubviewType(otherSubviewType);
|
||||
app()->setFirstResponder(selectedCell);
|
||||
selectedCell->reloadCell();
|
||||
return true;
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
|
||||
#include <escher.h>
|
||||
#include "calculation.h"
|
||||
#include "pretty_print_view.h"
|
||||
#include "scrollable_expression_view.h"
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
class HistoryViewCell : public ::EvenOddCell, public Responder {
|
||||
public:
|
||||
enum class SubviewType {
|
||||
PrettyPrint,
|
||||
Result
|
||||
Input,
|
||||
Output
|
||||
};
|
||||
HistoryViewCell();
|
||||
void reloadCell() override;
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
void setSelectedSubviewType(HistoryViewCell::SubviewType subviewType);
|
||||
private:
|
||||
constexpr static KDCoordinate k_resultWidth = 80;
|
||||
PrettyPrintView m_prettyPrint;
|
||||
ExpressionView m_result;
|
||||
ScrollableExpressionView m_inputView;
|
||||
ScrollableExpressionView m_outputView;
|
||||
SubviewType m_selectedSubviewType;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "pretty_print_view.h"
|
||||
#include "scrollable_expression_view.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
PrettyPrintView::PrettyPrintView(Responder * parentResponder) :
|
||||
ScrollableExpressionView::ScrollableExpressionView(Responder * parentResponder) :
|
||||
ScrollView(&m_expressionView, 0, 0, 0, 0, false),
|
||||
Responder(parentResponder),
|
||||
m_expressionView(ExpressionView()),
|
||||
@@ -11,34 +11,34 @@ PrettyPrintView::PrettyPrintView(Responder * parentResponder) :
|
||||
{
|
||||
}
|
||||
|
||||
void PrettyPrintView::setExpression(ExpressionLayout * expressionLayout) {
|
||||
void ScrollableExpressionView::setExpression(ExpressionLayout * expressionLayout) {
|
||||
m_expressionView.setExpression(expressionLayout);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void PrettyPrintView::setBackgroundColor(KDColor backgroundColor) {
|
||||
void ScrollableExpressionView::setBackgroundColor(KDColor backgroundColor) {
|
||||
m_expressionView.setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
void PrettyPrintView::layoutSubviews() {
|
||||
void ScrollableExpressionView::layoutSubviews() {
|
||||
m_expressionView.setSize(m_expressionView.minimalSizeForOptimalDisplay());
|
||||
ScrollView::layoutSubviews();
|
||||
}
|
||||
|
||||
KDSize PrettyPrintView::minimalSizeForOptimalDisplay() {
|
||||
KDSize ScrollableExpressionView::minimalSizeForOptimalDisplay() {
|
||||
return m_expressionView.minimalSizeForOptimalDisplay();
|
||||
}
|
||||
|
||||
void PrettyPrintView::reloadCell() {
|
||||
void ScrollableExpressionView::reloadCell() {
|
||||
m_manualScrolling = 0;
|
||||
setContentOffset(KDPoint(m_manualScrolling, 0));
|
||||
}
|
||||
|
||||
bool PrettyPrintView::rightViewIsInvisible() {
|
||||
bool ScrollableExpressionView::rightViewIsInvisible() {
|
||||
return m_expressionView.bounds().width() - m_manualScrolling > bounds().width();
|
||||
}
|
||||
|
||||
bool PrettyPrintView::handleEvent(Ion::Events::Event event) {
|
||||
bool ScrollableExpressionView::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::Right && rightViewIsInvisible()) {
|
||||
KDCoordinate rightSpace = m_expressionView.bounds().width() - m_manualScrolling - bounds().width();
|
||||
KDCoordinate scrollAdd = rightSpace > 10 ? 10 : rightSpace;
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef CALCULATION_PRETTY_PRINT_VIEW_H
|
||||
#define CALCULATION_PRETTY_PRINT_VIEW_H
|
||||
#ifndef CALCULATION_SCROLLABLE_EXPRESSION_VIEW_H
|
||||
#define CALCULATION_SCROLLABLE_EXPRESSION_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
class PrettyPrintView : public ScrollView, public Responder {
|
||||
class ScrollableExpressionView : public ScrollView, public Responder {
|
||||
public:
|
||||
PrettyPrintView(Responder * parentResponder);
|
||||
ScrollableExpressionView(Responder * parentResponder);
|
||||
void setExpression(ExpressionLayout * expressionLayout);
|
||||
void layoutSubviews() override;
|
||||
void setBackgroundColor(KDColor backgroundColor);
|
||||
@@ -48,7 +48,7 @@ void CalculationSelectableTableView::scrollToSubviewOfTypeOfCellAtLocation(Histo
|
||||
/* Main part of the scroll */
|
||||
KDCoordinate contentOffsetX = contentOffset().x();
|
||||
KDCoordinate contentOffsetY = contentOffset().y();
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
if (subviewType == HistoryViewCell::SubviewType::Input) {
|
||||
if (j == 0) {
|
||||
contentOffsetY = 0;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user