From 25ab4b2a52e458875ea6792327152e28526e9fab Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 1 Oct 2020 12:03:22 +0200 Subject: [PATCH] [shared/localization_controller] Table cropping Forced the top cell of the country table to be cropped in the middle, cutting the text, to avoid the cell looking squashed. Change-Id: I4d126ed19249f47652bd7f2001384b2491cfe6f8 --- apps/shared/localization_controller.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/shared/localization_controller.cpp b/apps/shared/localization_controller.cpp index fc655badf..92ff1bd2c 100644 --- a/apps/shared/localization_controller.cpp +++ b/apps/shared/localization_controller.cpp @@ -56,7 +56,6 @@ void LocalizationController::ContentView::layoutSubviews(bool force) { } if (m_controller->shouldDisplayWarning()) { origin = layoutWarningSubview(force, Metric::CommonTopMargin + origin) + Metric::CommonTopMargin; - m_borderView.setFrame(KDRect(Metric::CommonLeftMargin, origin, bounds().width() - Metric::CommonLeftMargin - Metric::CommonRightMargin, Metric::CellSeparatorThickness), force); } origin = layoutTableSubview(force, origin); assert(origin <= bounds().height()); @@ -82,6 +81,20 @@ KDCoordinate LocalizationController::ContentView::layoutTableSubview(bool force, KDCoordinate tableHeight = std::min( bounds().height() - verticalOrigin, m_selectableTableView.minimalSizeForOptimalDisplay().height()); + KDCoordinate tableHeightSansMargin = tableHeight - m_selectableTableView.bottomMargin(); + + if (m_controller->shouldDisplayWarning()) { + /* If the top cell is cut, bot not enough to hide part of the text, it will + * appear squashed. To prevent that, we increase the top margin slightly, + * so that the top cell will be cropped in the middle. */ + KDCoordinate rowHeight = m_controller->cellHeight() + Metric::CellSeparatorThickness; + KDCoordinate incompleteCellHeight = tableHeightSansMargin - (tableHeightSansMargin / rowHeight) * rowHeight; + KDCoordinate offset = std::max(0, incompleteCellHeight - rowHeight / 2); + tableHeight -= offset; + verticalOrigin += offset; + + m_borderView.setFrame(KDRect(Metric::CommonLeftMargin, verticalOrigin, bounds().width() - Metric::CommonLeftMargin - Metric::CommonRightMargin, Metric::CellSeparatorThickness), force); + } m_selectableTableView.setFrame(KDRect(0, verticalOrigin, bounds().width(), tableHeight), force); return verticalOrigin + tableHeight; }