[apps/sequence] Fix title cell alignments

Add margin right of "un="
Align the text vertically so that the equal is vertically centered in
the cell. This makes the left and right cell baselines be approximately
at the same level for basic sequences definition (un = 1, un=1/2, ...)
This commit is contained in:
Léa Saviot
2018-11-28 14:21:41 +01:00
parent 0a9edf8a43
commit d87c0669cb
2 changed files with 19 additions and 7 deletions

View File

@@ -8,13 +8,18 @@ namespace Sequence {
SequenceTitleCell::SequenceTitleCell() :
Shared::FunctionTitleCell(Orientation::VerticalIndicator),
m_titleTextView(k_verticalOrientationHorizontalAlignment, 0.5f)
m_titleTextView(k_verticalOrientationHorizontalAlignment, k_horizontalOrientationAlignment)
{
}
void SequenceTitleCell::setOrientation(Orientation orientation) {
float horizontalAlignment = orientation == Orientation::VerticalIndicator ? k_verticalOrientationHorizontalAlignment : k_horizontalOrientationHorizontalAlignment;
m_titleTextView.setAlignment(horizontalAlignment, 0.5f);
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);
}
@@ -48,8 +53,15 @@ View * SequenceTitleCell::subviewAtIndex(int index) {
void SequenceTitleCell::layoutSubviews() {
KDRect textFrame(0, k_colorIndicatorThickness, bounds().width(), bounds().height() - k_colorIndicatorThickness);
if (m_orientation == Orientation::VerticalIndicator){
textFrame = KDRect(k_colorIndicatorThickness, 0, bounds().width() - k_colorIndicatorThickness, bounds().height()-k_separatorThickness);
if (m_orientation == Orientation::VerticalIndicator) {
KDCoordinate h = bounds().height()-k_separatorThickness;
textFrame = KDRect(k_colorIndicatorThickness, 0, bounds().width() - k_colorIndicatorThickness, h);
/* We try to align the text so that the equal is vertically centered in the
* cell. This makes the title cell and the definition cell baselines be
* approximately at the same level for basic sequences definitions (un = 1,
* un=1/2, ...). */
float verticalAlignment = 0.5f + 20.0f/((float)h); // 20.0f is a magic value
m_titleTextView.setAlignment(k_verticalOrientationHorizontalAlignment, verticalAlignment);
}
m_titleTextView.setFrame(textFrame);
}