NotificationServer: Convert the notification window contents to GML

This commit is contained in:
Sam Atkins 2024-01-16 15:15:43 +00:00 committed by Tim Flynn
parent e4c7b9817b
commit 84e8bf3421
Notes: sideshowbarker 2024-07-17 06:28:38 +09:00
4 changed files with 61 additions and 13 deletions

View File

@ -4,12 +4,14 @@ serenity_component(
TARGETS NotificationServer TARGETS NotificationServer
) )
compile_gml(NotificationWidget.gml NotificationWidgetGML.cpp)
compile_ipc(NotificationServer.ipc NotificationServerEndpoint.h) compile_ipc(NotificationServer.ipc NotificationServerEndpoint.h)
compile_ipc(NotificationClient.ipc NotificationClientEndpoint.h) compile_ipc(NotificationClient.ipc NotificationClientEndpoint.h)
set(SOURCES set(SOURCES
ConnectionFromClient.cpp ConnectionFromClient.cpp
main.cpp main.cpp
NotificationWidgetGML.cpp
NotificationWindow.cpp NotificationWindow.cpp
) )

View File

@ -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"
}
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGUI/Widget.h>
namespace NotificationServer {
class NotificationWidget : public GUI::Widget {
C_OBJECT_ABSTRACT(NotificationWidget)
public:
static ErrorOr<NonnullRefPtr<NotificationWidget>> try_create();
virtual ~NotificationWidget() override = default;
private:
NotificationWidget() = default;
};
}

View File

@ -1,10 +1,12 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include "NotificationWindow.h" #include "NotificationWindow.h"
#include "NotificationWidget.h"
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/Vector.h> #include <AK/Vector.h>
@ -65,25 +67,19 @@ NotificationWindow::NotificationWindow(i32 client_id, String const& text, String
set_rect(rect); set_rect(rect);
auto widget = set_main_widget<GUI::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); m_image = widget->find_descendant_of_type_named<GUI::ImageWidget>("icon"sv);
widget->set_layout<GUI::HorizontalBoxLayout>(8, 6);
m_image = &widget->add<GUI::ImageWidget>();
m_image->set_visible(icon.is_valid()); m_image->set_visible(icon.is_valid());
if (icon.is_valid()) { if (icon.is_valid()) {
m_image->set_bitmap(icon.bitmap()); m_image->set_bitmap(icon.bitmap());
} }
auto& left_container = widget->add<GUI::Widget>(); m_title_label = widget->find_descendant_of_type_named<GUI::Label>("title");
left_container.set_layout<GUI::VerticalBoxLayout>(); m_title_label->set_text(title);
m_text_label = widget->find_descendant_of_type_named<GUI::Label>("text");
m_title_label = &left_container.add<GUI::Label>(title); m_text_label->set_text(text);
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<GUI::Label>(text);
m_text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
// FIXME: There used to be code for setting the tooltip here, but since we // 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 // expand the notification now we no longer set the tooltip. Should there be