Building a GUI application as part of SerenityOS is easy, and has been done plenty of times. Just take a look at any of the existing ones, or read the

How To Build a Standalone GUI Application for SerenityOS

submited by
Style Pass
2022-05-12 20:30:03

Building a GUI application as part of SerenityOS is easy, and has been done plenty of times. Just take a look at any of the existing ones, or read the (slightly outdated!) Introduction to SerenityOS GUI programming on Andreas' blog.

But what if you wanted to build one that exists as a standalone project and is not part of the SerenityOS repository, and instead installed as a port, or not open source in the first place? That's also possible, but not entirely straightforward — especially when using GML, Serenity's very own GUI Markup Language.

You might have noticed that we include a file in our program which I didn't mention yet, ExampleWindowGML.h, which is where the example_window_gml variable is defined. Generally speaking, the load_from_gml() function just takes a StringView, so we could define our GML source in the C++ file and pass it to that function directly.

That's ugly though and kind of defeats the point of trying to separate the GUI declaration from the program logic. So instead, we let CMake generate a header file from our GML source file!

Leave a Comment