mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
Base: Port serenity-application template to LibMain
This commit is contained in:
parent
ddeacce905
commit
2aff8b4a27
2 changed files with 14 additions and 18 deletions
|
@ -24,5 +24,5 @@ serenity_app($1 ICON filetype-executable)
|
||||||
# You should place all the libraries that your application uses here. You can
|
# 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
|
# identify each library by their include path. An exception is LibCore, which
|
||||||
# is linked to all components by default.
|
# is linked to all components by default.
|
||||||
target_link_libraries($1 LibGUI LibGfx)
|
target_link_libraries($1 LibGUI LibGfx LibMain)
|
||||||
EOF
|
EOF
|
||||||
|
|
|
@ -1,37 +1,33 @@
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/Frame.h>
|
#include <LibGUI/Frame.h>
|
||||||
#include <LibGUI/MessageBox.h>
|
#include <LibGUI/MessageBox.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <unistd.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) {
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath unix"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto app = GUI::Application::construct(argc, argv);
|
auto app = TRY(GUI::Application::try_create(arguments));
|
||||||
|
|
||||||
if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto window = GUI::Window::construct();
|
auto window = TRY(GUI::Window::try_create());
|
||||||
window->set_title("Form1");
|
window->set_title("Form1");
|
||||||
window->resize(96, 44);
|
window->resize(96, 44);
|
||||||
window->set_resizable(false);
|
window->set_resizable(false);
|
||||||
|
|
||||||
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||||
main_widget.set_fill_with_background_color(true);
|
main_widget->set_fill_with_background_color(true);
|
||||||
|
|
||||||
auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
|
auto layout = TRY(main_widget->try_set_layout<GUI::VerticalBoxLayout>());
|
||||||
layout.set_margins(16);
|
layout->set_margins(16);
|
||||||
|
|
||||||
auto& button = main_widget.add<GUI::Button>("Click me!");
|
auto button = TRY(main_widget->try_add<GUI::Button>("Click me!"));
|
||||||
button.on_click = [&](auto) {
|
button->on_click = [&](auto) {
|
||||||
GUI::MessageBox::show(window, "Hello friends!", ":^)");
|
GUI::MessageBox::show(window, "Hello friends!", ":^)");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue