1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:37:43 +00:00

LibVT: Relayout TerminalWidget on font change

We were not recomputing the internal dimensions after a font changed,
which caused things to look very off.

It's still not perfect as we're always using the same (small) font for
bold text, which obviously sticks out like a sore pinky when the rest
of the terminal text is large.
This commit is contained in:
Andreas Kling 2020-01-08 21:09:43 +01:00
parent 53e204dfb0
commit 56974f76be
2 changed files with 23 additions and 4 deletions

View file

@ -391,16 +391,24 @@ void TerminalWidget::force_repaint()
void TerminalWidget::resize_event(GResizeEvent& event) void TerminalWidget::resize_event(GResizeEvent& event)
{ {
relayout(event.size());
}
void TerminalWidget::relayout(const Size& size)
{
if (!m_scrollbar)
return;
auto base_size = compute_base_size(); auto base_size = compute_base_size();
int new_columns = (event.size().width() - base_size.width()) / font().glyph_width('x'); int new_columns = (size.width() - base_size.width()) / font().glyph_width('x');
int new_rows = (event.size().height() - base_size.height()) / m_line_height; int new_rows = (size.height() - base_size.height()) / m_line_height;
m_terminal.set_size(new_columns, new_rows); m_terminal.set_size(new_columns, new_rows);
Rect scrollbar_rect = { Rect scrollbar_rect = {
event.size().width() - m_scrollbar->width() - frame_thickness(), size.width() - m_scrollbar->width() - frame_thickness(),
frame_thickness(), frame_thickness(),
m_scrollbar->width(), m_scrollbar->width(),
event.size().height() - frame_thickness() * 2, size.height() - frame_thickness() * 2,
}; };
m_scrollbar->set_relative_rect(scrollbar_rect); m_scrollbar->set_relative_rect(scrollbar_rect);
} }
@ -654,3 +662,11 @@ void TerminalWidget::context_menu_event(GContextMenuEvent& event)
} }
m_context_menu->popup(event.screen_position()); m_context_menu->popup(event.screen_position());
} }
void TerminalWidget::did_change_font()
{
GFrame::did_change_font();
m_line_height = font().glyph_height() + m_line_spacing;
if (!size().is_empty())
relayout(size());
}

View file

@ -72,6 +72,7 @@ private:
virtual void focusin_event(CEvent&) override; virtual void focusin_event(CEvent&) override;
virtual void focusout_event(CEvent&) override; virtual void focusout_event(CEvent&) override;
virtual void context_menu_event(GContextMenuEvent&) override; virtual void context_menu_event(GContextMenuEvent&) override;
virtual void did_change_font() override;
// ^TerminalClient // ^TerminalClient
virtual void beep() override; virtual void beep() override;
@ -87,6 +88,8 @@ private:
void update_cursor(); void update_cursor();
void invalidate_cursor(); void invalidate_cursor();
void relayout(const Size&);
Size compute_base_size() const; Size compute_base_size() const;
int first_selection_column_on_row(int row) const; int first_selection_column_on_row(int row) const;
int last_selection_column_on_row(int row) const; int last_selection_column_on_row(int row) const;