mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
LibGfxDemo: Use TRY() a lot more :^)
This commit is contained in:
parent
abf86b7501
commit
dee90b2dc3
Notes:
sideshowbarker
2024-07-18 00:40:57 +09:00
Author: https://github.com/pbrw Commit: https://github.com/SerenityOS/serenity/commit/dee90b2dc31 Pull-request: https://github.com/SerenityOS/serenity/pull/11052
@ -8,4 +8,4 @@ set(SOURCES
|
||||
)
|
||||
|
||||
serenity_app(LibGfxDemo ICON app-libgfx-demo)
|
||||
target_link_libraries(LibGfxDemo LibGUI LibIPC LibGfx LibCore)
|
||||
target_link_libraries(LibGfxDemo LibGUI LibIPC LibGfx LibCore LibMain)
|
||||
|
@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
@ -16,6 +17,7 @@
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibGfx/Path.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const int WIDTH = 780;
|
||||
@ -182,37 +184,26 @@ void Canvas::draw()
|
||||
update();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
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", nullptr));
|
||||
TRY(Core::System::unveil("/res", "r"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
if (unveil("/res", "r") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil(nullptr, nullptr) < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto window = GUI::Window::construct();
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_double_buffering_enabled(true);
|
||||
window->set_title("LibGfx Demo");
|
||||
window->set_resizable(false);
|
||||
window->resize(WIDTH, HEIGHT);
|
||||
|
||||
auto& file_menu = window->add_menu("&File");
|
||||
file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
|
||||
auto file_menu = TRY(window->try_add_menu("&File"));
|
||||
TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })));
|
||||
|
||||
auto app_icon = GUI::Icon::default_icon("app-libgfx-demo");
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
window->set_main_widget<Canvas>();
|
||||
TRY(window->try_set_main_widget<Canvas>());
|
||||
window->show();
|
||||
|
||||
return app->exec();
|
||||
|
Loading…
Reference in New Issue
Block a user