Files
Upsilon/apps/sequence/sequence_title_cell.cpp
Gabriel Ozouf 43fc937469 [apps/sequence] SequenceTitleCell reload
SequenceTitleCell::reloadCell now triggers a layoutSubviews, causing the
vertical alignment to be recomputed. This solves issues regarding the
alignment of a sequence's name and definition, such as :
  - typing u_n = v_n ; v_n would be displayed above u_n
  - typing u_n = (1/3)/2 then changing to u_n = 1/(2/3) without erasing
    the formula first. u_n would no longer be aligned with the = sign.

Change-Id: I4a771d96ea79e42e2f4822e93f9f1cbbcf867610
2020-11-04 14:45:34 +01:00

80 lines
2.5 KiB
C++

#include "sequence_title_cell.h"
#include <assert.h>
using namespace Shared;
using namespace Poincare;
namespace Sequence {
SequenceTitleCell::SequenceTitleCell() :
Shared::FunctionTitleCell(Orientation::VerticalIndicator),
m_titleTextView(k_verticalOrientationHorizontalAlignment, k_horizontalOrientationAlignment)
{
m_titleTextView.setRightMargin(3);
}
void SequenceTitleCell::setOrientation(Orientation orientation) {
if (orientation == Orientation::VerticalIndicator) {
/* We do not care here about the vertical alignment, it will be set properly
* in layoutSubviews */
m_titleTextView.setAlignment(k_verticalOrientationHorizontalAlignment, k_verticalOrientationHorizontalAlignment);
} else {
m_titleTextView.setAlignment(k_horizontalOrientationAlignment, k_horizontalOrientationAlignment);
}
FunctionTitleCell::setOrientation(orientation);
}
void SequenceTitleCell::setLayout(Poincare::Layout layout) {
m_titleTextView.setLayout(layout);
}
void SequenceTitleCell::setHighlighted(bool highlight) {
EvenOddCell::setHighlighted(highlight);
m_titleTextView.setHighlighted(highlight);
}
void SequenceTitleCell::setEven(bool even) {
EvenOddCell::setEven(even);
m_titleTextView.setEven(even);
}
void SequenceTitleCell::setColor(KDColor color) {
Shared::FunctionTitleCell::setColor(color);
m_titleTextView.setTextColor(color);
}
void SequenceTitleCell::reloadCell() {
/* When creating a new sequence, the layout has not yet been initialized, but
* it is needed in layoutSubview to compute the vertical alignment. */
if (TreeNode::IsValidIdentifier(layout().identifier())) {
layoutSubviews();
}
m_titleTextView.reloadCell();
FunctionTitleCell::reloadCell();
}
int SequenceTitleCell::numberOfSubviews() const {
return 1;
}
View * SequenceTitleCell::subviewAtIndex(int index) {
assert(index == 0);
return &m_titleTextView;
}
void SequenceTitleCell::layoutSubviews(bool force) {
assert(TreeNode::IsValidIdentifier(layout().identifier()));
if (m_orientation == Orientation::VerticalIndicator) {
m_titleTextView.setAlignment(k_verticalOrientationHorizontalAlignment, verticalAlignment());
}
m_titleTextView.setFrame(subviewFrame(), force);
}
float SequenceTitleCell::verticalAlignmentGivenExpressionBaselineAndRowHeight(KDCoordinate expressionBaseline, KDCoordinate rowHeight) const {
assert(m_orientation == Orientation::VerticalIndicator);
Layout l = layout();
return ((float)(expressionBaseline - l.baseline()))/((float)rowHeight-l.layoutSize().height());
}
}