-
Notifications
You must be signed in to change notification settings - Fork 12
/
list_atomic_cell.cpp
50 lines (38 loc) · 1.67 KB
/
list_atomic_cell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "list_atomic_cell.h"
#include <poincare/integer.h>
#include <poincare/number.h>
namespace Atomic {
ListAtomicCell::ListAtomicCell()
{
}
void ListAtomicCell::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
ctx->fillRect(m_atomRect(), Palette::GrayMiddle);
KDPoint symbolPoint(m_atomRect().x() + m_atomRect().width() / 2 - KDFont::LargeFont->stringSize(m_atom.symbol).width() / 2,
m_atomRect().y() + m_atomRect().height() / 2 - KDFont::LargeFont->stringSize(m_atom.symbol).height() / 2);
ctx->drawString(m_atom.symbol, symbolPoint, KDFont::LargeFont, KDColorBlack, Palette::GrayMiddle);
char protons[4];
Poincare::Integer(m_atom.num).serialize(protons, 4);
KDPoint protonsPoint(m_atomRect().right() - KDFont::LargeFont->stringSize(protons).width() - k_padding,
m_atomRect().top() + k_padding);
ctx->drawString(protons, protonsPoint, KDFont::SmallFont, KDColorBlack, Palette::GrayMiddle);
KDPoint massPoint(m_atomRect().bottomLeft().x() + k_padding, m_atomRect().bottomLeft().y() - KDFont::SmallFont->glyphSize().height());
char mass[12];
Poincare::Number::FloatNumber(m_atom.mass).serialize(mass, 12);
mass[8] = 0;
ctx->drawString(mass, massPoint, KDFont::SmallFont, KDColorBlack, Palette::GrayMiddle);
}
View * ListAtomicCell::subviewAtIndex(int index) {
assert(false);
return nullptr;
}
void ListAtomicCell::setAtom(AtomDef atom) {
m_atom = atom;
markRectAsDirty(bounds());
}
KDRect ListAtomicCell::m_atomRect() const {
return KDRect((bounds().left() + (bounds().width()- k_width) / 2), bounds().top() + k_margin, k_width, bounds().height() - 2*k_margin);
}
void ListAtomicCell::layoutSubviews(bool force) {
}
}