Base: Port serenity-application template to LibMain

This commit is contained in:
Dolphin von Chips 2022-01-07 17:19:55 +05:00 committed by Linus Groh
parent ddeacce905
commit 2aff8b4a27
Notes: sideshowbarker 2024-07-19 17:11:16 +09:00
2 changed files with 14 additions and 18 deletions

View File

@ -24,5 +24,5 @@ serenity_app($1 ICON filetype-executable)
# You should place all the libraries that your application uses here. You can
# identify each library by their include path. An exception is LibCore, which
# is linked to all components by default.
target_link_libraries($1 LibGUI LibGfx)
target_link_libraries($1 LibGUI LibGfx LibMain)
EOF

View File

@ -1,37 +1,33 @@
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/Frame.h>
#include <LibGUI/MessageBox.h>
#include <LibMain/Main.h>
#include <unistd.h>
int main(int argc, char** argv)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (pledge("stdio recvfd sendfd rpath wpath cpath unix", nullptr) < 0) {
perror("pledge");
return 1;
}
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath unix"));
auto app = GUI::Application::construct(argc, argv);
auto app = TRY(GUI::Application::try_create(arguments));
if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) {
perror("pledge");
return 1;
}
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
auto window = GUI::Window::construct();
auto window = TRY(GUI::Window::try_create());
window->set_title("Form1");
window->resize(96, 44);
window->set_resizable(false);
auto& main_widget = window->set_main_widget<GUI::Widget>();
main_widget.set_fill_with_background_color(true);
auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
main_widget->set_fill_with_background_color(true);
auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
layout.set_margins(16);
auto layout = TRY(main_widget->try_set_layout<GUI::VerticalBoxLayout>());
layout->set_margins(16);
auto& button = main_widget.add<GUI::Button>("Click me!");
button.on_click = [&](auto) {
auto button = TRY(main_widget->try_add<GUI::Button>("Click me!"));
button->on_click = [&](auto) {
GUI::MessageBox::show(window, "Hello friends!", ":^)");
};