diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml index 45d4640e730..5d878dc1ebe 100644 --- a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml +++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml @@ -17,10 +17,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/home.png" + bitmap: "/res/icons/32x32/home.png" } @GUI::Widget { @@ -76,10 +76,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/color-chooser.png" + bitmap: "/res/icons/32x32/color-chooser.png" } @GUI::Label { @@ -122,10 +122,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/search-engine.png" + bitmap: "/res/icons/32x32/search-engine.png" } @GUI::CheckBox { @@ -191,10 +191,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/downloads.png" + bitmap: "/res/icons/32x32/downloads.png" } @GUI::CheckBox { diff --git a/Userland/Applications/KeyboardSettings/Keyboard.gml b/Userland/Applications/KeyboardSettings/Keyboard.gml index a1b55886786..1c5ab59a394 100644 --- a/Userland/Applications/KeyboardSettings/Keyboard.gml +++ b/Userland/Applications/KeyboardSettings/Keyboard.gml @@ -16,10 +16,10 @@ fixed_width: 32 layout: @GUI::VerticalBoxLayout {} - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/app-keyboard-mapper.png" + bitmap: "/res/icons/32x32/app-keyboard-mapper.png" } } @@ -69,10 +69,10 @@ fixed_width: 32 layout: @GUI::VerticalBoxLayout {} - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/app-keyboard-settings.png" + bitmap: "/res/icons/32x32/app-keyboard-settings.png" } } @@ -113,10 +113,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/app-calculator.png" + bitmap: "/res/icons/32x32/app-calculator.png" } @GUI::CheckBox { diff --git a/Userland/Applications/MailSettings/MailSettingsWidget.gml b/Userland/Applications/MailSettings/MailSettingsWidget.gml index d84fb0babdf..17a73b2903b 100644 --- a/Userland/Applications/MailSettings/MailSettingsWidget.gml +++ b/Userland/Applications/MailSettings/MailSettingsWidget.gml @@ -17,10 +17,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/graphics/mail-server-settings.png" + bitmap: "/res/graphics/mail-server-settings.png" } @GUI::Label { @@ -100,10 +100,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/graphics/mail-user-settings.png" + bitmap: "/res/graphics/mail-user-settings.png" } @GUI::Label { diff --git a/Userland/Applications/MouseSettings/Mouse.gml b/Userland/Applications/MouseSettings/Mouse.gml index 6524711451a..1c5e65b8989 100644 --- a/Userland/Applications/MouseSettings/Mouse.gml +++ b/Userland/Applications/MouseSettings/Mouse.gml @@ -17,10 +17,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/graphics/mouse-cursor-speed.png" + bitmap: "/res/graphics/mouse-cursor-speed.png" } @GUI::Label { @@ -65,10 +65,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/graphics/scroll-wheel-step-size.png" + bitmap: "/res/graphics/scroll-wheel-step-size.png" } @GUI::Label { @@ -175,10 +175,10 @@ spacing: 16 } - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - name: "switch_buttons_image_label" + name: "switch_buttons_image" } @GUI::CheckBox { diff --git a/Userland/Applications/MouseSettings/MouseWidget.cpp b/Userland/Applications/MouseSettings/MouseWidget.cpp index f8d5940d9e2..71a3410d143 100644 --- a/Userland/Applications/MouseSettings/MouseWidget.cpp +++ b/Userland/Applications/MouseSettings/MouseWidget.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -51,7 +52,7 @@ MouseWidget::MouseWidget() set_modified(true); }; - m_switch_buttons_image_label = *find_descendant_of_type_named("switch_buttons_image_label"); + m_switch_buttons_image = *find_descendant_of_type_named("switch_buttons_image"); m_switch_buttons_checkbox = *find_descendant_of_type_named("switch_buttons_checkbox"); m_switch_buttons_checkbox->set_checked(GUI::ConnectionToWindowServer::the().are_mouse_buttons_switched(), GUI::AllowCallback::No); m_switch_buttons_checkbox->on_checked = [&](auto) { @@ -103,8 +104,8 @@ void MouseWidget::update_double_click_speed_label() void MouseWidget::update_switch_buttons_image_label() { if (m_switch_buttons_checkbox->is_checked()) { - m_switch_buttons_image_label->set_icon_from_path("/res/graphics/mouse-button-right.png"sv); + m_switch_buttons_image->load_from_file("/res/graphics/mouse-button-right.png"sv); } else { - m_switch_buttons_image_label->set_icon_from_path("/res/graphics/mouse-button-left.png"sv); + m_switch_buttons_image->load_from_file("/res/graphics/mouse-button-left.png"sv); } } diff --git a/Userland/Applications/MouseSettings/MouseWidget.h b/Userland/Applications/MouseSettings/MouseWidget.h index c4e3835fcc7..269e3fdfc29 100644 --- a/Userland/Applications/MouseSettings/MouseWidget.h +++ b/Userland/Applications/MouseSettings/MouseWidget.h @@ -32,7 +32,7 @@ private: RefPtr m_double_click_speed_slider; RefPtr m_double_click_speed_label; RefPtr m_switch_buttons_checkbox; - RefPtr m_switch_buttons_image_label; + RefPtr m_switch_buttons_image; RefPtr m_natural_scroll_checkbox; RefPtr m_double_click_arrow_widget; }; diff --git a/Userland/Applications/NetworkSettings/NetworkSettings.gml b/Userland/Applications/NetworkSettings/NetworkSettings.gml index 326f2567b8c..bc1f27af4dc 100644 --- a/Userland/Applications/NetworkSettings/NetworkSettings.gml +++ b/Userland/Applications/NetworkSettings/NetworkSettings.gml @@ -11,10 +11,10 @@ } fixed_height: 40 - @GUI::Label { + @GUI::ImageWidget { fixed_width: 32 fixed_height: 32 - icon: "/res/icons/32x32/network.png" + bitmap: "/res/icons/32x32/network.png" } @GUI::Label { diff --git a/Userland/Applications/SystemMonitor/ProcessWindow.gml b/Userland/Applications/SystemMonitor/ProcessWindow.gml index 3304a90e0e5..5cd9e3d52af 100644 --- a/Userland/Applications/SystemMonitor/ProcessWindow.gml +++ b/Userland/Applications/SystemMonitor/ProcessWindow.gml @@ -11,8 +11,8 @@ spacing: 8 } - @GUI::Label { - name: "icon_label" + @GUI::ImageWidget { + name: "process_icon" fixed_size: [32, 32] } diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index 8ffe417bc97..6747f9bc78b 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -539,7 +540,7 @@ ErrorOr> build_process_window(pid_t pid) VERIFY(process_index.is_valid()); if (auto icon_data = process_index.sibling_at_column(ProcessModel::Column::Icon).data(); icon_data.is_icon()) { - main_widget->find_descendant_of_type_named("icon_label")->set_icon(icon_data.as_icon().bitmap_for_size(32)); + main_widget->find_descendant_of_type_named("process_icon")->set_bitmap(icon_data.as_icon().bitmap_for_size(32)); } main_widget->find_descendant_of_type_named("process_name")->set_text(String::formatted("{} (PID {})", process_index.sibling_at_column(ProcessModel::Column::Name).data().to_deprecated_string(), pid).release_value_but_fixme_should_propagate_errors()); diff --git a/Userland/Applications/Welcome/WelcomeWindow.gml b/Userland/Applications/Welcome/WelcomeWindow.gml index 233bfc8c470..63ce306beef 100644 --- a/Userland/Applications/Welcome/WelcomeWindow.gml +++ b/Userland/Applications/Welcome/WelcomeWindow.gml @@ -34,10 +34,10 @@ fixed_width: 60 layout: @GUI::VerticalBoxLayout {} - @GUI::Label { - name: "light_bulb_label" + @GUI::ImageWidget { fixed_height: 60 - icon: "/res/icons/32x32/app-welcome.png" + auto_resize: false + bitmap: "/res/icons/32x32/app-welcome.png" } } diff --git a/Userland/Games/Minesweeper/Field.cpp b/Userland/Games/Minesweeper/Field.cpp index 5455ea8012c..bd18cc105ca 100644 --- a/Userland/Games/Minesweeper/Field.cpp +++ b/Userland/Games/Minesweeper/Field.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -46,8 +47,8 @@ private: } }; -class SquareLabel final : public GUI::Label { - C_OBJECT(SquareLabel); +class SquareImage final : public GUI::ImageWidget { + C_OBJECT(SquareImage); public: Function on_chord_click; @@ -68,7 +69,7 @@ public: } }); } - GUI::Label::mousedown_event(event); + GUI::ImageWidget::mousedown_event(event); } virtual void mousemove_event(GUI::MouseEvent& event) override @@ -80,7 +81,7 @@ public: m_square.field->set_chord_preview(m_square, false); } } - GUI::Label::mousemove_event(event); + GUI::ImageWidget::mousemove_event(event); } virtual void mouseup_event(GUI::MouseEvent& event) override @@ -95,11 +96,11 @@ public: } } m_square.field->set_chord_preview(m_square, m_chord); - GUI::Label::mouseup_event(event); + GUI::ImageWidget::mouseup_event(event); } private: - explicit SquareLabel(Square& square) + explicit SquareImage(Square& square) : m_square(square) { } @@ -225,7 +226,7 @@ void Field::reset() for (int i = rows() * columns(); i < static_cast(m_squares.size()); ++i) { auto& square = m_squares[i]; square->button->set_visible(false); - square->label->set_visible(false); + square->image->set_visible(false); } size_t i = 0; @@ -242,15 +243,15 @@ void Field::reset() square.has_flag = false; square.is_considering = false; square.is_swept = false; - if (!square.label) { - square.label = add(square); - square.label->set_palette(m_mine_palette); - square.label->set_background_role(Gfx::ColorRole::Base); + if (!square.image) { + square.image = add(square); + square.image->set_palette(m_mine_palette); + square.image->set_background_role(Gfx::ColorRole::Base); } - square.label->set_fill_with_background_color(false); - square.label->set_relative_rect(rect); - square.label->set_visible(false); - square.label->set_icon(nullptr); + square.image->set_fill_with_background_color(false); + square.image->set_relative_rect(rect); + square.image->set_visible(false); + square.image->set_bitmap(nullptr); if (!square.button) { square.button = add(); square.button->on_click = [this, &square](auto) { @@ -262,7 +263,7 @@ void Field::reset() square.button->on_middle_click = [this, &square] { on_square_middle_clicked(square); }; - square.label->on_chord_click = [this, &square] { + square.image->on_chord_click = [this, &square] { on_square_chorded(square); }; } @@ -325,9 +326,9 @@ void Field::generate_field(size_t start_row, size_t start_column) }); square.number = number; if (square.has_mine) { - square.label->set_icon(m_mine_bitmap); + square.image->set_bitmap(m_mine_bitmap); } else if (square.number) { - square.label->set_icon(m_number_bitmap[square.number - 1]); + square.image->set_bitmap(m_number_bitmap[square.number - 1]); } } } @@ -395,9 +396,9 @@ void Field::on_square_clicked_impl(Square& square, bool should_flood_fill) update(); square.is_swept = true; square.button->set_visible(false); - square.label->set_visible(true); + square.image->set_visible(true); if (square.has_mine) { - square.label->set_fill_with_background_color(true); + square.image->set_fill_with_background_color(true); game_over(); return; } @@ -507,12 +508,12 @@ void Field::reveal_mines() auto& square = this->square(r, c); if (square.has_mine && !square.has_flag) { square.button->set_visible(false); - square.label->set_visible(true); + square.image->set_visible(true); } if (!square.has_mine && square.has_flag) { square.button->set_icon(*m_badflag_bitmap); square.button->set_visible(true); - square.label->set_visible(false); + square.image->set_visible(false); } } } diff --git a/Userland/Games/Minesweeper/Field.h b/Userland/Games/Minesweeper/Field.h index 609d3379561..46fc13cf060 100644 --- a/Userland/Games/Minesweeper/Field.h +++ b/Userland/Games/Minesweeper/Field.h @@ -14,7 +14,7 @@ class Field; class SquareButton; -class SquareLabel; +class SquareImage; class Square { AK_MAKE_NONCOPYABLE(Square); @@ -32,7 +32,7 @@ public: size_t column { 0 }; size_t number { 0 }; RefPtr button; - RefPtr label; + RefPtr image; template void for_each_neighbor(Callback); @@ -41,7 +41,7 @@ public: class Field final : public GUI::Frame { C_OBJECT(Field) friend class Square; - friend class SquareLabel; + friend class SquareImage; public: static ErrorOr> create(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button); diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp index 7368d50976a..6cddff3f01e 100644 --- a/Userland/Libraries/LibGUI/Label.cpp +++ b/Userland/Libraries/LibGUI/Label.cpp @@ -33,7 +33,6 @@ Label::Label(String text) REGISTER_STRING_PROPERTY("text", text, set_text); REGISTER_BOOL_PROPERTY("autosize", is_autosize, set_autosize); - REGISTER_WRITE_ONLY_STRING_PROPERTY("icon", set_icon_from_path); } void Label::set_autosize(bool autosize, size_t padding) @@ -46,24 +45,6 @@ void Label::set_autosize(bool autosize, size_t padding) size_to_fit(); } -void Label::set_icon(Gfx::Bitmap const* icon) -{ - if (m_icon == icon) - return; - m_icon = icon; - update(); -} - -void Label::set_icon_from_path(StringView path) -{ - auto maybe_bitmap = Gfx::Bitmap::load_from_file(path); - if (maybe_bitmap.is_error()) { - dbgln("Unable to load bitmap `{}` for label icon", path); - return; - } - set_icon(maybe_bitmap.release_value()); -} - void Label::set_text(String text) { if (text == m_text) @@ -88,15 +69,6 @@ void Label::paint_event(PaintEvent& event) Painter painter(*this); painter.add_clip_rect(event.rect()); - if (m_icon) { - if (m_should_stretch_icon) { - painter.draw_scaled_bitmap(frame_inner_rect(), *m_icon, m_icon->rect()); - } else { - auto icon_location = frame_inner_rect().center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)); - painter.blit(icon_location, *m_icon, m_icon->rect()); - } - } - if (text().is_empty()) return; diff --git a/Userland/Libraries/LibGUI/Label.h b/Userland/Libraries/LibGUI/Label.h index e6499180c6c..9a1344a29cc 100644 --- a/Userland/Libraries/LibGUI/Label.h +++ b/Userland/Libraries/LibGUI/Label.h @@ -22,19 +22,12 @@ public: String const& text() const { return m_text; } void set_text(String); - void set_icon(Gfx::Bitmap const*); - void set_icon_from_path(StringView); - Gfx::Bitmap const* icon() const { return m_icon.ptr(); } - Gfx::TextAlignment text_alignment() const { return m_text_alignment; } void set_text_alignment(Gfx::TextAlignment text_alignment) { m_text_alignment = text_alignment; } Gfx::TextWrapping text_wrapping() const { return m_text_wrapping; } void set_text_wrapping(Gfx::TextWrapping text_wrapping) { m_text_wrapping = text_wrapping; } - bool should_stretch_icon() const { return m_should_stretch_icon; } - void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; } - bool is_autosize() const { return m_autosize; } void set_autosize(bool, size_t padding = 0); @@ -56,10 +49,8 @@ private: void size_to_fit(); String m_text; - RefPtr m_icon; Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center }; Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap }; - bool m_should_stretch_icon { false }; bool m_autosize { false }; size_t m_autosize_padding { 0 }; }; diff --git a/Userland/Libraries/LibGUI/PasswordInputDialog.cpp b/Userland/Libraries/LibGUI/PasswordInputDialog.cpp index ee046d9546e..106aa39d97e 100644 --- a/Userland/Libraries/LibGUI/PasswordInputDialog.cpp +++ b/Userland/Libraries/LibGUI/PasswordInputDialog.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -25,9 +26,9 @@ PasswordInputDialog::PasswordInputDialog(Window* parent_window, DeprecatedString auto widget = set_main_widget().release_value_but_fixme_should_propagate_errors(); widget->load_from_gml(password_input_dialog_gml).release_value_but_fixme_should_propagate_errors(); - auto& key_icon_label = *widget->find_descendant_of_type_named("key_icon_label"); + auto& key_icon = *widget->find_descendant_of_type_named("key_icon"); - key_icon_label.set_icon(Gfx::Bitmap::load_from_file("/res/icons/32x32/key.png"sv).release_value_but_fixme_should_propagate_errors()); + key_icon.set_bitmap(Gfx::Bitmap::load_from_file("/res/icons/32x32/key.png"sv).release_value_but_fixme_should_propagate_errors()); auto& server_label = *widget->find_descendant_of_type_named("server_label"); server_label.set_text(String::from_deprecated_string(server).release_value_but_fixme_should_propagate_errors()); diff --git a/Userland/Libraries/LibGUI/PasswordInputDialog.gml b/Userland/Libraries/LibGUI/PasswordInputDialog.gml index 316393a6c05..9beb266e5da 100644 --- a/Userland/Libraries/LibGUI/PasswordInputDialog.gml +++ b/Userland/Libraries/LibGUI/PasswordInputDialog.gml @@ -9,8 +9,8 @@ shrink_to_fit: true layout: @GUI::VerticalBoxLayout {} - @GUI::Label { - name: "key_icon_label" + @GUI::ImageWidget { + name: "key_icon" fixed_height: 32 fixed_width: 32 }