mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
LibGUI: Replace DeprecatedString usage in Widget
This commit is contained in:
parent
d978dd4af8
commit
174d6f1f51
Notes:
sideshowbarker
2024-07-17 05:21:12 +09:00
Author: https://github.com/camc Commit: https://github.com/SerenityOS/serenity/commit/174d6f1f51 Pull-request: https://github.com/SerenityOS/serenity/pull/20312 Reviewed-by: https://github.com/AtkinsSJ ✅
@ -90,7 +90,7 @@ ErrorOr<NonnullRefPtr<MainWidget>> MainWidget::try_create(GUI::Icon const& icon)
|
||||
main_widget->m_editor->on_change = [main_widget = main_widget.ptr()] {
|
||||
main_widget->m_preview->remove_all_children();
|
||||
// FIXME: Parsing errors happen while the user is typing. What should we do about them?
|
||||
(void)main_widget->m_preview->load_from_gml(main_widget->m_editor->text(), [](DeprecatedString const& class_name) -> ErrorOr<NonnullRefPtr<Core::EventReceiver>> {
|
||||
(void)main_widget->m_preview->load_from_gml(main_widget->m_editor->text(), [](StringView class_name) -> ErrorOr<NonnullRefPtr<Core::EventReceiver>> {
|
||||
return UnregisteredWidget::try_create(class_name);
|
||||
});
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ void GMLPreviewWidget::load_gml(DeprecatedString const& gml)
|
||||
}
|
||||
|
||||
// FIXME: Parsing errors happen while the user is typing. What should we do about them?
|
||||
(void)load_from_gml(gml, [](DeprecatedString const& name) -> ErrorOr<NonnullRefPtr<Core::EventReceiver>> {
|
||||
(void)load_from_gml(gml, [](StringView name) -> ErrorOr<NonnullRefPtr<Core::EventReceiver>> {
|
||||
return GUI::Label::try_create(TRY(String::formatted("{} is not registered as a GML element!", name)));
|
||||
});
|
||||
|
||||
|
@ -57,7 +57,7 @@ Widget::Widget()
|
||||
REGISTER_BOOL_PROPERTY("visible", is_visible, set_visible);
|
||||
REGISTER_BOOL_PROPERTY("focused", is_focused, set_focus);
|
||||
REGISTER_BOOL_PROPERTY("enabled", is_enabled, set_enabled);
|
||||
REGISTER_DEPRECATED_STRING_PROPERTY("tooltip", tooltip_deprecated, set_tooltip_deprecated);
|
||||
REGISTER_STRING_PROPERTY("tooltip", tooltip, set_tooltip);
|
||||
|
||||
REGISTER_UI_SIZE_PROPERTY("min_size", min_size, set_min_size);
|
||||
REGISTER_READONLY_UI_SIZE_PROPERTY("effective_min_size", effective_min_size);
|
||||
@ -82,7 +82,7 @@ Widget::Widget()
|
||||
REGISTER_INT_PROPERTY("x", x, set_x);
|
||||
REGISTER_INT_PROPERTY("y", y, set_y);
|
||||
|
||||
REGISTER_DEPRECATED_STRING_PROPERTY("font", m_font->family, set_font_family);
|
||||
REGISTER_STRING_PROPERTY("font", font_family, set_font_family);
|
||||
REGISTER_INT_PROPERTY("font_size", m_font->presentation_size, set_font_size);
|
||||
REGISTER_FONT_WEIGHT_PROPERTY("font_weight", m_font->weight, set_font_weight);
|
||||
|
||||
@ -819,9 +819,9 @@ void Widget::set_font(Gfx::Font const* font)
|
||||
update();
|
||||
}
|
||||
|
||||
void Widget::set_font_family(DeprecatedString const& family)
|
||||
void Widget::set_font_family(String const& family)
|
||||
{
|
||||
set_font(Gfx::FontDatabase::the().get(family, m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
set_font(Gfx::FontDatabase::the().get(family.to_deprecated_string(), m_font->presentation_size(), m_font->weight(), m_font->width(), m_font->slope()));
|
||||
}
|
||||
|
||||
void Widget::set_font_size(unsigned size)
|
||||
@ -1108,6 +1108,11 @@ Gfx::IntRect Widget::relative_non_grabbable_rect() const
|
||||
}
|
||||
|
||||
void Widget::set_tooltip_deprecated(DeprecatedString tooltip)
|
||||
{
|
||||
set_tooltip(String::from_deprecated_string(move(tooltip)).release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
|
||||
void Widget::set_tooltip(String tooltip)
|
||||
{
|
||||
m_tooltip = move(tooltip);
|
||||
if (Application::the()->tooltip_source_widget() == this)
|
||||
@ -1117,7 +1122,7 @@ void Widget::set_tooltip_deprecated(DeprecatedString tooltip)
|
||||
void Widget::show_or_hide_tooltip()
|
||||
{
|
||||
if (has_tooltip())
|
||||
Application::the()->show_tooltip(m_tooltip, this);
|
||||
Application::the()->show_tooltip(m_tooltip.to_deprecated_string(), this);
|
||||
else
|
||||
Application::the()->hide_tooltip();
|
||||
}
|
||||
@ -1140,7 +1145,7 @@ void Widget::set_override_cursor(AK::Variant<Gfx::StandardCursor, NonnullRefPtr<
|
||||
|
||||
ErrorOr<void> Widget::load_from_gml(StringView gml_string)
|
||||
{
|
||||
return load_from_gml(gml_string, [](DeprecatedString const& class_name) -> ErrorOr<NonnullRefPtr<Core::EventReceiver>> {
|
||||
return load_from_gml(gml_string, [](StringView class_name) -> ErrorOr<NonnullRefPtr<Core::EventReceiver>> {
|
||||
dbgln("Class '{}' not registered", class_name);
|
||||
return Error::from_string_literal("Class not registered");
|
||||
});
|
||||
@ -1265,4 +1270,9 @@ void Widget::add_spacer()
|
||||
return layout()->add_spacer();
|
||||
}
|
||||
|
||||
String Widget::font_family() const
|
||||
{
|
||||
return String::from_deprecated_string(m_font->family()).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -161,7 +161,9 @@ public:
|
||||
virtual bool is_visible_for_timer_purposes() const override;
|
||||
|
||||
bool has_tooltip() const { return !m_tooltip.is_empty(); }
|
||||
DeprecatedString tooltip_deprecated() const { return m_tooltip; }
|
||||
String tooltip() const { return m_tooltip; }
|
||||
void set_tooltip(String tooltip);
|
||||
DeprecatedString tooltip_deprecated() const { return tooltip().to_deprecated_string(); }
|
||||
void set_tooltip_deprecated(DeprecatedString);
|
||||
|
||||
bool is_auto_focusable() const { return m_auto_focusable; }
|
||||
@ -283,7 +285,7 @@ public:
|
||||
void set_font(Gfx::Font const*);
|
||||
void set_font(Gfx::Font const& font) { set_font(&font); }
|
||||
|
||||
void set_font_family(DeprecatedString const&);
|
||||
void set_font_family(String const&);
|
||||
void set_font_size(unsigned);
|
||||
void set_font_weight(unsigned);
|
||||
void set_font_fixed_width(bool);
|
||||
@ -343,7 +345,7 @@ public:
|
||||
AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap const>> const& override_cursor() const { return m_override_cursor; }
|
||||
void set_override_cursor(AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap const>>);
|
||||
|
||||
using UnregisteredChildHandler = ErrorOr<NonnullRefPtr<Core::EventReceiver>>(DeprecatedString const&);
|
||||
using UnregisteredChildHandler = ErrorOr<NonnullRefPtr<Core::EventReceiver>>(StringView);
|
||||
ErrorOr<void> load_from_gml(StringView);
|
||||
ErrorOr<void> load_from_gml(StringView, UnregisteredChildHandler);
|
||||
|
||||
@ -421,6 +423,9 @@ private:
|
||||
int dummy_fixed_height() { return 0; }
|
||||
Gfx::IntSize dummy_fixed_size() { return {}; }
|
||||
|
||||
// HACK: Used as property getter for the font_family property, can be removed when Font is migrated from DeprecatedString.
|
||||
String font_family() const;
|
||||
|
||||
Window* m_window { nullptr };
|
||||
RefPtr<Layout> m_layout;
|
||||
|
||||
@ -428,7 +433,7 @@ private:
|
||||
Gfx::ColorRole m_background_role;
|
||||
Gfx::ColorRole m_foreground_role;
|
||||
NonnullRefPtr<Gfx::Font const> m_font;
|
||||
DeprecatedString m_tooltip;
|
||||
String m_tooltip;
|
||||
|
||||
UISize m_min_size { SpecialDimension::Shrink };
|
||||
UISize m_max_size { SpecialDimension::Grow };
|
||||
|
Loading…
Reference in New Issue
Block a user