GUI Applications
Strata lets you build desktop applications with GTK4. The built-in bindings are currently minimal, but you can still access the full GTK4 API through FFI while keeping Strata's type safety for the parts it defines.
Getting Started
To build a GUI application, you'll typically need a project structure that includes your Strata source files and any necessary assets (like .str.ui or .css files).
Requirements
Install GTK4 before building or running GUI applications:
Ubuntu/Debian:
sudo apt install libgtk-4-devmacOS:
brew install gtk4Project Configuration
Enable the GTK extension strata_gtk and configuration in your .strata.json:
{
"srcDir": "src",
"buildDir": "build",
"entryPoint": "src/app.str",
"runtime": {
"extensions": [
"/path/to/strata_gtk.so"
],
"ini": {
"ffi.enable": "1"
}
}
}Basic Application
A minimal GTK4 application in Strata involves initializing the App class and setting up a window in the onStartup handler.
import Strata.Gtk.App;
fn main(): Void {
let app = App(options: [
'prgname' => 'strata-gtk-app',
'appname' => 'Hello Strata',
'builder_only' => false,
]);
app.onStartup(handler: (app: App) => {
let window = app.window();
window.title(title: 'Hello World');
window.defaultSize(width: 480, height: 240);
// add a simple label
let label = app.label(text: 'Hello from Strata + GTK4!');
window.child(child: label);
window.show();
});
app.run();
}Project Structure
For a GUI project, you might have a structure like this:
.
├── .strata.json
└── src/
├── app.str
└── assets/
├── styles.css
└── MainWindow.str.uiRunning the Application
You can run your GUI application using the standard run command:
strata run src/app.strStrata will automatically:
- Compile your code.
- Ensure the
ffiextension is loaded. - Discover and use your project's autoloader.
- Copy any associated assets to the execution environment.
Additional Resources
For more detailed information on GTK4, refer to the GTK4 documentation.