mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/calculation] Handle calculation to heigh to be fully displayed in
the screen Change-Id: I182f0c76d911e6686223a22be2a6ddb561b287ec
This commit is contained in:
@@ -41,10 +41,10 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
{
|
||||
int focusRow = m_selectableTableView.selectedRow();
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
|
||||
HistoryViewCell::SelectedView selectedSubview = selectedCell->selectedView();
|
||||
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
|
||||
EditExpressionController * editController = (EditExpressionController *)parentResponder();
|
||||
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
|
||||
if (selectedSubview == HistoryViewCell::SelectedView::PrettyPrint) {
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
editController->setTextBody(calculation->text());
|
||||
} else {
|
||||
char buffer[Constant::FloatBufferSizeInScientificMode];
|
||||
@@ -59,11 +59,11 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
{
|
||||
int focusRow = m_selectableTableView.selectedRow();
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
|
||||
HistoryViewCell::SelectedView selectedSubview = selectedCell->selectedView();
|
||||
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
|
||||
EditExpressionController * editController = (EditExpressionController *)parentResponder();
|
||||
Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow);
|
||||
Calculation newCalculation;
|
||||
if (selectedSubview == HistoryViewCell::SelectedView::PrettyPrint) {
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
newCalculation = *calculation;
|
||||
} else {
|
||||
char buffer[Constant::FloatBufferSizeInScientificMode];
|
||||
@@ -82,7 +82,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
{
|
||||
int focusRow = m_selectableTableView.selectedRow();
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)m_selectableTableView.cellAtLocation(0, focusRow);
|
||||
HistoryViewCell::SelectedView selectedSubview = selectedCell->selectedView();
|
||||
HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType();
|
||||
EditExpressionController * editController = (EditExpressionController *)parentResponder();
|
||||
m_calculationStore->deleteCalculationAtIndex(focusRow);
|
||||
m_selectableTableView.deselectTable();
|
||||
@@ -96,7 +96,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
|
||||
} else {
|
||||
m_selectableTableView.selectCellAtLocation(0, 0);
|
||||
}
|
||||
if (selectedSubview == HistoryViewCell::SelectedView::PrettyPrint) {
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
tableViewDidChangeSelection(&m_selectableTableView, 0, m_selectableTableView.selectedRow());
|
||||
} else {
|
||||
tableViewDidChangeSelection(&m_selectableTableView, 0, -1);
|
||||
@@ -120,13 +120,13 @@ void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)(t->selectedCell());
|
||||
selectedCell->setParentResponder(t);
|
||||
if (m_selectableTableView.selectedRow() < previousSelectedCellY) {
|
||||
selectedCell->setSelectedView(HistoryViewCell::SelectedView::Result);
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
|
||||
}
|
||||
if (m_selectableTableView.selectedRow() >= previousSelectedCellY) {
|
||||
selectedCell->setSelectedView(HistoryViewCell::SelectedView::PrettyPrint);
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::PrettyPrint);
|
||||
}
|
||||
if (previousSelectedCellY == -1) {
|
||||
selectedCell->setSelectedView(HistoryViewCell::SelectedView::Result);
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
|
||||
}
|
||||
app()->setFirstResponder(selectedCell);
|
||||
selectedCell->reloadCell();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "history_view_cell.h"
|
||||
#include "../constant.h"
|
||||
#include "selectable_table_view.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -9,7 +10,7 @@ HistoryViewCell::HistoryViewCell() :
|
||||
Responder(nullptr),
|
||||
m_prettyPrint(PrettyPrintView(this)),
|
||||
m_result(BufferTextView(1.0f, 0.5f)),
|
||||
m_selectedView(HistoryViewCell::SelectedView::Result)
|
||||
m_selectedSubviewType(HistoryViewCell::SubviewType::Result)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,7 +61,7 @@ void HistoryViewCell::reloadCell() {
|
||||
m_result.setBackgroundColor(backgroundColor());
|
||||
m_prettyPrint.setBackgroundColor(backgroundColor());
|
||||
if (isHighlighted()) {
|
||||
if (m_selectedView == HistoryViewCell::SelectedView::Result) {
|
||||
if (m_selectedSubviewType == HistoryViewCell::SubviewType::Result) {
|
||||
m_result.setBackgroundColor(Palette::FocusCellBackgroundColor);
|
||||
} else {
|
||||
m_prettyPrint.setBackgroundColor(Palette::FocusCellBackgroundColor);
|
||||
@@ -72,34 +73,40 @@ void HistoryViewCell::reloadCell() {
|
||||
}
|
||||
|
||||
void HistoryViewCell::didBecomeFirstResponder() {
|
||||
if (m_selectedView == HistoryViewCell::SelectedView::PrettyPrint) {
|
||||
if (m_selectedSubviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
app()->setFirstResponder(&m_prettyPrint);
|
||||
}
|
||||
}
|
||||
|
||||
HistoryViewCell::SelectedView HistoryViewCell::selectedView() {
|
||||
return m_selectedView;
|
||||
HistoryViewCell::SubviewType HistoryViewCell::selectedSubviewType() {
|
||||
return m_selectedSubviewType;
|
||||
}
|
||||
|
||||
void HistoryViewCell::setSelectedView(HistoryViewCell::SelectedView selectedView) {
|
||||
m_selectedView = selectedView;
|
||||
void HistoryViewCell::setSelectedSubviewType(HistoryViewCell::SubviewType subviewType) {
|
||||
m_selectedSubviewType = subviewType;
|
||||
}
|
||||
|
||||
bool HistoryViewCell::handleEvent(Ion::Events::Event event) {
|
||||
switch (event) {
|
||||
case Ion::Events::Event::DOWN_ARROW:
|
||||
if (m_selectedView == HistoryViewCell::SelectedView::PrettyPrint) {
|
||||
m_selectedView = HistoryViewCell::SelectedView::Result;
|
||||
app()->setFirstResponder(this);
|
||||
reloadCell();
|
||||
if (m_selectedSubviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
CalculationSelectableTableView * tableView = (CalculationSelectableTableView *)parentResponder();
|
||||
tableView->scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType::Result, tableView->selectedColumn(), tableView->selectedRow());
|
||||
HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
|
||||
selectedCell->setSelectedSubviewType(HistoryViewCell::SubviewType::Result);
|
||||
app()->setFirstResponder(selectedCell);
|
||||
selectedCell->reloadCell();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case Ion::Events::Event::UP_ARROW:
|
||||
if (m_selectedView == HistoryViewCell::SelectedView::Result) {
|
||||
m_selectedView = HistoryViewCell::SelectedView::PrettyPrint;
|
||||
app()->setFirstResponder(&m_prettyPrint);
|
||||
reloadCell();
|
||||
if (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);
|
||||
app()->setFirstResponder(selectedCell);
|
||||
selectedCell->reloadCell();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Calculation {
|
||||
|
||||
class HistoryViewCell : public ::EvenOddCell, public Responder {
|
||||
public:
|
||||
enum class SelectedView {
|
||||
enum class SubviewType {
|
||||
PrettyPrint,
|
||||
Result
|
||||
};
|
||||
@@ -24,13 +24,13 @@ public:
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
constexpr static KDCoordinate k_digitHorizontalMargin = 10;
|
||||
constexpr static KDCoordinate k_digitVerticalMargin = 5;
|
||||
SelectedView selectedView();
|
||||
void setSelectedView(HistoryViewCell::SelectedView selectedView);
|
||||
SubviewType selectedSubviewType();
|
||||
void setSelectedSubviewType(HistoryViewCell::SubviewType subviewType);
|
||||
private:
|
||||
constexpr static KDCoordinate k_resultWidth = 80;
|
||||
PrettyPrintView m_prettyPrint;
|
||||
BufferTextView m_result;
|
||||
SelectedView m_selectedView;
|
||||
SubviewType m_selectedSubviewType;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,52 @@ void CalculationSelectableTableView::scrollToCell(int i, int j) {
|
||||
KDCoordinate contentOffsetY = dataSource()->cumulatedHeightFromIndex(dataSource()->numberOfRows()) - maxContentHeightDisplayableWithoutScrolling();
|
||||
setContentOffset(KDPoint(contentOffsetX, contentOffsetY));
|
||||
}
|
||||
if (dataSource()->rowHeight(j) > bounds().height()) {
|
||||
KDCoordinate contentOffsetX = contentOffset().x();
|
||||
KDCoordinate contentOffsetY = contentOffset().y();
|
||||
if (contentOffset().y() > dataSource()->cumulatedHeightFromIndex(j) && contentOffset().y() > dataSource()->cumulatedHeightFromIndex(j+1)) {
|
||||
// Let's scroll the tableView to align the top of the cell to the top
|
||||
contentOffsetY = dataSource()->cumulatedHeightFromIndex(j);
|
||||
} else {
|
||||
// Let's scroll the tableView to align the bottom of the cell to the bottom
|
||||
contentOffsetY = dataSource()->cumulatedHeightFromIndex(j+1) - maxContentHeightDisplayableWithoutScrolling();
|
||||
}
|
||||
setContentOffset(KDPoint(contentOffsetX, contentOffsetY));
|
||||
}
|
||||
}
|
||||
|
||||
void CalculationSelectableTableView::scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType subviewType, int i, int j) {
|
||||
if (dataSource()->rowHeight(j) <= bounds().height()) {
|
||||
return;
|
||||
}
|
||||
/* As we scroll, the selected calculation does not use the same history view
|
||||
* cell, thus, we want to deselect the previous used history view cell. */
|
||||
if (selectedRow() >= 0) {
|
||||
TableViewCell * previousCell = cellAtLocation(selectedColumn(), selectedRow());
|
||||
previousCell->setHighlighted(false);
|
||||
}
|
||||
/* Main part of the scroll */
|
||||
KDCoordinate contentOffsetX = contentOffset().x();
|
||||
KDCoordinate contentOffsetY = contentOffset().y();
|
||||
if (subviewType == HistoryViewCell::SubviewType::PrettyPrint) {
|
||||
if (j == 0) {
|
||||
contentOffsetY = 0;
|
||||
} else {
|
||||
contentOffsetY = dataSource()->cumulatedHeightFromIndex(j);
|
||||
}
|
||||
} else {
|
||||
contentOffsetY = dataSource()->cumulatedHeightFromIndex(j+1) - maxContentHeightDisplayableWithoutScrolling();
|
||||
}
|
||||
/* For the same reason, we have to rehighlight the new history view cell and
|
||||
* inform the delegate which history view cell is highlighted even if the
|
||||
* selected calculation has not changed. */
|
||||
setContentOffset(KDPoint(contentOffsetX, contentOffsetY));
|
||||
TableViewCell * cell = cellAtLocation(i, j);
|
||||
cell->setHighlighted(true);
|
||||
if (m_delegate) {
|
||||
m_delegate->tableViewDidChangeSelection(this, selectedColumn(), selectedRow());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CALCULATION_SELECTABLE_TABLE_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
#include "history_view_cell.h"
|
||||
namespace Calculation {
|
||||
|
||||
class CalculationSelectableTableView : public ::SelectableTableView {
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
CalculationSelectableTableView(Responder * parentResponder, TableViewDataSource * dataSource,
|
||||
SelectableTableViewDelegate * delegate = nullptr);
|
||||
void scrollToCell(int i, int j) override;
|
||||
void scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType subviewType, int i, int j);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@ public:
|
||||
void deselectTable();
|
||||
bool selectCellAtLocation(int i, int j);
|
||||
TableViewCell * selectedCell();
|
||||
protected:
|
||||
SelectableTableViewDelegate * m_delegate;
|
||||
private:
|
||||
int m_selectedCellX;
|
||||
int m_selectedCellY;
|
||||
SelectableTableViewDelegate * m_delegate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,9 +5,9 @@ SelectableTableView::SelectableTableView(Responder * parentResponder, TableViewD
|
||||
SelectableTableViewDelegate * delegate) :
|
||||
TableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin),
|
||||
Responder(parentResponder),
|
||||
m_delegate(delegate),
|
||||
m_selectedCellX(0),
|
||||
m_selectedCellY(-1),
|
||||
m_delegate(delegate)
|
||||
m_selectedCellY(-1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user