From 43fc9374698ab2c10cde73fbb3b77efefc586adc Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Wed, 17 Jun 2020 17:37:46 +0200 Subject: [PATCH] [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 --- apps/sequence/sequence_title_cell.cpp | 11 +++++++++++ apps/sequence/sequence_title_cell.h | 1 + 2 files changed, 12 insertions(+) diff --git a/apps/sequence/sequence_title_cell.cpp b/apps/sequence/sequence_title_cell.cpp index f1802b10a..aeabfec6a 100644 --- a/apps/sequence/sequence_title_cell.cpp +++ b/apps/sequence/sequence_title_cell.cpp @@ -43,6 +43,16 @@ void SequenceTitleCell::setColor(KDColor 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; } @@ -53,6 +63,7 @@ View * SequenceTitleCell::subviewAtIndex(int index) { } void SequenceTitleCell::layoutSubviews(bool force) { + assert(TreeNode::IsValidIdentifier(layout().identifier())); if (m_orientation == Orientation::VerticalIndicator) { m_titleTextView.setAlignment(k_verticalOrientationHorizontalAlignment, verticalAlignment()); } diff --git a/apps/sequence/sequence_title_cell.h b/apps/sequence/sequence_title_cell.h index b858fe1a0..db5c7c209 100644 --- a/apps/sequence/sequence_title_cell.h +++ b/apps/sequence/sequence_title_cell.h @@ -20,6 +20,7 @@ public: Poincare::Layout layout() const override { return m_titleTextView.layout(); } + void reloadCell() override; private: static constexpr float k_horizontalOrientationAlignment = 0.5f; static constexpr float k_verticalOrientationHorizontalAlignment = 0.9f;