mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibGUI: Brighten icons when hovering items in item views
View classes now track their hovered item and paint them in a slightly brighter shade to liven up the user interface. :^)
This commit is contained in:
parent
add93bf593
commit
b4fde72013
Notes:
sideshowbarker
2024-07-19 08:02:45 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b4fde720132
6 changed files with 40 additions and 11 deletions
|
@ -193,7 +193,16 @@ void AbstractView::mousedown_event(MouseEvent& event)
|
|||
|
||||
void AbstractView::mousemove_event(MouseEvent& event)
|
||||
{
|
||||
if (!model() || !m_might_drag)
|
||||
if (!model())
|
||||
return ScrollableWidget::mousemove_event(event);
|
||||
|
||||
auto hovered_index = index_at_event_position(event.position());
|
||||
if (m_hovered_index != hovered_index) {
|
||||
m_hovered_index = hovered_index;
|
||||
update();
|
||||
}
|
||||
|
||||
if (!m_might_drag)
|
||||
return ScrollableWidget::mousemove_event(event);
|
||||
|
||||
if (!(event.buttons() & MouseButton::Left) || m_selection.is_empty()) {
|
||||
|
|
|
@ -96,6 +96,8 @@ protected:
|
|||
Gfx::Point m_left_mousedown_position;
|
||||
bool m_might_drag { false };
|
||||
|
||||
ModelIndex m_hovered_index;
|
||||
|
||||
private:
|
||||
RefPtr<Model> m_model;
|
||||
OwnPtr<ModelEditingDelegate> m_editing_delegate;
|
||||
|
|
|
@ -128,9 +128,14 @@ void ColumnsView::paint_event(PaintEvent& event)
|
|||
auto icon = model()->data(index, Model::Role::Icon);
|
||||
Gfx::Rect icon_rect = { column_x + icon_spacing(), 0, icon_size(), icon_size() };
|
||||
icon_rect.center_vertically_within(row_rect);
|
||||
if (icon.is_icon())
|
||||
if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size()))
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
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())
|
||||
painter.blit_brightened(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
else
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::Rect text_rect = {
|
||||
icon_rect.right() + 1 + icon_spacing(), row * item_height(),
|
||||
|
|
|
@ -299,8 +299,13 @@ void ItemView::paint_event(PaintEvent& event)
|
|||
get_item_rects(item_index, font, item_text, item_rect, icon_rect, text_rect);
|
||||
|
||||
if (icon.is_icon()) {
|
||||
if (auto bitmap = icon.as_icon().bitmap_for_size(icon_rect.width()))
|
||||
painter.draw_scaled_bitmap(icon_rect, *bitmap, bitmap->rect());
|
||||
if (auto bitmap = icon.as_icon().bitmap_for_size(icon_rect.width())) {
|
||||
if (m_hovered_index.is_valid() && m_hovered_index == model_index) {
|
||||
painter.blit_brightened(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
} else {
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Color text_color;
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/Model.h>
|
||||
|
@ -35,6 +34,7 @@
|
|||
#include <LibGUI/TableView.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
|
@ -119,8 +119,12 @@ void TableView::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)) {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
Color text_color;
|
||||
if (is_selected_row)
|
||||
|
|
|
@ -260,8 +260,12 @@ void TreeView::paint_event(PaintEvent& event)
|
|||
Gfx::Rect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() };
|
||||
auto icon = model.data(index, Model::Role::Icon);
|
||||
if (icon.is_icon()) {
|
||||
if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size()))
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
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())
|
||||
painter.blit_brightened(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
else
|
||||
painter.blit(icon_rect.location(), *bitmap, bitmap->rect());
|
||||
}
|
||||
}
|
||||
Gfx::Rect text_rect = {
|
||||
icon_rect.right() + 1 + icon_spacing(), rect.y(),
|
||||
|
|
Loading…
Add table
Reference in a new issue