https://github.com/TomasLinhart/SwiftGtk
SwiftGtk is an experimental Gtk+ binding for Swift that tries to make usage of Gtk+ pleasant and "Swifty" as much as possible.
https://github.com/TomasLinhart/SwiftGtk
gtk swift
Last synced: 6 months ago
JSON representation
SwiftGtk is an experimental Gtk+ binding for Swift that tries to make usage of Gtk+ pleasant and "Swifty" as much as possible.
- Host: GitHub
- URL: https://github.com/TomasLinhart/SwiftGtk
- Owner: TomasLinhart
- License: mit
- Created: 2016-01-04T22:58:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-06T13:12:44.000Z (almost 3 years ago)
- Last Synced: 2023-11-07T17:25:16.197Z (over 1 year ago)
- Topics: gtk, swift
- Language: Swift
- Homepage:
- Size: 651 KB
- Stars: 304
- Watchers: 22
- Forks: 34
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# SwiftGtk
SwiftGtk is a experimental Gtk+ binding for Swift that tries to make usage of Gtk+ pleasant and "Swifty" as much as possible. Currently it implements only a small subset of Gtk+ and it works on Mac OS X and Linux.
## Dependencies
You need to have Swift 3.1 or higher installed on your computer (tested with 3.1.1 bundled with Xcode 8.3.3) and depending on your platform you need to install Gtk+3. On Mac OS X you can also build the project with Xcode.
### Mac OS X
You need to have Gtk+3 installed on your machine. Recommended way for installing Gtk+3 is through [homebrew](http://brew.sh/).
```bash
brew install gtk+3
```### Linux
You need to have Gtk+3 and Clang installed on your machine. You can easily install them with `apt-get`.
```bash
sudo apt-get install libgtk-3-dev clang
```## Usage
SwiftGtk supports [Swift Package Manager](https://github.com/apple/swift-package-manager) so you only need to add SwiftGtk to your `Package.swift`.
```swift
import PackageDescriptionlet package = Package(
name: "SwiftGtkApplication",
dependencies: [
.Package(url: "https://github.com/TomasLinhart/SwiftGtk", Version(0, 3, 1))
]
)
```After that run `swift build` in the folder where `Package.swift` is located. Once it builds you can execute the application `.build/debug/SwiftGtkApplication`.
## Demo
Following code will create a window with a button that when it is pressed presents another window.
```swift
import SwiftGtklet app = Application(applicationId: "com.example.application")
app.run { window in
window.title = "Hello World"
window.defaultSize = Size(width: 400, height: 400)
window.resizable = truelet button = Button(label: "Press Me")
button.clicked = { _ in
let newWindow = Window(windowType: .topLevel)
newWindow.title = "Just a window"
newWindow.defaultSize = Size(width: 200, height: 200)
let labelPressed = Label(text: "Oh, you pressed the button.")
newWindow.add(labelPressed)newWindow.showAll()
}window.add(button)
}
```
## License
All code is licensed under MIT license.