From 5d2763382128fb6ddbdc34ca803dc1b0f582d318 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 20 Oct 2022 14:51:09 -0300 Subject: [PATCH] fix: show a single line in ProjectItem's desc. when there's no more space Signed-off-by: flow --- launcher/ui/widgets/ProjectItem.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/launcher/ui/widgets/ProjectItem.cpp b/launcher/ui/widgets/ProjectItem.cpp index 49baf3e8..d1ff9dbc 100644 --- a/launcher/ui/widgets/ProjectItem.cpp +++ b/launcher/ui/widgets/ProjectItem.cpp @@ -89,13 +89,19 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o auto num_lines = 1; // Get second line, elided if needed - if (cut_text.size() > 1 && rect.height() - title_height > opt.fontMetrics.height() * 2) { - if (cut_text.size() > 2) { - description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first); + if (cut_text.size() > 1) { + // 2.5x so because there should be some margin left from the 2x so things don't get too squishy. + if (rect.height() - title_height <= 2.5 * opt.fontMetrics.height()) { + // If there's not enough space, show only a single line, elided. + description = opt.fontMetrics.elidedText(description, opt.textElideMode, cut_text.at(0).first); } else { - description += cut_text.at(1).second; + if (cut_text.size() > 2) { + description += opt.fontMetrics.elidedText(cut_text.at(1).second, opt.textElideMode, cut_text.at(1).first); + } else { + description += cut_text.at(1).second; + } + num_lines += 1; } - num_lines += 1; } int description_x = rect.x();