From 84e8bf34211f862d1c6f7d14667f8b728c054ff9 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 16 Jan 2024 15:15:43 +0000 Subject: [PATCH] NotificationServer: Convert the notification window contents to GML --- .../NotificationServer/CMakeLists.txt | 2 ++ .../NotificationServer/NotificationWidget.gml | 27 +++++++++++++++++++ .../NotificationServer/NotificationWidget.h | 23 ++++++++++++++++ .../NotificationServer/NotificationWindow.cpp | 22 +++++++-------- 4 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 Userland/Services/NotificationServer/NotificationWidget.gml create mode 100644 Userland/Services/NotificationServer/NotificationWidget.h diff --git a/Userland/Services/NotificationServer/CMakeLists.txt b/Userland/Services/NotificationServer/CMakeLists.txt index 76c97e60cf..a3fe65f7b5 100644 --- a/Userland/Services/NotificationServer/CMakeLists.txt +++ b/Userland/Services/NotificationServer/CMakeLists.txt @@ -4,12 +4,14 @@ serenity_component( TARGETS NotificationServer ) +compile_gml(NotificationWidget.gml NotificationWidgetGML.cpp) compile_ipc(NotificationServer.ipc NotificationServerEndpoint.h) compile_ipc(NotificationClient.ipc NotificationClientEndpoint.h) set(SOURCES ConnectionFromClient.cpp main.cpp + NotificationWidgetGML.cpp NotificationWindow.cpp ) diff --git a/Userland/Services/NotificationServer/NotificationWidget.gml b/Userland/Services/NotificationServer/NotificationWidget.gml new file mode 100644 index 0000000000..b54f351d16 --- /dev/null +++ b/Userland/Services/NotificationServer/NotificationWidget.gml @@ -0,0 +1,27 @@ +@NotificationServer::NotificationWidget { + layout: @GUI::HorizontalBoxLayout { + margins: [8] + spacing: 6 + } + fill_with_background_color: true + + @GUI::ImageWidget { + name: "icon" + visible: false + } + + @GUI::Widget { + layout: @GUI::VerticalBoxLayout {} + + @GUI::Label { + name: "title" + font_weight: "Bold" + text_alignment: "CenterLeft" + } + + @GUI::Label { + name: "text" + text_alignment: "CenterLeft" + } + } +} diff --git a/Userland/Services/NotificationServer/NotificationWidget.h b/Userland/Services/NotificationServer/NotificationWidget.h new file mode 100644 index 0000000000..f05c8d167f --- /dev/null +++ b/Userland/Services/NotificationServer/NotificationWidget.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace NotificationServer { + +class NotificationWidget : public GUI::Widget { + C_OBJECT_ABSTRACT(NotificationWidget) +public: + static ErrorOr> try_create(); + virtual ~NotificationWidget() override = default; + +private: + NotificationWidget() = default; +}; + +} diff --git a/Userland/Services/NotificationServer/NotificationWindow.cpp b/Userland/Services/NotificationServer/NotificationWindow.cpp index 65b454f384..c31ecfde9a 100644 --- a/Userland/Services/NotificationServer/NotificationWindow.cpp +++ b/Userland/Services/NotificationServer/NotificationWindow.cpp @@ -1,10 +1,12 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #include "NotificationWindow.h" +#include "NotificationWidget.h" #include #include #include @@ -65,25 +67,19 @@ NotificationWindow::NotificationWindow(i32 client_id, String const& text, String set_rect(rect); - auto widget = set_main_widget(); + auto widget = NotificationServer::NotificationWidget::try_create().release_value_but_fixme_should_propagate_errors(); + set_main_widget(widget); - widget->set_fill_with_background_color(true); - widget->set_layout(8, 6); - - m_image = &widget->add(); + m_image = widget->find_descendant_of_type_named("icon"sv); m_image->set_visible(icon.is_valid()); if (icon.is_valid()) { m_image->set_bitmap(icon.bitmap()); } - auto& left_container = widget->add(); - left_container.set_layout(); - - m_title_label = &left_container.add(title); - m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant()); - m_title_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); - m_text_label = &left_container.add(text); - m_text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); + m_title_label = widget->find_descendant_of_type_named("title"); + m_title_label->set_text(title); + m_text_label = widget->find_descendant_of_type_named("text"); + m_text_label->set_text(text); // FIXME: There used to be code for setting the tooltip here, but since we // expand the notification now we no longer set the tooltip. Should there be