mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibVT+Terminal: Resize terminal when font changes
When the font is changed in the Terminal application, we now resize the terminal window to accomodate the new font.
This commit is contained in:
parent
9d6198b683
commit
6a19542715
Notes:
sideshowbarker
2024-07-19 00:00:29 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6a19542715e
3 changed files with 23 additions and 3 deletions
|
@ -417,7 +417,8 @@ int main(int argc, char** argv)
|
|||
[&](auto&) {
|
||||
auto picker = GUI::FontPicker::construct(window, &terminal.font(), true);
|
||||
if (picker->exec() == GUI::Dialog::ExecOK) {
|
||||
terminal.set_font(picker->font());
|
||||
terminal.set_font_and_resize_to_fit(*picker->font());
|
||||
window->resize(terminal.size());
|
||||
config->write_entry("Text", "Font", picker->font()->qualified_name());
|
||||
config->sync();
|
||||
}
|
||||
|
|
|
@ -960,8 +960,9 @@ void TerminalWidget::terminal_history_changed()
|
|||
|
||||
void TerminalWidget::terminal_did_resize(u16 columns, u16 rows)
|
||||
{
|
||||
m_pixel_width = (frame_thickness() * 2) + (m_inset * 2) + (columns * font().glyph_width('x')) + m_scrollbar->width();
|
||||
m_pixel_height = (frame_thickness() * 2) + (m_inset * 2) + (rows * (font().glyph_height() + m_line_spacing));
|
||||
auto pixel_size = widget_size_for_font(font());
|
||||
m_pixel_width = pixel_size.width();
|
||||
m_pixel_height = pixel_size.height();
|
||||
|
||||
if (m_automatic_size_policy) {
|
||||
set_fixed_size(m_pixel_width, m_pixel_height);
|
||||
|
@ -1119,3 +1120,17 @@ void TerminalWidget::update_paste_action()
|
|||
{
|
||||
m_paste_action->set_enabled(GUI::Clipboard::the().mime_type().starts_with("text/") && !GUI::Clipboard::the().data().is_empty());
|
||||
}
|
||||
|
||||
Gfx::IntSize TerminalWidget::widget_size_for_font(const Gfx::Font& font) const
|
||||
{
|
||||
return {
|
||||
(frame_thickness() * 2) + (m_inset * 2) + (m_terminal.columns() * font.glyph_width('x')) + m_scrollbar->width(),
|
||||
(frame_thickness() * 2) + (m_inset * 2) + (m_terminal.rows() * (font.glyph_height() + m_line_spacing))
|
||||
};
|
||||
}
|
||||
|
||||
void TerminalWidget::set_font_and_resize_to_fit(const Gfx::Font& font)
|
||||
{
|
||||
set_font(font);
|
||||
resize(widget_size_for_font(font));
|
||||
}
|
||||
|
|
|
@ -106,6 +106,8 @@ public:
|
|||
|
||||
GUI::Menu& context_menu() { return *m_context_menu; }
|
||||
|
||||
void set_font_and_resize_to_fit(const Gfx::Font&);
|
||||
|
||||
private:
|
||||
// ^GUI::Widget
|
||||
virtual void event(Core::Event&) override;
|
||||
|
@ -138,6 +140,8 @@ private:
|
|||
Gfx::IntRect glyph_rect(u16 row, u16 column);
|
||||
Gfx::IntRect row_rect(u16 row);
|
||||
|
||||
Gfx::IntSize widget_size_for_font(const Gfx::Font&) const;
|
||||
|
||||
void update_cursor();
|
||||
void invalidate_cursor();
|
||||
|
||||
|
|
Loading…
Reference in a new issue