1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 13:54:57 +00:00

LibGUI: Make selected item tint color based on focused state

Use the inactive selection color for item icon tinting when the item
view is not focused.
This commit is contained in:
Andreas Kling 2020-12-28 01:14:01 +01:00
parent 0f1235be25
commit 97c42694db
3 changed files with 14 additions and 8 deletions

View file

@ -66,6 +66,8 @@ void TableView::paint_event(PaintEvent& event)
if (!model())
return;
auto selection_color = is_focused() ? palette().selection() : palette().inactive_selection();
int exposed_width = max(content_size().width(), width());
int x_offset = row_header().is_visible() ? row_header().width() : 0;
int y_offset = column_header().is_visible() ? column_header().height() : 0;
@ -88,8 +90,8 @@ void TableView::paint_event(PaintEvent& event)
Color background_color;
Color key_column_background_color;
if (is_selected_row && highlight_selected_rows()) {
background_color = is_focused() ? palette().selection() : palette().inactive_selection();
key_column_background_color = is_focused() ? palette().selection() : palette().inactive_selection();
background_color = selection_color;
key_column_background_color = selection_color;
} else {
if (alternating_row_colors() && (painted_item_index % 2)) {
background_color = widget_background_color.darkened(0.8f);
@ -124,7 +126,7 @@ void TableView::paint_event(PaintEvent& event)
} else if (data.is_icon()) {
if (auto bitmap = data.as_icon().bitmap_for_size(16)) {
if (is_selected_row) {
auto tint = palette().selection().with_alpha(100);
auto tint = selection_color.with_alpha(100);
painter.blit_filtered(cell_rect.location(), *bitmap, bitmap->rect(), [&](auto src) { return src.blend(tint); });
} else if (m_hovered_index.is_valid() && cell_index.row() == m_hovered_index.row()) {
painter.blit_brightened(cell_rect.location(), *bitmap, bitmap->rect());