1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

LibGUI: Add a way for GWidget subclasses to learn that the font changed

Use this in GTextEditor to update the vertical scrolling step size so
we always scroll one-line-at-a-time.
This commit is contained in:
Andreas Kling 2019-09-01 12:26:35 +02:00
parent e7d15ccca4
commit 3e2e086011
4 changed files with 22 additions and 6 deletions

View file

@ -1448,3 +1448,9 @@ void GTextEditor::add_custom_context_menu_action(GAction& action)
{
m_custom_context_menu_actions.append(action);
}
void GTextEditor::did_change_font()
{
vertical_scrollbar().set_step(line_height());
GWidget::did_change_font();
}

View file

@ -165,6 +165,9 @@ public:
void add_custom_context_menu_action(GAction&);
protected:
virtual void did_change_font() override;
private:
virtual void paint_event(GPaintEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;

View file

@ -14,8 +14,8 @@
GWidget::GWidget(GWidget* parent)
: CObject(parent, true)
, m_font(Font::default_font())
{
set_font(nullptr);
m_background_color = Color::WarmGray;
m_foreground_color = Color::Black;
}
@ -372,12 +372,17 @@ void GWidget::set_focus(bool focus)
}
}
void GWidget::set_font(Font* font)
void GWidget::set_font(const Font* font)
{
if (m_font.ptr() == font)
return;
if (!font)
m_font = Font::default_font();
else
m_font = font;
m_font = *font;
did_change_font();
update();
}

View file

@ -176,8 +176,8 @@ public:
bool fill_with_background_color() const { return m_fill_with_background_color; }
const Font& font() const { return *m_font; }
void set_font(Font*);
void set_font(Font& font) { set_font(&font); }
void set_font(const Font*);
void set_font(const Font& font) { set_font(&font); }
void set_global_cursor_tracking(bool);
bool global_cursor_tracking() const;
@ -219,6 +219,8 @@ public:
virtual void save_to(AK::JsonObject&) override;
virtual void did_change_font() {}
private:
void handle_paint_event(GPaintEvent&);
void handle_resize_event(GResizeEvent&);
@ -237,7 +239,7 @@ private:
Rect m_relative_rect;
Color m_background_color;
Color m_foreground_color;
RefPtr<Font> m_font;
NonnullRefPtr<Font> m_font;
String m_tooltip;
SizePolicy m_horizontal_size_policy { SizePolicy::Fill };