mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
LibGUI: Recalculate GlyphMapWidget content size when changing font
Previously, if it was displaying N glyphs per line, then you changed font to one that was a drastically different size, it would continue to display N glyphs per line until you resized the window. Now, we immediately recalculate how many to show, so that they fill the available width. :^)
This commit is contained in:
parent
21a24c36a8
commit
15a7dfbc30
2 changed files with 19 additions and 12 deletions
|
@ -60,18 +60,7 @@ GlyphMapWidget::~GlyphMapWidget()
|
||||||
|
|
||||||
void GlyphMapWidget::resize_event(ResizeEvent& event)
|
void GlyphMapWidget::resize_event(ResizeEvent& event)
|
||||||
{
|
{
|
||||||
int event_width = event.size().width() - vertical_scrollbar().width() - (frame_thickness() * 2) - m_horizontal_spacing;
|
recalculate_content_size();
|
||||||
int event_height = event.size().height() - (frame_thickness() * 2);
|
|
||||||
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);
|
|
||||||
|
|
||||||
int content_width = columns() * (font().max_glyph_width() + m_horizontal_spacing);
|
|
||||||
int content_height = rows() * (font().glyph_height() + m_vertical_spacing) + frame_thickness();
|
|
||||||
set_content_size({ content_width, content_height });
|
|
||||||
|
|
||||||
scroll_to_glyph(m_active_glyph);
|
|
||||||
|
|
||||||
AbstractScrollableWidget::resize_event(event);
|
AbstractScrollableWidget::resize_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,6 +234,7 @@ void GlyphMapWidget::keydown_event(KeyEvent& event)
|
||||||
|
|
||||||
void GlyphMapWidget::did_change_font()
|
void GlyphMapWidget::did_change_font()
|
||||||
{
|
{
|
||||||
|
recalculate_content_size();
|
||||||
vertical_scrollbar().set_step(font().glyph_height() + m_vertical_spacing);
|
vertical_scrollbar().set_step(font().glyph_height() + m_vertical_spacing);
|
||||||
set_active_glyph('A');
|
set_active_glyph('A');
|
||||||
}
|
}
|
||||||
|
@ -262,4 +252,20 @@ void GlyphMapWidget::scroll_to_glyph(int glyph)
|
||||||
scroll_into_view(scroll_rect, true, true);
|
scroll_into_view(scroll_rect, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlyphMapWidget::recalculate_content_size()
|
||||||
|
{
|
||||||
|
auto inner_rect = frame_inner_rect();
|
||||||
|
int event_width = inner_rect.width() - vertical_scrollbar().width() - m_horizontal_spacing;
|
||||||
|
int event_height = 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);
|
||||||
|
|
||||||
|
int content_width = columns() * (font().max_glyph_width() + m_horizontal_spacing);
|
||||||
|
int content_height = rows() * (font().glyph_height() + m_vertical_spacing) + frame_thickness();
|
||||||
|
set_content_size({ content_width, content_height });
|
||||||
|
|
||||||
|
scroll_to_glyph(m_active_glyph);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ private:
|
||||||
void copy_glyph(int glyph);
|
void copy_glyph(int glyph);
|
||||||
void paste_glyph(int glyph);
|
void paste_glyph(int glyph);
|
||||||
void delete_glyph(int glyph);
|
void delete_glyph(int glyph);
|
||||||
|
void recalculate_content_size();
|
||||||
|
|
||||||
int m_glyph_count { 0x110000 };
|
int m_glyph_count { 0x110000 };
|
||||||
int m_columns { 0 };
|
int m_columns { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue