mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibCore: Make Core::Object::add<ChildType> return a ChildType&
Since the returned object is now owned by the callee object, we can simply vend a ChildType&. This allows us to use "." instead of "->" at the call site, which is quite nice. :^)
This commit is contained in:
parent
fb09b6a8ce
commit
028c011760
46 changed files with 1035 additions and 1039 deletions
|
@ -51,28 +51,28 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
set_rect({ 0, 0, 360, 420 });
|
||||
set_resizable(false);
|
||||
|
||||
auto tab_widget = main_widget.add<GUI::TabWidget>();
|
||||
auto& tab_widget = main_widget.add<GUI::TabWidget>();
|
||||
|
||||
auto general_tab = tab_widget->add_tab<GUI::Widget>("General");
|
||||
auto general_tab = tab_widget.add_tab<GUI::Widget>("General");
|
||||
general_tab->set_layout<GUI::VerticalBoxLayout>();
|
||||
general_tab->layout()->set_margins({ 12, 8, 12, 8 });
|
||||
general_tab->layout()->set_spacing(10);
|
||||
|
||||
general_tab->layout()->add_spacer();
|
||||
|
||||
auto file_container = general_tab->add<GUI::Widget>();
|
||||
file_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
file_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
file_container->layout()->set_spacing(20);
|
||||
file_container->set_preferred_size(0, 34);
|
||||
auto& file_container = general_tab->add<GUI::Widget>();
|
||||
file_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
file_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
file_container.layout()->set_spacing(20);
|
||||
file_container.set_preferred_size(0, 34);
|
||||
|
||||
m_icon = file_container->add<GUI::Label>();
|
||||
m_icon = file_container.add<GUI::Label>();
|
||||
m_icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_icon->set_preferred_size(32, 32);
|
||||
|
||||
m_name = file_path.basename();
|
||||
|
||||
m_name_box = file_container->add<GUI::TextBox>();
|
||||
m_name_box = file_container.add<GUI::TextBox>();
|
||||
m_name_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_name_box->set_preferred_size({ 0, 22 });
|
||||
m_name_box->set_text(m_name);
|
||||
|
@ -130,19 +130,19 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
|
||||
general_tab->layout()->add_spacer();
|
||||
|
||||
auto button_widget = main_widget.add<GUI::Widget>();
|
||||
button_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button_widget->set_preferred_size(0, 24);
|
||||
button_widget->layout()->set_spacing(5);
|
||||
auto& button_widget = main_widget.add<GUI::Widget>();
|
||||
button_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_widget.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button_widget.set_preferred_size(0, 24);
|
||||
button_widget.layout()->set_spacing(5);
|
||||
|
||||
button_widget->layout()->add_spacer();
|
||||
button_widget.layout()->add_spacer();
|
||||
|
||||
make_button("OK", button_widget)->on_click = [this] {
|
||||
make_button("OK", button_widget).on_click = [this] {
|
||||
if (apply_changes())
|
||||
close();
|
||||
};
|
||||
make_button("Cancel", button_widget)->on_click = [this] {
|
||||
make_button("Cancel", button_widget).on_click = [this] {
|
||||
close();
|
||||
};
|
||||
|
||||
|
@ -215,48 +215,48 @@ bool PropertiesDialog::apply_changes()
|
|||
|
||||
void PropertiesDialog::make_permission_checkboxes(NonnullRefPtr<GUI::Widget>& parent, PermissionMasks masks, String label_string, mode_t mode)
|
||||
{
|
||||
auto widget = parent->add<GUI::Widget>();
|
||||
widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
widget->set_preferred_size(0, 16);
|
||||
widget->layout()->set_spacing(10);
|
||||
auto& widget = parent->add<GUI::Widget>();
|
||||
widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
widget.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
widget.set_preferred_size(0, 16);
|
||||
widget.layout()->set_spacing(10);
|
||||
|
||||
auto label = widget->add<GUI::Label>(label_string);
|
||||
label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
auto& label = widget.add<GUI::Label>(label_string);
|
||||
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
auto box_read = widget->add<GUI::CheckBox>("Read");
|
||||
box_read->set_checked(mode & masks.read);
|
||||
box_read->on_checked = [&, masks](bool checked) { permission_changed(masks.read, checked); };
|
||||
auto& box_read = widget.add<GUI::CheckBox>("Read");
|
||||
box_read.set_checked(mode & masks.read);
|
||||
box_read.on_checked = [&, masks](bool checked) { permission_changed(masks.read, checked); };
|
||||
|
||||
auto box_write = widget->add<GUI::CheckBox>("Write");
|
||||
box_write->set_checked(mode & masks.write);
|
||||
box_write->on_checked = [&, masks](bool checked) { permission_changed(masks.write, checked); };
|
||||
auto& box_write = widget.add<GUI::CheckBox>("Write");
|
||||
box_write.set_checked(mode & masks.write);
|
||||
box_write.on_checked = [&, masks](bool checked) { permission_changed(masks.write, checked); };
|
||||
|
||||
auto box_execute = widget->add<GUI::CheckBox>("Execute");
|
||||
box_execute->set_checked(mode & masks.execute);
|
||||
box_execute->on_checked = [&, masks](bool checked) { permission_changed(masks.execute, checked); };
|
||||
auto& box_execute = widget.add<GUI::CheckBox>("Execute");
|
||||
box_execute.set_checked(mode & masks.execute);
|
||||
box_execute.on_checked = [&, masks](bool checked) { permission_changed(masks.execute, checked); };
|
||||
}
|
||||
|
||||
void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>& pairs, NonnullRefPtr<GUI::Widget>& parent)
|
||||
void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>& pairs, GUI::Widget& parent)
|
||||
{
|
||||
int max_width = 0;
|
||||
Vector<NonnullRefPtr<GUI::Label>> property_labels;
|
||||
|
||||
property_labels.ensure_capacity(pairs.size());
|
||||
for (auto pair : pairs) {
|
||||
auto label_container = parent->add<GUI::Widget>();
|
||||
label_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
label_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
label_container->set_preferred_size(0, 14);
|
||||
label_container->layout()->set_spacing(12);
|
||||
auto& label_container = parent.add<GUI::Widget>();
|
||||
label_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
label_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
label_container.set_preferred_size(0, 14);
|
||||
label_container.layout()->set_spacing(12);
|
||||
|
||||
auto label_property = label_container->add<GUI::Label>(pair.property);
|
||||
label_property->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
label_property->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
auto& label_property = label_container.add<GUI::Label>(pair.property);
|
||||
label_property.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
label_property.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
|
||||
label_container->add<GUI::Label>(pair.value)->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
label_container.add<GUI::Label>(pair.value).set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
max_width = max(max_width, label_property->font().width(pair.property));
|
||||
max_width = max(max_width, label_property.font().width(pair.property));
|
||||
property_labels.append(label_property);
|
||||
}
|
||||
|
||||
|
@ -264,21 +264,21 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
|
|||
label->set_preferred_size({ max_width, 0 });
|
||||
}
|
||||
|
||||
NonnullRefPtr<GUI::Button> PropertiesDialog::make_button(String text, NonnullRefPtr<GUI::Widget>& parent)
|
||||
GUI::Button& PropertiesDialog::make_button(String text, GUI::Widget& parent)
|
||||
{
|
||||
auto button = parent->add<GUI::Button>(text);
|
||||
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button->set_preferred_size(70, 22);
|
||||
auto& button = parent.add<GUI::Button>(text);
|
||||
button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button.set_preferred_size(70, 22);
|
||||
return button;
|
||||
}
|
||||
|
||||
void PropertiesDialog::make_divider(NonnullRefPtr<GUI::Widget>& parent)
|
||||
void PropertiesDialog::make_divider(GUI::Widget& parent)
|
||||
{
|
||||
parent->layout()->add_spacer();
|
||||
parent.layout()->add_spacer();
|
||||
|
||||
auto divider = parent->add<GUI::Frame>();
|
||||
divider->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
divider->set_preferred_size({ 0, 2 });
|
||||
auto& divider = parent.add<GUI::Frame>();
|
||||
divider.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
divider.set_preferred_size({ 0, 2 });
|
||||
|
||||
parent->layout()->add_spacer();
|
||||
parent.layout()->add_spacer();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue