LibGUI: Convert GLabel to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-21 14:19:05 +02:00
parent 6b347747f2
commit c7437f9caa
Notes: sideshowbarker 2024-07-19 12:02:31 +09:00
22 changed files with 47 additions and 45 deletions

View file

@ -24,12 +24,12 @@ int main(int argc, char** argv)
widget->layout()->set_margins({ 0, 8, 0, 8 });
widget->layout()->set_spacing(8);
auto* icon_label = new GLabel(widget);
auto icon_label = GLabel::construct(widget);
icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/serenity.png"));
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
icon_label->set_preferred_size(icon_label->icon()->size());
auto* label = new GLabel(widget);
auto label = GLabel::construct(widget);
label->set_font(Font::default_bold_font());
label->set_text("Serenity Operating System");
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
@ -39,7 +39,7 @@ int main(int argc, char** argv)
int rc = uname(&uts);
ASSERT(rc == 0);
auto* version_label = new GLabel(widget);
auto version_label = GLabel::construct(widget);
version_label->set_text(String::format("Version %s", uts.release));
version_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
version_label->set_preferred_size(0, 11);

View file

@ -13,7 +13,7 @@ CalculatorWidget::CalculatorWidget(GWidget* parent)
m_entry->set_relative_rect(5, 5, 244, 26);
m_entry->set_text_alignment(TextAlignment::CenterRight);
m_label = new GLabel(this);
m_label = GLabel::construct(this);
m_label->set_relative_rect(12, 42, 27, 27);
m_label->set_foreground_color(Color::NamedColor::Red);
m_label->set_frame_shadow(FrameShadow::Sunken);

View file

@ -26,5 +26,5 @@ private:
Keypad m_keypad;
GTextBox* m_entry { nullptr };
GLabel* m_label { nullptr };
ObjectPtr<GLabel> m_label;
};

View file

@ -101,19 +101,19 @@ void DisplayPropertiesWidget::create_frame()
background_content->set_layout(make<GBoxLayout>(Orientation::Vertical));
background_content->layout()->set_margins({ 4, 4, 4, 4 });
auto* wallpaper_preview = new GLabel(background_splitter);
m_wallpaper_preview = GLabel::construct(background_splitter);
auto* wallpaper_list = new GListView(background_content);
wallpaper_list->set_background_color(Color::White);
wallpaper_list->set_model(*ItemListModel<AK::String>::create(m_wallpapers));
wallpaper_list->horizontal_scrollbar().set_visible(false);
wallpaper_list->on_selection = [this, wallpaper_preview](auto& index) {
wallpaper_list->on_selection = [this](auto& index) {
StringBuilder builder;
m_selected_wallpaper = m_wallpapers.at(index.row());
builder.append("/res/wallpapers/");
builder.append(m_selected_wallpaper);
wallpaper_preview->set_icon(load_png(builder.to_string()));
wallpaper_preview->set_should_stretch_icon(true);
m_wallpaper_preview->set_icon(load_png(builder.to_string()));
m_wallpaper_preview->set_should_stretch_icon(true);
};
// Let's add the settings tab

View file

@ -7,6 +7,7 @@
#include <LibDraw/Color.h>
#include <LibDraw/Size.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GLabel.h>
class DisplayPropertiesWidget final {
public:
@ -41,6 +42,7 @@ private:
GWidget* m_root_widget { nullptr };
Vector<Size> m_resolutions;
Vector<String> m_wallpapers;
ObjectPtr<GLabel> m_wallpaper_preview;
Size m_selected_resolution;
String m_selected_wallpaper;

View file

@ -53,7 +53,7 @@ int main(int argc, char** argv)
location_toolbar->layout()->set_margins({ 6, 3, 6, 3 });
location_toolbar->set_preferred_size(0, 25);
auto* location_label = new GLabel("Location: ", location_toolbar);
auto location_label = GLabel::construct("Location: ", location_toolbar);
location_label->size_to_fit();
auto* location_textbox = new GTextEditor(GTextEditor::SingleLine, location_toolbar);

View file

@ -22,15 +22,15 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GWidget* parent)
layout()->set_margins({ 0, 8, 0, 0 });
layout()->set_spacing(3);
auto build_widgets_for_label = [this](const String& description) -> GLabel* {
auto build_widgets_for_label = [this](const String& description) -> ObjectPtr<GLabel> {
auto* container = new GWidget(this);
container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
container->set_preferred_size(275, 12);
auto* description_label = new GLabel(description, container);
auto description_label = GLabel::construct(description, container);
description_label->set_font(Font::default_bold_font());
description_label->set_text_alignment(TextAlignment::CenterLeft);
auto* label = new GLabel(container);
auto label = GLabel::construct(container);
label->set_text_alignment(TextAlignment::CenterRight);
return label;
};

View file

@ -17,9 +17,9 @@ private:
virtual void timer_event(CTimerEvent&) override;
GraphWidget& m_graph;
GLabel* m_user_physical_pages_label { nullptr };
GLabel* m_supervisor_physical_pages_label { nullptr };
GLabel* m_kmalloc_label { nullptr };
GLabel* m_kmalloc_count_label { nullptr };
ObjectPtr<GLabel> m_user_physical_pages_label;
ObjectPtr<GLabel> m_supervisor_physical_pages_label;
ObjectPtr<GLabel> m_kmalloc_label;
ObjectPtr<GLabel> m_kmalloc_count_label;
CFile m_proc_memstat;
};

View file

@ -69,7 +69,7 @@ int main(int argc, char** argv)
window->set_resizable(true);
window->set_rect(window_rect);
auto* background = new GLabel;
auto background = GLabel::construct();
window->set_main_widget(background);
background->set_fill_with_background_color(true);
background->set_layout(make<GBoxLayout>(Orientation::Vertical));
@ -83,7 +83,7 @@ int main(int argc, char** argv)
// header
//
auto* header = new GLabel(background);
auto header = GLabel::construct(background);
header->set_font(Font::default_bold_font());
header->set_text("Welcome to Serenity");
header->set_text_alignment(TextAlignment::CenterLeft);
@ -117,7 +117,7 @@ int main(int argc, char** argv)
content->layout()->set_spacing(8);
content->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
auto* content_title = new GLabel(content);
auto content_title = GLabel::construct(content);
content_title->set_font(Font::default_bold_font());
content_title->set_text(page.title);
content_title->set_text_alignment(TextAlignment::CenterLeft);

View file

@ -223,7 +223,7 @@ int main(int argc, char** argv)
auto* fire = new Fire;
window->set_main_widget(fire);
auto* time = new GLabel(fire);
auto time = GLabel::construct(fire);
time->set_relative_rect({ 0, 4, 40, 10 });
time->move_by({ window->width() - time->width(), 0 });
time->set_foreground_color(Color::from_rgb(0x444444));

View file

@ -20,7 +20,7 @@ int main(int argc, char** argv)
main_widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
main_widget->layout()->set_margins({ 4, 4, 4, 4 });
auto* label = new GLabel(main_widget);
auto label = GLabel::construct(main_widget);
label->set_text("Hello\nWorld!");
auto* button = new GButton(main_widget);

View file

@ -50,9 +50,9 @@ int main(int argc, char** argv)
progress1->set_value(progress1->min());
});
auto* label1 = new GLabel("GLabel 1", main_widget);
auto label1 = GLabel::construct("GLabel 1", main_widget);
(void)label1;
auto* label2 = new GLabel("GLabel 2", main_widget);
auto label2 = GLabel::construct("GLabel 2", main_widget);
label2->set_enabled(false);
auto* textbox1 = new GTextBox(main_widget);

View file

@ -78,7 +78,7 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent)
case VBWidgetType::GGroupBox:
return new GGroupBox("groupbox_1", parent);
case VBWidgetType::GLabel: {
auto* label = new GLabel(parent);
auto label = GLabel::construct(parent);
label->set_fill_with_background_color(true);
label->set_text("label_1");
return label;

View file

@ -29,16 +29,16 @@ int main(int argc, char** argv)
container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
container->set_preferred_size(0, 36);
container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
auto* flag_icon_label = new GLabel(container);
auto flag_icon_label = GLabel::construct(container);
flag_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/flag.png"));
auto* flag_label = new GLabel(container);
auto flag_label = GLabel::construct(container);
auto* face_button = new GButton(container);
face_button->set_button_style(ButtonStyle::CoolBar);
face_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
face_button->set_preferred_size(36, 0);
auto* time_icon_label = new GLabel(container);
auto time_icon_label = GLabel::construct(container);
time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png"));
auto* time_label = new GLabel(container);
auto time_label = GLabel::construct(container);
auto* field = new Field(*flag_label, *time_label, *face_button, widget, [&](Size size) {
size.set_height(size.height() + container->preferred_size().height());
window->resize(size);

View file

@ -22,7 +22,7 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C
left_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
left_container->set_preferred_size(48, 0);
left_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
auto* icon_label = new GLabel(left_container);
auto icon_label = GLabel::construct(left_container);
icon_label->set_icon(m_icon);
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
icon_label->set_preferred_size(40, 40);
@ -33,7 +33,7 @@ GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, C
right_container->layout()->set_margins({ 0, 4, 4, 4 });
auto make_label = [&](const StringView& text, bool bold = false) {
auto* label = new GLabel(text, right_container);
auto label = GLabel::construct(text, right_container);
label->set_text_alignment(TextAlignment::CenterLeft);
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
label->set_preferred_size(0, 14);

View file

@ -75,7 +75,7 @@ public:
TooltipWindow()
{
set_window_type(GWindowType::Tooltip);
m_label = new GLabel;
m_label = GLabel::construct();
m_label->set_background_color(Color::from_rgb(0xdac7b5));
m_label->set_fill_with_background_color(true);
m_label->set_frame_thickness(1);
@ -92,7 +92,7 @@ public:
m_label->set_text(tooltip);
}
GLabel* m_label { nullptr };
ObjectPtr<GLabel> m_label;
};
void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_location)

View file

@ -128,7 +128,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
filename_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
filename_container->set_preferred_size(0, 20);
filename_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
auto* filename_label = new GLabel("File name:", filename_container);
auto filename_label = GLabel::construct("File name:", filename_container);
filename_label->set_text_alignment(TextAlignment::CenterLeft);
filename_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
filename_label->set_preferred_size(60, 0);
@ -201,17 +201,17 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
preview_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
preview_container->layout()->set_margins({ 8, 8, 8, 8 });
m_preview_image_label = new GLabel(preview_container);
m_preview_image_label = GLabel::construct(preview_container);
m_preview_image_label->set_should_stretch_icon(true);
m_preview_image_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
m_preview_image_label->set_preferred_size(160, 160);
m_preview_name_label = new GLabel(preview_container);
m_preview_name_label = GLabel::construct(preview_container);
m_preview_name_label->set_font(Font::default_bold_font());
m_preview_name_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_preview_name_label->set_preferred_size(0, m_preview_name_label->font().glyph_height());
m_preview_geometry_label = new GLabel(preview_container);
m_preview_geometry_label = GLabel::construct(preview_container);
m_preview_geometry_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_preview_geometry_label->set_preferred_size(0, m_preview_name_label->font().glyph_height());
}

View file

@ -47,8 +47,8 @@ private:
FileSystemPath m_selected_file;
GTextBox* m_filename_textbox { nullptr };
GLabel* m_preview_image_label { nullptr };
GLabel* m_preview_name_label { nullptr };
GLabel* m_preview_geometry_label { nullptr };
ObjectPtr<GLabel> m_preview_image_label;
ObjectPtr<GLabel> m_preview_name_label;
ObjectPtr<GLabel> m_preview_geometry_label;
Mode m_mode { Mode::Open };
};

View file

@ -34,7 +34,7 @@ void GInputBox::build()
widget->layout()->set_margins({ 8, 8, 8, 8 });
widget->layout()->set_spacing(8);
auto* label = new GLabel(m_prompt, widget);
auto label = GLabel::construct(m_prompt, widget);
label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
label->set_preferred_size(text_width, 16);

View file

@ -69,14 +69,14 @@ void GMessageBox::build()
message_container->layout()->set_margins({ 8, 0, 8, 0 });
message_container->layout()->set_spacing(8);
auto* icon_label = new GLabel(message_container);
auto icon_label = GLabel::construct(message_container);
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
icon_label->set_preferred_size(32, 32);
icon_label->set_icon(icon());
icon_width = icon_label->icon()->width();
}
auto* label = new GLabel(m_text, message_container);
auto label = GLabel::construct(m_text, message_container);
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
label->set_preferred_size(text_width, 16);

View file

@ -13,7 +13,7 @@ GStatusBar::GStatusBar(GWidget* parent)
set_layout(make<GBoxLayout>(Orientation::Horizontal));
layout()->set_margins({ 2, 2, 2, 2 });
layout()->set_spacing(2);
m_label = new GLabel(this);
m_label = GLabel::construct(this);
m_label->set_frame_shadow(FrameShadow::Sunken);
m_label->set_frame_shape(FrameShape::Panel);
m_label->set_frame_thickness(1);

View file

@ -17,6 +17,6 @@ public:
private:
virtual void paint_event(GPaintEvent&) override;
GLabel* m_label { nullptr };
ObjectPtr<GLabel> m_label;
GResizeCorner* m_corner { nullptr };
};