mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibGUI: Add FontsChanged event and deliver it to windows and widgets
This commit is contained in:
parent
9318d9f284
commit
b40d771512
Notes:
sideshowbarker
2024-07-18 09:12:36 +09:00
Author: https://github.com/luk1337 Commit: https://github.com/SerenityOS/serenity/commit/b40d7715128 Pull-request: https://github.com/SerenityOS/serenity/pull/8676
7 changed files with 39 additions and 0 deletions
|
@ -52,6 +52,7 @@ public:
|
|||
DragMove,
|
||||
Drop,
|
||||
ThemeChange,
|
||||
FontsChange,
|
||||
ScreenRectsChange,
|
||||
ActionEnter,
|
||||
ActionLeave,
|
||||
|
@ -425,6 +426,14 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class FontsChangeEvent final : public Event {
|
||||
public:
|
||||
FontsChangeEvent()
|
||||
: Event(Type::FontsChange)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ScreenRectsChangeEvent final : public Event {
|
||||
public:
|
||||
explicit ScreenRectsChangeEvent(const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index)
|
||||
|
|
|
@ -70,6 +70,7 @@ struct TextDocumentSpan;
|
|||
class TextDocumentUndoCommand;
|
||||
class TextEditor;
|
||||
class ThemeChangeEvent;
|
||||
class FontsChangeEvent;
|
||||
class Toolbar;
|
||||
class ToolbarContainer;
|
||||
class TreeView;
|
||||
|
|
|
@ -295,6 +295,8 @@ void Widget::event(Core::Event& event)
|
|||
return drop_event(static_cast<DropEvent&>(event));
|
||||
case Event::ThemeChange:
|
||||
return theme_change_event(static_cast<ThemeChangeEvent&>(event));
|
||||
case Event::FontsChange:
|
||||
return fonts_change_event(static_cast<FontsChangeEvent&>(event));
|
||||
case Event::Enter:
|
||||
return handle_enter_event(event);
|
||||
case Event::Leave:
|
||||
|
@ -558,6 +560,10 @@ void Widget::theme_change_event(ThemeChangeEvent&)
|
|||
{
|
||||
}
|
||||
|
||||
void Widget::fonts_change_event(FontsChangeEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void Widget::screen_rects_change_event(ScreenRectsChangeEvent&)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -314,6 +314,7 @@ protected:
|
|||
virtual void drag_leave_event(Event&);
|
||||
virtual void drop_event(DropEvent&);
|
||||
virtual void theme_change_event(ThemeChangeEvent&);
|
||||
virtual void fonts_change_event(FontsChangeEvent&);
|
||||
virtual void screen_rects_change_event(ScreenRectsChangeEvent&);
|
||||
|
||||
virtual void did_begin_inspection() override;
|
||||
|
|
|
@ -511,6 +511,21 @@ void Window::handle_theme_change_event(ThemeChangeEvent& event)
|
|||
dispatch_theme_change(*m_main_widget.ptr(), dispatch_theme_change);
|
||||
}
|
||||
|
||||
void Window::handle_fonts_change_event(FontsChangeEvent& event)
|
||||
{
|
||||
if (!m_main_widget)
|
||||
return;
|
||||
auto dispatch_fonts_change = [&](auto& widget, auto recursive) {
|
||||
widget.dispatch_event(event, this);
|
||||
widget.for_each_child_widget([&](auto& widget) -> IterationDecision {
|
||||
widget.dispatch_event(event, this);
|
||||
recursive(widget, recursive);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
};
|
||||
dispatch_fonts_change(*m_main_widget.ptr(), dispatch_fonts_change);
|
||||
}
|
||||
|
||||
void Window::handle_screen_rects_change_event(ScreenRectsChangeEvent& event)
|
||||
{
|
||||
if (!m_main_widget)
|
||||
|
@ -594,6 +609,9 @@ void Window::event(Core::Event& event)
|
|||
if (event.type() == Event::ThemeChange)
|
||||
return handle_theme_change_event(static_cast<ThemeChangeEvent&>(event));
|
||||
|
||||
if (event.type() == Event::FontsChange)
|
||||
return handle_fonts_change_event(static_cast<FontsChangeEvent&>(event));
|
||||
|
||||
if (event.type() == Event::ScreenRectsChange)
|
||||
return handle_screen_rects_change_event(static_cast<ScreenRectsChangeEvent&>(event));
|
||||
|
||||
|
|
|
@ -220,6 +220,7 @@ private:
|
|||
void handle_became_active_or_inactive_event(Core::Event&);
|
||||
void handle_close_request();
|
||||
void handle_theme_change_event(ThemeChangeEvent&);
|
||||
void handle_fonts_change_event(FontsChangeEvent&);
|
||||
void handle_screen_rects_change_event(ScreenRectsChangeEvent&);
|
||||
void handle_drag_move_event(DragEvent&);
|
||||
void handle_left_event();
|
||||
|
|
|
@ -72,6 +72,9 @@ void WindowServerConnection::update_system_fonts(const String& default_font_quer
|
|||
Gfx::FontDatabase::set_default_font_query(default_font_query);
|
||||
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
|
||||
Window::update_all_windows({});
|
||||
Window::for_each_window({}, [](auto& window) {
|
||||
Core::EventLoop::current().post_event(window, make<FontsChangeEvent>());
|
||||
});
|
||||
}
|
||||
|
||||
void WindowServerConnection::paint(i32 window_id, Gfx::IntSize const& window_size, Vector<Gfx::IntRect> const& rects)
|
||||
|
|
Loading…
Reference in a new issue