slint
slint copied to clipboard
Bindings to the Swift programming language
A Swift compiler exists not only for the Apple ecosystem but also for Windows and Linux but SwiftUI can only be used for Apple devices. Furthermore, Qt is a cross plattform framework, but only supports C++ and Python. Maybe, Slint can fill a gap, and become a cross plattform framework for Swift. Furthermore, I am not aware of any UI framework that supports Swift on Windows.
We aim to support multiple programming language in the future. That said, Swift is not a priority for us considering that Swift already has a natural UI framework and that Swift is not really popular on Linux and Windows. But if someone were to contribute Swift bindings, we'd happily assist them.
We aim to support multiple programming language in the future. That said, Swift is not a priority for us considering that Swift already has a natural UI framework and that Swift is not really popular on Linux and Windows. But if someone were to contribute Swift bindings, we'd happily assist them.
@ogoffart Is there a guide how to develop bindings for other programming languages?
We don't have such a guide.
There is two things to do:
- wrap the API to the slint runtime
- Create a code generator for the swift language.
For example, for C++, the wrapper is in https://github.com/slint-ui/slint/tree/master/api/cpp , and the code generator in https://github.com/slint-ui/slint/blob/master/internal/compiler/generator/cpp.rs
The best would be, I guess, to look at that and try to do something similar for swift.
If you are interested, I'd be happy to answer any questions you have, here or by chat or so.
I've spent a few weeks taking a crack at it. I'm no longer interested in pursuing this, but if someone else wants to this could be a good starting point.
Here's my result: https://github.com/illucid-matthew/slint-swift-bindings
The main things I accomplished are:
- Importing the private
cbindgen
API into Swift - Integrating the Slint event loop and main-thread requirements into Swift's concurrency model
- Basic application framework
- Create a type that conforms to
SlintApp
- Write a
start()
method to initialize your UI - Event loop starts when
start()
is finished
- Create a type that conforms to
Example:
import SlintUI
@main
struct ExampleApp: SlintApp {
static func start() {
print("⏰ Setting up a timer to fire in three seconds…")
let timer = SlintTimer()
timer.willRun(after: 3000) {
print("⏰ Timer fired!")
}
}
}
I also converted timer
and callback
, but the latter runs into a strange bug that that I'm not inclined to track down.
Beyond that, there are a few unfinished core library types, and a minor attempt to create bindings for the interpreter API.
Great that you managed to get that far with Swift bindings - thanks for sharing!