mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-28 18:20:14 +01:00
[apps/calcul] create a cell to represent history line
Change-Id: Ib24189e510c10a5541b4ec83ce4dc286fba40706
This commit is contained in:
@@ -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
|
||||
|
||||
59
apps/calcul/history_view_cell.cpp
Normal file
59
apps/calcul/history_view_cell.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
28
apps/calcul/history_view_cell.h
Normal file
28
apps/calcul/history_view_cell.h
Normal 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
|
||||
Reference in New Issue
Block a user