LibGUI: Add ModelRole::IconOpacity and support it in all views :^)
This role allows you to specify a custom opacity for icon painting. Note that the opacity is not in effect when the item is either selected and/or hovered.
This commit is contained in:
parent
2d1eff01a2
commit
8ba47facf6
Notes:
sideshowbarker
2024-07-18 08:02:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8ba47facf6c
6 changed files with 20 additions and 10 deletions
|
@ -118,7 +118,8 @@ void ColumnsView::paint_event(PaintEvent& event)
|
|||
} 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());
|
||||
} else {
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
auto opacity = index.data(ModelRole::IconOpacity).as_float_or(1.0f);
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect(), opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -539,7 +539,8 @@ void IconView::paint_event(PaintEvent& event)
|
|||
} else if (m_hovered_index.is_valid() && m_hovered_index == item_data.index) {
|
||||
painter.blit_brightened(destination.location(), *bitmap, bitmap->rect());
|
||||
} else {
|
||||
painter.blit(destination.location(), *bitmap, bitmap->rect());
|
||||
auto opacity = item_data.index.data(ModelRole::IconOpacity).as_float_or(1.0f);
|
||||
painter.blit(destination.location(), *bitmap, bitmap->rect(), opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,8 +118,10 @@ void ListView::paint_list_item(Painter& painter, int row_index, int painted_item
|
|||
if (data.is_bitmap()) {
|
||||
painter.blit(row_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
|
||||
} else if (data.is_icon()) {
|
||||
if (auto bitmap = data.as_icon().bitmap_for_size(16))
|
||||
painter.blit(row_rect.location(), *bitmap, bitmap->rect());
|
||||
if (auto bitmap = data.as_icon().bitmap_for_size(16)) {
|
||||
auto opacity = index.data(ModelRole::IconOpacity).as_float_or(1.0f);
|
||||
painter.blit(row_rect.location(), *bitmap, bitmap->rect(), opacity);
|
||||
}
|
||||
} else {
|
||||
Color text_color;
|
||||
if (is_selected_row)
|
||||
|
|
|
@ -14,6 +14,7 @@ enum class ModelRole {
|
|||
ForegroundColor,
|
||||
BackgroundColor,
|
||||
Icon,
|
||||
IconOpacity,
|
||||
Font,
|
||||
MimeData,
|
||||
TextAlignment,
|
||||
|
|
|
@ -121,7 +121,8 @@ void TableView::paint_event(PaintEvent& event)
|
|||
} else if (m_hovered_index.is_valid() && cell_index.row() == m_hovered_index.row()) {
|
||||
painter.blit_brightened(cell_rect.location(), *bitmap, bitmap->rect());
|
||||
} else {
|
||||
painter.blit(cell_rect.location(), *bitmap, bitmap->rect());
|
||||
auto opacity = cell_index.data(ModelRole::IconOpacity).as_float_or(1.0f);
|
||||
painter.blit(cell_rect.location(), *bitmap, bitmap->rect(), opacity);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -298,8 +298,10 @@ void TreeView::paint_event(PaintEvent& event)
|
|||
if (data.is_bitmap()) {
|
||||
painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
|
||||
} else if (data.is_icon()) {
|
||||
if (auto bitmap = data.as_icon().bitmap_for_size(16))
|
||||
painter.blit(cell_rect.location(), *bitmap, bitmap->rect());
|
||||
if (auto bitmap = data.as_icon().bitmap_for_size(16)) {
|
||||
auto opacity = cell_index.data(ModelRole::IconOpacity).as_float_or(1.0f);
|
||||
painter.blit(cell_rect.location(), *bitmap, bitmap->rect(), opacity);
|
||||
}
|
||||
} else {
|
||||
auto text_alignment = cell_index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
draw_item_text(painter, cell_index, is_selected_row, cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, Gfx::TextElision::Right);
|
||||
|
@ -318,10 +320,12 @@ void TreeView::paint_event(PaintEvent& event)
|
|||
auto icon = index.data(ModelRole::Icon);
|
||||
if (icon.is_icon()) {
|
||||
if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) {
|
||||
if (m_hovered_index.is_valid() && m_hovered_index.parent() == index.parent() && m_hovered_index.row() == index.row())
|
||||
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());
|
||||
else
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
} else {
|
||||
auto opacity = index.data(ModelRole::IconOpacity).as_float_or(1.0f);
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect(), opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
draw_item_text(painter, index, is_selected_row, text_rect, index.data().to_string(), font_for_index(index), Gfx::TextAlignment::Center, Gfx::TextElision::None);
|
||||
|
|
Loading…
Add table
Reference in a new issue