From 74b5ca2f128959803442a4742e9d856b44aab576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 31 Dec 2019 10:33:37 +0100 Subject: [PATCH] [escher] ExpressionTableCellWithExpression: avoid to add margins around the accessory subview twice --- .../escher/expression_table_cell_with_expression.h | 2 ++ escher/include/escher/table_cell.h | 1 + escher/src/table_cell.cpp | 11 ++++++----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/escher/include/escher/expression_table_cell_with_expression.h b/escher/include/escher/expression_table_cell_with_expression.h index 6fb3ed5b6..be89f289f 100644 --- a/escher/include/escher/expression_table_cell_with_expression.h +++ b/escher/include/escher/expression_table_cell_with_expression.h @@ -12,6 +12,8 @@ public: void setAccessoryLayout(Poincare::Layout l); void didBecomeFirstResponder() override; private: + // Accessory margin is already handled in ScrollableExpressionView + KDCoordinate accessoryMargin() const override { return 0; } ScrollableExpressionView m_accessoryExpressionView; }; diff --git a/escher/include/escher/table_cell.h b/escher/include/escher/table_cell.h index eded3bc2e..a30cd08e7 100644 --- a/escher/include/escher/table_cell.h +++ b/escher/include/escher/table_cell.h @@ -24,6 +24,7 @@ public: void drawRect(KDContext * ctx, KDRect rect) const override; protected: virtual KDCoordinate labelMargin() const { return Metric::TableCellHorizontalMargin; } + virtual KDCoordinate accessoryMargin() const { return Metric::TableCellHorizontalMargin; } int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews(bool force = false) override; diff --git a/escher/src/table_cell.cpp b/escher/src/table_cell.cpp index 72cb5db62..9df058c2c 100644 --- a/escher/src/table_cell.cpp +++ b/escher/src/table_cell.cpp @@ -87,7 +87,7 @@ void TableCell::layoutSubviews(bool force) { * Horizontally: * || Line separator | margin* | SUBVIEW | margin* | Line separator || * - * * = margin can either be labelMargin() or k_horizontalMargin depending on the subview + * * = margin can either be labelMargin(), accessoryMargin() or k_horizontalMargin depending on the subview * * */ KDCoordinate horizontalMargin = k_separatorThickness + labelMargin(); @@ -105,6 +105,7 @@ void TableCell::layoutSubviews(bool force) { accessory->setFrame(KDRect(horizontalMargin, y, width - 2*horizontalMargin, subAccessoryHeight), force); y += subAccessoryHeight; } + horizontalMargin = k_separatorThickness + accessoryMargin(); y = maxCoordinate(y, height - k_separatorThickness - withMargin(accessorySize.height(), Metric::TableCellVerticalMargin)); if (accessory) { KDCoordinate accessoryHeight = minCoordinate(accessorySize.height(), height - y - k_separatorThickness - Metric::TableCellVerticalMargin); @@ -128,15 +129,15 @@ void TableCell::layoutSubviews(bool force) { * [ White space if possible otherwise the overlap can be from left to * right subviews or the contrary ] * - * ... | SUBACCESSORY | ACCESSORY | k_horizontalMarginĀ | Line separator || + * ... | SUBACCESSORY | ACCESSORY | Accessory marginĀ | Line separator || * * */ KDCoordinate verticalMargin = k_separatorThickness; KDCoordinate x = 0; KDCoordinate labelX = k_separatorThickness + labelMargin(); - KDCoordinate subAccessoryX = maxCoordinate(k_separatorThickness+k_horizontalMargin, width - k_separatorThickness - withMargin(accessorySize.width(), k_horizontalMargin) - withMargin(subAccessorySize.width(), 0)); - KDCoordinate accessoryX = maxCoordinate(k_separatorThickness+k_horizontalMargin, width - k_separatorThickness - withMargin(accessorySize.width(), k_horizontalMargin)); + KDCoordinate subAccessoryX = maxCoordinate(k_separatorThickness + k_horizontalMargin, width - k_separatorThickness - withMargin(accessorySize.width(), accessoryMargin()) - withMargin(subAccessorySize.width(), 0)); + KDCoordinate accessoryX = maxCoordinate(k_separatorThickness + accessoryMargin(), width - k_separatorThickness - withMargin(accessorySize.width(), accessoryMargin())); if (label) { x = labelX; KDCoordinate labelWidth = minCoordinate(labelSize.width(), width - x - k_separatorThickness - labelMargin()); @@ -157,7 +158,7 @@ void TableCell::layoutSubviews(bool force) { } if (accessory) { x = maxCoordinate(x, accessoryX); - KDCoordinate accessoryWidth = minCoordinate(accessorySize.width(), width - x - k_separatorThickness - k_horizontalMargin); + KDCoordinate accessoryWidth = minCoordinate(accessorySize.width(), width - x - k_separatorThickness - accessoryMargin()); accessory->setFrame(KDRect(x, verticalMargin, accessoryWidth, height-2*verticalMargin), force); } }