mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +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:
parent
e7d15ccca4
commit
3e2e086011
4 changed files with 22 additions and 6 deletions
|
@ -1448,3 +1448,9 @@ void GTextEditor::add_custom_context_menu_action(GAction& action)
|
||||||
{
|
{
|
||||||
m_custom_context_menu_actions.append(action);
|
m_custom_context_menu_actions.append(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GTextEditor::did_change_font()
|
||||||
|
{
|
||||||
|
vertical_scrollbar().set_step(line_height());
|
||||||
|
GWidget::did_change_font();
|
||||||
|
}
|
||||||
|
|
|
@ -165,6 +165,9 @@ public:
|
||||||
|
|
||||||
void add_custom_context_menu_action(GAction&);
|
void add_custom_context_menu_action(GAction&);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void did_change_font() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
virtual void mousedown_event(GMouseEvent&) override;
|
virtual void mousedown_event(GMouseEvent&) override;
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
GWidget::GWidget(GWidget* parent)
|
GWidget::GWidget(GWidget* parent)
|
||||||
: CObject(parent, true)
|
: CObject(parent, true)
|
||||||
|
, m_font(Font::default_font())
|
||||||
{
|
{
|
||||||
set_font(nullptr);
|
|
||||||
m_background_color = Color::WarmGray;
|
m_background_color = Color::WarmGray;
|
||||||
m_foreground_color = Color::Black;
|
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)
|
if (!font)
|
||||||
m_font = Font::default_font();
|
m_font = Font::default_font();
|
||||||
else
|
else
|
||||||
m_font = font;
|
m_font = *font;
|
||||||
|
|
||||||
|
did_change_font();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,8 @@ public:
|
||||||
bool fill_with_background_color() const { return m_fill_with_background_color; }
|
bool fill_with_background_color() const { return m_fill_with_background_color; }
|
||||||
|
|
||||||
const Font& font() const { return *m_font; }
|
const Font& font() const { return *m_font; }
|
||||||
void set_font(Font*);
|
void set_font(const Font*);
|
||||||
void set_font(Font& font) { set_font(&font); }
|
void set_font(const Font& font) { set_font(&font); }
|
||||||
|
|
||||||
void set_global_cursor_tracking(bool);
|
void set_global_cursor_tracking(bool);
|
||||||
bool global_cursor_tracking() const;
|
bool global_cursor_tracking() const;
|
||||||
|
@ -219,6 +219,8 @@ public:
|
||||||
|
|
||||||
virtual void save_to(AK::JsonObject&) override;
|
virtual void save_to(AK::JsonObject&) override;
|
||||||
|
|
||||||
|
virtual void did_change_font() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handle_paint_event(GPaintEvent&);
|
void handle_paint_event(GPaintEvent&);
|
||||||
void handle_resize_event(GResizeEvent&);
|
void handle_resize_event(GResizeEvent&);
|
||||||
|
@ -237,7 +239,7 @@ private:
|
||||||
Rect m_relative_rect;
|
Rect m_relative_rect;
|
||||||
Color m_background_color;
|
Color m_background_color;
|
||||||
Color m_foreground_color;
|
Color m_foreground_color;
|
||||||
RefPtr<Font> m_font;
|
NonnullRefPtr<Font> m_font;
|
||||||
String m_tooltip;
|
String m_tooltip;
|
||||||
|
|
||||||
SizePolicy m_horizontal_size_policy { SizePolicy::Fill };
|
SizePolicy m_horizontal_size_policy { SizePolicy::Fill };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue