slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.72k stars 615 forks source link

Bindings to the Swift programming language #1005

Open PetaSoft opened 2 years ago

PetaSoft commented 2 years ago

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.

ogoffart commented 2 years ago

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.

thbonk commented 2 years ago

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?

ogoffart commented 2 years ago

We don't have such a guide.

There is two things to do:

  1. wrap the API to the slint runtime
  2. 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.

illucid-matthew commented 9 months ago

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:

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.

tronical commented 9 months ago

Great that you managed to get that far with Swift bindings - thanks for sharing!