mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
LibGfx: Convert FontDatabase APIs to use FlyString
This commit is contained in:
parent
e4d14e1afc
commit
13db3c5ce0
15 changed files with 66 additions and 62 deletions
|
@ -30,11 +30,11 @@ FontPicker::FontPicker(Window* parent_window, Gfx::Font const* current_font, boo
|
|||
widget->load_from_gml(font_picker_dialog_gml).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
m_family_list_view = *widget->find_descendant_of_type_named<ListView>("family_list_view");
|
||||
m_family_list_view->set_model(ItemListModel<DeprecatedString>::create(m_families));
|
||||
m_family_list_view->set_model(ItemListModel<FlyString>::create(m_families));
|
||||
m_family_list_view->horizontal_scrollbar().set_visible(false);
|
||||
|
||||
m_variant_list_view = *widget->find_descendant_of_type_named<ListView>("variant_list_view");
|
||||
m_variant_list_view->set_model(ItemListModel<DeprecatedString>::create(m_variants));
|
||||
m_variant_list_view->set_model(ItemListModel<FlyString>::create(m_variants));
|
||||
m_variant_list_view->horizontal_scrollbar().set_visible(false);
|
||||
|
||||
m_size_spin_box = *widget->find_descendant_of_type_named<SpinBox>("size_spin_box");
|
||||
|
@ -57,7 +57,7 @@ FontPicker::FontPicker(Window* parent_window, Gfx::Font const* current_font, boo
|
|||
|
||||
m_family_list_view->on_selection_change = [this] {
|
||||
const auto& index = m_family_list_view->selection().first();
|
||||
m_family = index.data().to_deprecated_string();
|
||||
m_family = MUST(String::from_deprecated_string(index.data().to_deprecated_string()));
|
||||
m_variants.clear();
|
||||
Gfx::FontDatabase::the().for_each_typeface([&](auto& typeface) {
|
||||
if (m_fixed_width_only && !typeface.is_fixed_width())
|
||||
|
@ -78,7 +78,7 @@ FontPicker::FontPicker(Window* parent_window, Gfx::Font const* current_font, boo
|
|||
m_variant_list_view->on_selection_change = [this] {
|
||||
const auto& index = m_variant_list_view->selection().first();
|
||||
bool font_is_fixed_size = false;
|
||||
m_variant = index.data().to_deprecated_string();
|
||||
m_variant = MUST(String::from_deprecated_string(index.data().to_deprecated_string()));
|
||||
m_sizes.clear();
|
||||
Gfx::FontDatabase::the().for_each_typeface([&](auto& typeface) {
|
||||
if (m_fixed_width_only && !typeface.is_fixed_width())
|
||||
|
@ -190,15 +190,15 @@ void FontPicker::set_font(Gfx::Font const* font)
|
|||
return;
|
||||
}
|
||||
|
||||
m_family = font->family().to_deprecated_string();
|
||||
m_variant = font->variant().to_deprecated_string();
|
||||
m_family = font->family();
|
||||
m_variant = font->variant();
|
||||
m_size = font->presentation_size();
|
||||
|
||||
auto family_index = m_families.find_first_index(m_font->family().to_deprecated_string());
|
||||
auto family_index = m_families.find_first_index(m_font->family());
|
||||
if (family_index.has_value())
|
||||
m_family_list_view->set_cursor(m_family_list_view->model()->index(family_index.value()), GUI::AbstractView::SelectionUpdate::Set);
|
||||
|
||||
auto variant_index = m_variants.find_first_index(m_font->variant().to_deprecated_string());
|
||||
auto variant_index = m_variants.find_first_index(m_font->variant());
|
||||
if (variant_index.has_value())
|
||||
m_variant_list_view->set_cursor(m_variant_list_view->model()->index(variant_index.value()), GUI::AbstractView::SelectionUpdate::Set);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibGUI/Dialog.h>
|
||||
#include <LibGfx/Font/Font.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
|
@ -37,12 +38,12 @@ private:
|
|||
RefPtr<SpinBox> m_size_spin_box;
|
||||
RefPtr<Label> m_sample_text_label;
|
||||
|
||||
Vector<DeprecatedString> m_families;
|
||||
Vector<DeprecatedString> m_variants;
|
||||
Vector<FlyString> m_families;
|
||||
Vector<FlyString> m_variants;
|
||||
Vector<int> m_sizes;
|
||||
|
||||
Optional<DeprecatedString> m_family;
|
||||
Optional<DeprecatedString> m_variant;
|
||||
Optional<FlyString> m_family;
|
||||
Optional<FlyString> m_variant;
|
||||
Optional<int> m_size;
|
||||
};
|
||||
|
||||
|
|
|
@ -821,25 +821,25 @@ void Widget::set_font(Gfx::Font const* font)
|
|||
|
||||
void Widget::set_font_family(String const& family)
|
||||
{
|
||||
set_font(Gfx::FontDatabase::the().get(family.to_deprecated_string(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
set_font(Gfx::FontDatabase::the().get(family, m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
}
|
||||
|
||||
void Widget::set_font_size(unsigned size)
|
||||
{
|
||||
set_font(Gfx::FontDatabase::the().get(m_font->family().to_deprecated_string(), size, m_font->weight(), m_font->width(), m_font->slope()));
|
||||
set_font(Gfx::FontDatabase::the().get(m_font->family(), size, m_font->weight(), m_font->width(), m_font->slope()));
|
||||
}
|
||||
|
||||
void Widget::set_font_weight(unsigned weight)
|
||||
{
|
||||
set_font(Gfx::FontDatabase::the().get(m_font->family().to_deprecated_string(), m_font->presentation_size(), weight, m_font->width(), m_font->slope()));
|
||||
set_font(Gfx::FontDatabase::the().get(m_font->family(), m_font->presentation_size(), weight, m_font->width(), m_font->slope()));
|
||||
}
|
||||
|
||||
void Widget::set_font_fixed_width(bool fixed_width)
|
||||
{
|
||||
if (fixed_width)
|
||||
set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_fixed_width_font().family().to_deprecated_string(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_fixed_width_font().family(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
else
|
||||
set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family().to_deprecated_string(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
}
|
||||
|
||||
bool Widget::is_font_fixed_width()
|
||||
|
|
|
@ -33,7 +33,7 @@ ErrorOr<void> CoverWizardPage::build(String title, String subtitle)
|
|||
m_content_widget->set_layout<VerticalBoxLayout>(20);
|
||||
|
||||
m_header_label = TRY(m_content_widget->try_add<Label>(move(title)));
|
||||
m_header_label->set_font(Gfx::FontDatabase::the().get("Pebbleton", 14, 700, Gfx::FontWidth::Normal, 0));
|
||||
m_header_label->set_font(Gfx::FontDatabase::the().get("Pebbleton"_fly_string, 14, 700, Gfx::FontWidth::Normal, 0));
|
||||
m_header_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||
m_header_label->set_fixed_height(48);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue