mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 09:40:07 +01:00
[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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user