mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
Applications+LibGUI: Convert all GML consumers to use the LibCore finder
Remove Widget::find_child_by_name and Widget::find_descendant_by_name, and convert all users to using the type-safer version in Core::Object.
This commit is contained in:
parent
5b03a0867f
commit
347bf6459d
11 changed files with 58 additions and 88 deletions
|
@ -98,19 +98,19 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font, boo
|
|||
if (!widget.load_from_gml(font_picker_dialog_gml))
|
||||
ASSERT_NOT_REACHED();
|
||||
|
||||
m_family_list_view = static_cast<ListView&>(*widget.find_descendant_by_name("family_list_view"));
|
||||
m_family_list_view = *widget.find_descendant_of_type_named<ListView>("family_list_view");
|
||||
m_family_list_view->set_model(ItemListModel<String>::create(m_families));
|
||||
m_family_list_view->horizontal_scrollbar().set_visible(false);
|
||||
|
||||
m_weight_list_view = static_cast<ListView&>(*widget.find_descendant_by_name("weight_list_view"));
|
||||
m_weight_list_view = *widget.find_descendant_of_type_named<ListView>("weight_list_view");
|
||||
m_weight_list_view->set_model(adopt(*new FontWeightListModel(m_weights)));
|
||||
m_weight_list_view->horizontal_scrollbar().set_visible(false);
|
||||
|
||||
m_size_list_view = static_cast<ListView&>(*widget.find_descendant_by_name("size_list_view"));
|
||||
m_size_list_view = *widget.find_descendant_of_type_named<ListView>("size_list_view");
|
||||
m_size_list_view->set_model(ItemListModel<int>::create(m_sizes));
|
||||
m_size_list_view->horizontal_scrollbar().set_visible(false);
|
||||
|
||||
m_sample_text_label = static_cast<Label&>(*widget.find_descendant_by_name("sample_text_label"));
|
||||
m_sample_text_label = *widget.find_descendant_of_type_named<Label>("sample_text_label");
|
||||
|
||||
m_families.clear();
|
||||
Gfx::FontDatabase::the().for_each_font([&](auto& font) {
|
||||
|
@ -167,12 +167,12 @@ FontPicker::FontPicker(Window* parent_window, const Gfx::Font* current_font, boo
|
|||
update_font();
|
||||
};
|
||||
|
||||
auto& ok_button = static_cast<Button&>(*widget.find_descendant_by_name("ok_button"));
|
||||
auto& ok_button = *widget.find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
ok_button.on_click = [this](auto) {
|
||||
done(ExecOK);
|
||||
};
|
||||
|
||||
auto& cancel_button = static_cast<Button&>(*widget.find_descendant_by_name("cancel_button"));
|
||||
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
cancel_button.on_click = [this](auto) {
|
||||
done(ExecCancel);
|
||||
};
|
||||
|
|
|
@ -1001,33 +1001,6 @@ bool Widget::load_from_json(const JsonObject& json)
|
|||
return true;
|
||||
}
|
||||
|
||||
Widget* Widget::find_child_by_name(const String& name)
|
||||
{
|
||||
Widget* found_widget = nullptr;
|
||||
for_each_child_widget([&](auto& child) {
|
||||
if (child.name() == name) {
|
||||
found_widget = &child;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return found_widget;
|
||||
}
|
||||
|
||||
Widget* Widget::find_descendant_by_name(const String& name)
|
||||
{
|
||||
Widget* found_widget = nullptr;
|
||||
if (this->name() == name)
|
||||
return this;
|
||||
for_each_child_widget([&](auto& child) {
|
||||
found_widget = child.find_descendant_by_name(name);
|
||||
if (found_widget)
|
||||
return IterationDecision::Break;
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return found_widget;
|
||||
}
|
||||
|
||||
bool Widget::has_focus_within() const
|
||||
{
|
||||
auto* window = this->window();
|
||||
|
|
|
@ -305,9 +305,6 @@ public:
|
|||
|
||||
bool load_from_gml(const StringView&);
|
||||
|
||||
Widget* find_child_by_name(const String&);
|
||||
Widget* find_descendant_by_name(const String&);
|
||||
|
||||
protected:
|
||||
Widget();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue