From d87c0669cbf14749b4265ea8f17319aa24912674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 28 Nov 2018 14:21:41 +0100 Subject: [PATCH] [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, ...) --- apps/sequence/sequence_title_cell.cpp | 22 +++++++++++++++++----- apps/sequence/sequence_title_cell.h | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/sequence/sequence_title_cell.cpp b/apps/sequence/sequence_title_cell.cpp index 5c2eed39f..e7e3c6853 100644 --- a/apps/sequence/sequence_title_cell.cpp +++ b/apps/sequence/sequence_title_cell.cpp @@ -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); } diff --git a/apps/sequence/sequence_title_cell.h b/apps/sequence/sequence_title_cell.h index 262aa8715..db787b793 100644 --- a/apps/sequence/sequence_title_cell.h +++ b/apps/sequence/sequence_title_cell.h @@ -21,8 +21,8 @@ public: return m_titleTextView.layout(); } private: - static constexpr float k_horizontalOrientationHorizontalAlignment = 0.5f; - static constexpr float k_verticalOrientationHorizontalAlignment = 1.0f; + static constexpr float k_horizontalOrientationAlignment = 0.5f; + static constexpr float k_verticalOrientationHorizontalAlignment = 0.9f; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews() override;