[apps/calcul] create a cell to represent history line

Change-Id: Ib24189e510c10a5541b4ec83ce4dc286fba40706
This commit is contained in:
Émilie Feral
2016-10-21 13:40:15 +01:00
parent 7fdc7de746
commit 3aad29019e
3 changed files with 88 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ app_objs += $(addprefix apps/calcul/,\
app.o\
calcul_controller.o\
calcul.o\
history_view_cell.o\
)
inline_images += apps/calcul/calcul_icon.png

View File

@@ -0,0 +1,59 @@
#include "history_view_cell.h"
#include <assert.h>
#include <string.h>
namespace Calcul {
HistoryViewCell::HistoryViewCell() :
m_calcul(nullptr),
m_highlighted(false),
m_result(BufferTextView(1.0f, 0.5f))
{
}
int HistoryViewCell::numberOfSubviews() const {
return 1;
}
View * HistoryViewCell::subviewAtIndex(int index) {
assert(index == 0);
return &m_result;
}
void HistoryViewCell::layoutSubviews() {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
// Position the result
KDSize prettyPrintSize = KDSize(0,0);
if (m_calcul && m_calcul->layout() != nullptr) {
prettyPrintSize = m_calcul->layout()->size();
}
KDRect resultFrame(prettyPrintSize.width(), 0, width - prettyPrintSize.width(), height);
m_result.setFrame(resultFrame);
}
void HistoryViewCell::setCalcul(Calcul * calcul) {
m_calcul = calcul;
char buffer[7];
m_calcul->evaluation()->convertFloatToText(buffer, 14, 7);
m_result.setText(buffer);
}
void HistoryViewCell::setHighlighted(bool highlight) {
m_highlighted = highlight;
KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_result.setBackgroundColor(backgroundColor);
markRectAsDirty(bounds());
}
void HistoryViewCell::drawRect(KDContext * ctx, KDRect rect) const {
// Select background color
KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
ctx->fillRect(rect, backgroundColor);
// Draw the pretty print
if (m_calcul && m_calcul->layout() != nullptr) {
m_calcul->layout()->draw(ctx, KDPointZero, KDColorBlack, backgroundColor);
}
}
}

View File

@@ -0,0 +1,28 @@
#ifndef CALCUL_HISTORY_VIEW_CELL_H
#define CALCUL_HISTORY_VIEW_CELL_H
#include <escher.h>
#include "calcul.h"
namespace Calcul {
class HistoryViewCell : public View {
public:
HistoryViewCell();
BufferTextView * result();
void setCalcul(Calcul * calcul);
void setHighlighted(bool highlight);
void drawRect(KDContext * ctx, KDRect rect) const override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
private:
Calcul * m_calcul;
bool m_highlighted;
BufferTextView m_result;
};
}
#endif