mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:12:45 +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:
		
							parent
							
								
									0f1235be25
								
							
						
					
					
						commit
						97c42694db
					
				
					 3 changed files with 14 additions and 8 deletions
				
			
		|  | @ -96,6 +96,8 @@ void ColumnsView::paint_event(PaintEvent& event) | |||
| 
 | ||||
|     int column_x = 0; | ||||
| 
 | ||||
|     auto selection_color = is_focused() ? palette().selection() : palette().inactive_selection(); | ||||
| 
 | ||||
|     for (size_t i = 0; i < m_columns.size(); i++) { | ||||
|         auto& column = m_columns[i]; | ||||
|         auto* next_column = i + 1 == m_columns.size() ? nullptr : &m_columns[i + 1]; | ||||
|  | @ -118,8 +120,8 @@ void ColumnsView::paint_event(PaintEvent& event) | |||
|             } | ||||
| 
 | ||||
|             if (is_selected_row) { | ||||
|                 background_color = palette().selection(); | ||||
|                 text_color = palette().selection_text(); | ||||
|                 background_color = selection_color; | ||||
|                 text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); | ||||
|             } | ||||
| 
 | ||||
|             Gfx::IntRect row_rect { column_x, row * item_height(), column.width, item_height() }; | ||||
|  | @ -131,7 +133,7 @@ void ColumnsView::paint_event(PaintEvent& event) | |||
|             if (icon.is_icon()) { | ||||
|                 if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { | ||||
|                     if (is_selected_row) { | ||||
|                         auto tint = palette().selection().with_alpha(100); | ||||
|                         auto tint = selection_color.with_alpha(100); | ||||
|                         painter.blit_filtered(icon_rect.location(), *bitmap, bitmap->rect(), [&](auto src) { return src.blend(tint); }); | ||||
|                     } else if (m_hovered_index.is_valid() && m_hovered_index.parent() == index.parent() && m_hovered_index.row() == index.row()) { | ||||
|                         painter.blit_brightened(icon_rect.location(), *bitmap, bitmap->rect()); | ||||
|  |  | |||
|  | @ -517,10 +517,12 @@ void IconView::paint_event(PaintEvent& event) | |||
|     painter.translate(frame_thickness(), frame_thickness()); | ||||
|     painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value()); | ||||
| 
 | ||||
|     auto selection_color = is_focused() ? palette().selection() : palette().inactive_selection(); | ||||
| 
 | ||||
|     for_each_item_intersecting_rect(to_content_rect(event.rect()), [&](auto& item_data) -> IterationDecision { | ||||
|         Color background_color; | ||||
|         if (item_data.selected) { | ||||
|             background_color = is_focused() ? palette().selection() : palette().inactive_selection(); | ||||
|             background_color = selection_color; | ||||
|         } else { | ||||
|             if (fill_with_background_color()) | ||||
|                 background_color = widget_background_color; | ||||
|  | @ -534,7 +536,7 @@ void IconView::paint_event(PaintEvent& event) | |||
|                 destination.center_within(item_data.icon_rect); | ||||
| 
 | ||||
|                 if (item_data.selected) { | ||||
|                     auto tint = palette().selection().with_alpha(100); | ||||
|                     auto tint = selection_color.with_alpha(100); | ||||
|                     painter.blit_filtered(destination.location(), *bitmap, bitmap->rect(), [&](auto src) { return src.blend(tint); }); | ||||
|                 } else if (m_hovered_index.is_valid() && m_hovered_index == item_data.index) { | ||||
|                     painter.blit_brightened(destination.location(), *bitmap, bitmap->rect()); | ||||
|  |  | |||
|  | @ -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()); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling