mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibGUI: Improve visible glyph estimate in GlyphMapWidget
Previously the widget used a very rough estimate for visible glyphs based on viewport and glyph areas. Now it simply figures rows times columns with a two row overdraw to accommodate fractional glyphs on either end of visible content. For KaticaRegular10, this ends up reducing unnecessary glyph iterations during painting by about 30%.
This commit is contained in:
parent
e34503800c
commit
a98d5c52f8
2 changed files with 10 additions and 6 deletions
|
@ -128,12 +128,11 @@ void GlyphMapWidget::paint_event(PaintEvent& event)
|
|||
painter.set_font(font());
|
||||
painter.fill_rect(widget_inner_rect(), palette().window().darkened(0.8f));
|
||||
|
||||
int scroll_steps = vertical_scrollbar().value() / vertical_scrollbar().step();
|
||||
int first_visible_glyph = scroll_steps * columns();
|
||||
int range_offset = m_active_range.first;
|
||||
int last_glyph = m_active_range.last + 1;
|
||||
auto first_row = vertical_scrollbar().value() / vertical_scrollbar().step();
|
||||
auto first_glyph = first_row * columns() + m_active_range.first;
|
||||
auto last_glyph = m_active_range.last;
|
||||
|
||||
for (int glyph = first_visible_glyph + range_offset; glyph <= first_visible_glyph + m_visible_glyphs + range_offset && glyph < last_glyph; ++glyph) {
|
||||
for (u32 glyph = first_glyph; glyph <= first_glyph + m_visible_glyphs && glyph <= last_glyph; ++glyph) {
|
||||
Gfx::IntRect outer_rect = get_outer_rect(glyph);
|
||||
Gfx::IntRect inner_rect(
|
||||
outer_rect.x() + m_horizontal_spacing / 2,
|
||||
|
@ -437,10 +436,14 @@ void GlyphMapWidget::recalculate_content_size()
|
|||
{
|
||||
auto event_width = widget_inner_rect().width();
|
||||
auto event_height = widget_inner_rect().height();
|
||||
m_visible_glyphs = (event_width * event_height) / (font().max_glyph_width() * font().glyph_height());
|
||||
m_columns = max(event_width / (font().max_glyph_width() + m_horizontal_spacing), 1);
|
||||
m_rows = ceil_div(m_glyph_count, m_columns);
|
||||
|
||||
constexpr auto overdraw_margins = 2;
|
||||
auto max_visible_rows = event_height / (font().glyph_height() + m_vertical_spacing);
|
||||
m_visible_rows = min(max_visible_rows, m_rows);
|
||||
m_visible_glyphs = (m_visible_rows + overdraw_margins) * m_columns;
|
||||
|
||||
int content_width = columns() * (font().max_glyph_width() + m_horizontal_spacing);
|
||||
int content_height = rows() * (font().glyph_height() + m_vertical_spacing);
|
||||
set_content_size({ content_width, content_height });
|
||||
|
|
|
@ -100,6 +100,7 @@ private:
|
|||
int m_glyph_count { 0x110000 };
|
||||
int m_columns { 0 };
|
||||
int m_rows { 0 };
|
||||
int m_visible_rows { 0 };
|
||||
int m_horizontal_spacing { 4 };
|
||||
int m_vertical_spacing { 4 };
|
||||
Selection m_selection;
|
||||
|
|
Loading…
Add table
Reference in a new issue