summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmusedNetwork <joseph@bywater.xyz>2020-11-07 16:52:57 +0000
committerAndreas Kling <kling@serenityos.org>2020-11-10 09:54:18 +0100
commiteac0344ef08cb249a90a0495b24235ea8bfb1315 (patch)
tree66cec2487e4f6477bfad238727cb2ab01184bf72
parent1041ab88ca8fd4b0385bcb9a2123d6eae9ad7c35 (diff)
downloadserenity-eac0344ef08cb249a90a0495b24235ea8bfb1315.zip
LibGUI: Limit the height of item text in IconView
Set the max height of the text_rect to be the height difference between two icons. Calculate the number of text lines that can be displayed in this height, and display only that many.
-rw-r--r--Libraries/LibGUI/IconView.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/Libraries/LibGUI/IconView.cpp b/Libraries/LibGUI/IconView.cpp
index 9c4255d5f2..c116520697 100644
--- a/Libraries/LibGUI/IconView.cpp
+++ b/Libraries/LibGUI/IconView.cpp
@@ -523,17 +523,22 @@ void IconView::paint_event(PaintEvent& event)
auto font = font_for_index(item_data.index);
- painter.fill_rect(item_data.text_rect, background_color);
+ Gfx::IntRect text_rect = item_data.text_rect;
+ auto icon_translation = translation.y() - 12;
+ text_rect.set_height(text_rect.height() > icon_translation ? icon_translation : text_rect.height());
+
+ painter.fill_rect(text_rect, background_color);
if (is_focused() && item_data.index == cursor_index()) {
- painter.draw_rect(item_data.text_rect, widget_background_color);
- painter.draw_focus_rect(item_data.text_rect, palette().focus_outline());
+ painter.draw_rect(text_rect, widget_background_color);
+ painter.draw_focus_rect(text_rect, palette().focus_outline());
}
if (!item_data.wrapped_text_lines.is_empty()) {
// Item text would not fit in the item text rect, let's break it up into lines..
const auto& lines = item_data.wrapped_text_lines;
- for (size_t line_index = 0; line_index < lines.size(); ++line_index) {
+ size_t number_of_text_lines = min((size_t)icon_translation / font->glyph_height(), lines.size());
+ for (size_t line_index = 0; line_index < number_of_text_lines; ++line_index) {
Gfx::IntRect line_rect;
line_rect.set_width(item_data.text_rect.width());
line_rect.set_height(font->glyph_height());
@@ -541,6 +546,10 @@ void IconView::paint_event(PaintEvent& event)
line_rect.set_y(2 + item_data.text_rect.y() + line_index * font->glyph_height());
line_rect.inflate(6, 0);
+ // Shrink the line_rect on the last line to apply elision if there are more lines.
+ if (number_of_text_lines - 1 == line_index && lines.size() > number_of_text_lines)
+ line_rect.inflate(-(6 + 2 * font->max_glyph_width()), 0);
+
draw_item_text(painter, item_data.index, item_data.selected, line_rect, lines[line_index], font, Gfx::TextAlignment::Center, Gfx::TextElision::Right);
}
} else {