mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibGUI: Allow override the font on a per-index basis in GListView
This should be ported to all of the GAbstractView subclasses.
This commit is contained in:
parent
b89f64cb55
commit
31b5047894
Notes:
sideshowbarker
2024-07-19 11:35:16 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/31b50478943
4 changed files with 21 additions and 2 deletions
|
@ -108,3 +108,18 @@ void GAbstractView::notify_selection_changed(Badge<GModelSelection>)
|
|||
on_selection_change();
|
||||
update();
|
||||
}
|
||||
|
||||
NonnullRefPtr<Font> GAbstractView::font_for_index(const GModelIndex& index) const
|
||||
{
|
||||
if (!model())
|
||||
return font();
|
||||
|
||||
auto font_data = model()->data(index, GModel::Role::Font);
|
||||
if (font_data.is_font())
|
||||
return font_data.as_font();
|
||||
|
||||
auto column_metadata = model()->column_metadata(index.column());
|
||||
if (column_metadata.font)
|
||||
return *column_metadata.font;
|
||||
return font();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
|
||||
void notify_selection_changed(Badge<GModelSelection>);
|
||||
|
||||
NonnullRefPtr<Font> font_for_index(const GModelIndex&) const;
|
||||
|
||||
protected:
|
||||
virtual void did_scroll() override;
|
||||
void activate(const GModelIndex&);
|
||||
|
|
|
@ -113,11 +113,12 @@ void GListView::paint_event(GPaintEvent& event)
|
|||
}
|
||||
|
||||
auto column_metadata = model()->column_metadata(m_model_column);
|
||||
const Font& font = column_metadata.font ? *column_metadata.font : this->font();
|
||||
|
||||
Rect row_rect(0, y, content_width(), item_height());
|
||||
painter.fill_rect(row_rect, background_color);
|
||||
auto index = model()->index(row_index, m_model_column);
|
||||
auto data = model()->data(index);
|
||||
auto font = font_for_index(index);
|
||||
if (data.is_bitmap()) {
|
||||
painter.blit(row_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
|
||||
} else if (data.is_icon()) {
|
||||
|
|
|
@ -34,7 +34,8 @@ public:
|
|||
Custom,
|
||||
ForegroundColor,
|
||||
BackgroundColor,
|
||||
Icon
|
||||
Icon,
|
||||
Font,
|
||||
};
|
||||
|
||||
virtual ~GModel();
|
||||
|
|
Loading…
Add table
Reference in a new issue