diff --git a/apps/graph/values/value_cell.cpp b/apps/graph/values/value_cell.cpp index 548c36d3d..334e0fe1d 100644 --- a/apps/graph/values/value_cell.cpp +++ b/apps/graph/values/value_cell.cpp @@ -1,25 +1,35 @@ #include "value_cell.h" +#include "assert.h" namespace Graph { ValueCell::ValueCell() : EvenOddCell(), - m_float(Float(0.0f)) + m_bufferTextView(BufferTextView(1.0f, 0.5f)) { } -void ValueCell::setFloat(float f) { - m_float = Float(f); - m_float.convertFloatToText(m_buffer, 14, 7); +void ValueCell::reloadCell() { + EvenOddCell::reloadCell(); + m_bufferTextView.setBackgroundColor(backgroundColor()); } -void ValueCell::drawRect(KDContext * ctx, KDRect rect) const { - EvenOddCell::drawRect(ctx, rect); - // Write the content of the cell - KDColor background = backgroundColor(); - KDSize textSize = KDText::stringSize(m_buffer); - KDPoint origin(m_frame.width() - textSize.width(), 0.5f*(m_frame.height() - textSize.height())); - ctx->drawString(m_buffer, origin, KDColorBlack, background); +void ValueCell::setText(const char * textContent) { + m_bufferTextView.setText(textContent); +} + + +int ValueCell::numberOfSubviews() const { + return 1; +} + +View * ValueCell::subviewAtIndex(int index) { + assert(index == 0); + return &m_bufferTextView; +} + +void ValueCell::layoutSubviews() { + m_bufferTextView.setFrame(bounds()); } } diff --git a/apps/graph/values/value_cell.h b/apps/graph/values/value_cell.h index 5fc2a00e7..5a94027f0 100644 --- a/apps/graph/values/value_cell.h +++ b/apps/graph/values/value_cell.h @@ -9,12 +9,14 @@ namespace Graph { class ValueCell : public EvenOddCell { public: ValueCell(); - void setFloat(float f); - void drawRect(KDContext * ctx, KDRect rect) const override; + void reloadCell() override; + void setText(const char * textContent); + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; protected: - Float m_float; - char m_buffer[14]; + BufferTextView m_bufferTextView; }; } diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 6d4eecd3f..53477162f 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -210,12 +210,15 @@ void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) { } } else { ValueCell * myCell = (ValueCell *)cell; + char buffer[14]; if (i == 0){ - myCell->setFloat(m_interval.element(j-1)); + Float(m_interval.element(j-1)).convertFloatToText(buffer, 14, 7); + myCell->setText(buffer); } else { Function * function = m_functionStore->activeFunctionAtIndex(i-1); float x = m_interval.element(j-1); - myCell->setFloat(function->evaluateAtAbscissa(x, m_evaluateContext)); + Float(function->evaluateAtAbscissa(x, m_evaluateContext)).convertFloatToText(buffer, 14, 7); + myCell->setText(buffer); } myCell->setEven(j%2 == 0); }