1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:07:45 +00:00

Userland+Base: Make the window titlebar font configurable separately

Instead of defaulting to "bold variant of the system default font",
let's allow the user to set any font they want as the titlebar font.
This commit is contained in:
Andreas Kling 2022-07-31 18:41:07 +02:00
parent 419e986dcc
commit 548081ea23
20 changed files with 107 additions and 21 deletions

View file

@ -51,7 +51,7 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
frame_rect.set_location({ 0, 0 });
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
auto titlebar_rect = this->titlebar_rect(WindowType::Normal, window_rect, palette);
auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_rect, palette);
@ -118,7 +118,7 @@ void ClassicWindowTheme::paint_tool_window_frame(Painter& painter, WindowState w
frame_rect.set_location({ 0, 0 });
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
auto titlebar_rect = this->titlebar_rect(WindowType::ToolWindow, window_rect, palette);
auto titlebar_inner_rect = titlebar_text_rect(WindowType::ToolWindow, window_rect, palette);
@ -152,7 +152,7 @@ IntRect ClassicWindowTheme::menubar_rect(WindowType window_type, IntRect const&
IntRect ClassicWindowTheme::titlebar_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const
{
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
auto window_titlebar_height = titlebar_height(window_type, palette);
// FIXME: The top of the titlebar doesn't get redrawn properly if this padding is different
int total_vertical_padding = title_font.glyph_height() - 1;
@ -254,7 +254,7 @@ Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, IntRe
int ClassicWindowTheme::titlebar_height(WindowType window_type, Palette const& palette) const
{
auto& title_font = FontDatabase::default_font().bold_variant();
auto& title_font = FontDatabase::window_title_font();
switch (window_type) {
case WindowType::Normal:
case WindowType::Notification:

View file

@ -25,8 +25,13 @@ FontDatabase& FontDatabase::the()
static RefPtr<Font> s_default_font;
static String s_default_font_query;
static RefPtr<Font> s_window_title_font;
static String s_window_title_font_query;
static RefPtr<Font> s_fixed_width_font;
static String s_fixed_width_font_query;
static String s_default_fonts_lookup_path = "/res/fonts";
void FontDatabase::set_default_font_query(String query)
@ -42,6 +47,19 @@ String FontDatabase::default_font_query()
return s_default_font_query;
}
void FontDatabase::set_window_title_font_query(String query)
{
if (s_window_title_font_query == query)
return;
s_window_title_font_query = move(query);
s_window_title_font = nullptr;
}
String FontDatabase::window_title_font_query()
{
return s_window_title_font_query;
}
void FontDatabase::set_default_fonts_lookup_path(String path)
{
if (s_default_fonts_lookup_path == path)
@ -64,6 +82,16 @@ Font& FontDatabase::default_font()
return *s_default_font;
}
Font& FontDatabase::window_title_font()
{
if (!s_window_title_font) {
VERIFY(!s_window_title_font_query.is_empty());
s_window_title_font = FontDatabase::the().get_by_name(s_window_title_font_query);
VERIFY(s_window_title_font);
}
return *s_window_title_font;
}
void FontDatabase::set_fixed_width_font_query(String query)
{
if (s_fixed_width_font_query == query)

View file

@ -36,11 +36,15 @@ public:
static Font& default_font();
static Font& default_fixed_width_font();
static Font& window_title_font();
static String default_font_query();
static String window_title_font_query();
static String fixed_width_font_query();
static String default_fonts_lookup_path();
static void set_default_font_query(String);
static void set_window_title_font_query(String);
static void set_fixed_width_font_query(String);
static void set_default_fonts_lookup_path(String);