mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
LibGUI: Programatically draw table header sorting arrows
These arrows were previously drawn using the code points U+2B06 and U+2B07. The .png files for these emoji were removed in commitbfe99eb
and added to the Katica Regular 10 font in commitcf62d08
. The emoji were not added to the bold Katica variants that are used by the table header view. The effect is that a "?" replacement character was rendered. Instead of rendering the emoji, we can draw the arrows programatically, like we do in other GUI components (e.g. the scrollbar).
This commit is contained in:
parent
e746360b9a
commit
32642394a9
4 changed files with 32 additions and 17 deletions
|
@ -264,22 +264,22 @@ void HeaderView::paint_horizontal(Painter& painter)
|
|||
bool pressed = section == m_pressed_section && m_pressed_section_is_pressed;
|
||||
bool hovered = section == m_hovered_section && model()->is_column_sortable(section);
|
||||
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
|
||||
String text;
|
||||
if (is_key_column) {
|
||||
StringBuilder builder;
|
||||
builder.append(model()->column_name(section));
|
||||
if (m_table_view.sort_order() == SortOrder::Ascending)
|
||||
builder.append(" \xE2\xAC\x86"sv); // UPWARDS BLACK ARROW
|
||||
else if (m_table_view.sort_order() == SortOrder::Descending)
|
||||
builder.append(" \xE2\xAC\x87"sv); // DOWNWARDS BLACK ARROW
|
||||
text = builder.to_string();
|
||||
} else {
|
||||
text = model()->column_name(section);
|
||||
}
|
||||
|
||||
auto text = model()->column_name(section);
|
||||
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
|
||||
if (pressed)
|
||||
text_rect.translate_by(1, 1);
|
||||
painter.draw_text(text_rect, text, font(), section_data.alignment, palette().button_text());
|
||||
|
||||
if (is_key_column && (m_table_view.sort_order() != SortOrder::None)) {
|
||||
Gfx::IntPoint offset { text_rect.x() + font().width(text) + sorting_arrow_offset, sorting_arrow_offset };
|
||||
auto coordinates = m_table_view.sort_order() == SortOrder::Ascending
|
||||
? ascending_arrow_coordinates.span()
|
||||
: descending_arrow_coordinates.span();
|
||||
|
||||
painter.draw_triangle(offset, coordinates, palette().button_text());
|
||||
}
|
||||
|
||||
x_offset += section_width + m_table_view.horizontal_padding() * 2;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue