mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 11:47:35 +00:00
Base: Add the serenity-application HackStudio template
This is a template which instantiates into what you'd write to start out a basic Serenity GUI application. It contains a CMakeLists.txt file which describes what each declaration does, a simple GUI application which uses layouts, widgets and callbacks, and comes with a minimal set of pledges which the user can add to as necessary.
This commit is contained in:
parent
949d27f21b
commit
7adc5725b8
4 changed files with 73 additions and 0 deletions
5
Base/res/devel/templates/serenity-application.ini
Normal file
5
Base/res/devel/templates/serenity-application.ini
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[HackStudioTemplate]
|
||||||
|
Name=SerenityOS GUI Application (C++)
|
||||||
|
Description=Template for creating a GUI-based SerenityOS application with CMake.
|
||||||
|
Priority=90
|
||||||
|
IconName32x=serenity-application
|
28
Base/res/devel/templates/serenity-application.postcreate
Normal file
28
Base/res/devel/templates/serenity-application.postcreate
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo > $2/CMakeLists.txt <<-EOF
|
||||||
|
# NOTE! Make sure to edit this file and remove the comments before submitting a
|
||||||
|
# PR for a new application.
|
||||||
|
|
||||||
|
# Defines your application component. If the application is essential to the
|
||||||
|
# system's operation, add REQUIRED. If it would be beneficial for the user that
|
||||||
|
# this application is built by default, add RECOMMENDED.
|
||||||
|
serenity_component(
|
||||||
|
$1
|
||||||
|
TARGETS $1
|
||||||
|
)
|
||||||
|
|
||||||
|
# Place source files here. You should also add auto-generated headers, if you
|
||||||
|
# have any.
|
||||||
|
set(SOURCES
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Change this to something cool. :^)
|
||||||
|
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)
|
||||||
|
EOF
|
40
Base/res/devel/templates/serenity-application/main.cpp
Normal file
40
Base/res/devel/templates/serenity-application/main.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include <LibGUI/Application.h>
|
||||||
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
#include <LibGUI/Button.h>
|
||||||
|
#include <LibGUI/Frame.h>
|
||||||
|
#include <LibGUI/MessageBox.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (pledge("stdio recvfd sendfd rpath wpath cpath unix", nullptr) < 0) {
|
||||||
|
perror("pledge");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto app = GUI::Application::construct(argc, argv);
|
||||||
|
|
||||||
|
if (pledge("stdio recvfd sendfd rpath", nullptr) < 0) {
|
||||||
|
perror("pledge");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto window = GUI::Window::construct();
|
||||||
|
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& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||||
|
layout.set_margins({ 16, 16, 16, 16 });
|
||||||
|
|
||||||
|
auto& button = main_widget.add<GUI::Button>("Click me!");
|
||||||
|
button.on_click = [&](auto) {
|
||||||
|
GUI::MessageBox::show(window, "Hello friends!", ":^)");
|
||||||
|
};
|
||||||
|
|
||||||
|
window->show();
|
||||||
|
return app->exec();
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 7.7 KiB |
Loading…
Add table
Add a link
Reference in a new issue