Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Add support for auto-generated widget bindings
Browse files Browse the repository at this point in the history
Additionally fix an update problem occurring with custom views
  • Loading branch information
david-swift committed Jan 22, 2024
1 parent e5b5459 commit d8de611
Show file tree
Hide file tree
Showing 158 changed files with 13,296 additions and 3,047 deletions.
8 changes: 0 additions & 8 deletions .github/ISSUE_TEMPLATE/component_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ body:
validations:
required: false

- type: textarea
attributes:
label: Name the equivalents in Libadwaita.
placeholder: >-
A list of the equivalents in the Libadwaita library (see dependencies).
validations:
required: true

- type: textarea
attributes:
label: Describe your idea for the implementation.
Expand Down
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ type_contents_order:
- view_life_cycle_method
- ib_action
- other_method

excluded:
- Sources/Adwaita/View/Generated/
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Open the project folder in GNOME Builder, Xcode or another IDE.
- `User Interface` contains protocols and structures that are the basis of presenting content to the user.
- `View` contains structures that conform to the `View` protocol and provide an easier-to-use wrapper around a GTUI `NativeWidgetPeer` type.
- `Window` contains structures that conform to the `Window` protocol and simplify the creation of different types of windows.
- `CAdw` contains the reference to the C library.
- `Generation` contains the code for the auto-generation of Adwaita and Gtk widgets.
- `Tests` contains an example application for testing `Adwaita`.

### 4. Edit the Code
Expand Down
696 changes: 21 additions & 675 deletions LICENSE.md

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,39 @@ let package = Package(
.library(
name: "Adwaita",
targets: ["Adwaita"]
),
.library(
name: "CAdw",
targets: ["CAdw"]
)
],
dependencies: [
.package(url: "https://github.com/AparokshaUI/Libadwaita", from: "0.1.6"),
.package(
url: "https://github.com/david-swift/LevenshteinTransformations",
from: "0.1.1"
)
),
.package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1")
],
targets: [
.systemLibrary(
name: "CAdw",
pkgConfig: "libadwaita-1"
),
.target(
name: "Adwaita",
dependencies: [
.product(name: "Libadwaita", package: "Libadwaita"),
"CAdw",
.product(name: "LevenshteinTransformations", package: "LevenshteinTransformations")
]
),
.executableTarget(
name: "Swift Adwaita Demo",
name: "Generation",
dependencies: [
.product(name: "XMLCoder", package: "XMLCoder")
]
),
.executableTarget(
name: "Demo",
dependencies: ["Adwaita"],
path: "Tests"
)
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<img width="256" alt="Adwaita Icon" src="Icons/AdwaitaIcon.png">
<h1 align="center">Adwaita</h1>
<h1 align="center">Adwaita for Swift</h1>
</p>

<p align="center">
Expand Down Expand Up @@ -110,15 +110,17 @@ I recommend using the [template repository](https://github.com/AparokshaUI/Adwai
### Information

* [Widgets](user-manual/Information/Widgets.md)
* [Auto-Generated Widgets](user-manual/Information/AutoGeneratedWidgets.md)

## Thanks

### Dependencies
- [Libadwaita][18] licensed under the [GPL-3.0 license][19]
- [XMLCoder][18] licensed under the [MIT license][19]
- [Levenshtein Transformations](https://github.com/david-swift/LevenshteinTransformations) licensed under the [MIT license](https://github.com/david-swift/LevenshteinTransformations/blob/main/LICENSE.md)

### Other Thanks
- The [contributors][20]
- The auto-generation of widgets is based on [Swift Cross UI](https://github.com/stackotter/swift-cross-ui)
- [SwiftLint][21] for checking whether code style conventions are violated
- The programming language [Swift][22]
- [SourceDocs][23] used for generating the [docs][24]
Expand All @@ -140,8 +142,8 @@ I recommend using the [template repository](https://github.com/AparokshaUI/Adwai
[15]: user-manual/Basics/Windows.md
[16]: user-manual/Basics/KeyboardShortcuts.md
[17]: user-manual/Advanced/CreatingWidgets.md
[18]: https://github.com/AparokshaUI/Libadwaita
[19]: https://github.com/AparokshaUI/Libadwaita/blob/main/LICENSE.md
[18]: https://github.com/CoreOffice/XMLCoder
[19]: https://github.com/CoreOffice/XMLCoder/blob/main/LICENSE
[20]: Contributors.md
[21]: https://github.com/realm/SwiftLint
[22]: https://github.com/apple/swift
Expand Down
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
## Information

* [Widgets](user-manual/Information/Widgets.md)
* [Auto-Generated Widgets](user-manual/Information/AutoGeneratedWidgets.md)

[1]: README.md
[2]: user-manual/GettingStarted.md
Expand Down
13 changes: 9 additions & 4 deletions Sources/Adwaita/Menu/MenuButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by david-swift on 22.10.23.
//

import Libadwaita
import CAdw

/// A button widget for menus.
public struct MenuButton: MenuItem {
Expand All @@ -19,6 +19,9 @@ public struct MenuButton: MenuItem {
/// Whether to prefer adding the action to the application window.
var preferApplicationWindow: Bool

/// The action label.
var filteredLabel: String { label.filter { $0.isLetter || $0.isNumber || $0 == "-" || $0 == "." } }

/// Initialize a menu button.
/// - Parameters:
/// - label: The buttons label.
Expand All @@ -35,11 +38,13 @@ public struct MenuButton: MenuItem {
/// - menu: The menu.
/// - app: The application containing the menu.
/// - window: The application window containing the menu.
public func addMenuItem(menu: Libadwaita.Menu, app: GTUIApp, window: GTUIApplicationWindow?) {
public func addMenuItem(menu: OpaquePointer?, app: GTUIApp, window: GTUIApplicationWindow?) {
if let window, preferApplicationWindow {
_ = menu.append(label, window: window, shortcut: shortcut, handler: handler)
window.addKeyboardShortcut(shortcut, id: filteredLabel, handler: handler)
g_menu_append(menu, label, "win." + filteredLabel)
} else {
_ = menu.append(label, app: app, shortcut: shortcut, handler: handler)
app.addKeyboardShortcut(shortcut, id: filteredLabel, handler: handler)
g_menu_append(menu, label, "app." + filteredLabel)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/Menu/MenuSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by david-swift on 22.10.23.
//

import Libadwaita
import CAdw

/// A section for menus.
public struct MenuSection: MenuItem {
Expand All @@ -24,9 +24,9 @@ public struct MenuSection: MenuItem {
/// - menu: The menu.
/// - app: The application containing the menu.
/// - window: The application window containing the menu.
public func addMenuItem(menu: Libadwaita.Menu, app: GTUIApp, window: GTUIApplicationWindow?) {
let section = Libadwaita.Menu()
_ = menu.append("", section: section)
public func addMenuItem(menu: OpaquePointer?, app: GTUIApp, window: GTUIApplicationWindow?) {
let section = g_menu_new()
g_menu_append_section(menu, nil, section?.cast())
for element in sectionContent {
element.addMenuItems(menu: section, app: app, window: window)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/Menu/Submenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by david-swift on 22.10.23.
//

import Libadwaita
import CAdw

/// A submenu widget.
public struct Submenu: MenuItem {
Expand All @@ -29,9 +29,9 @@ public struct Submenu: MenuItem {
/// - menu: The menu.
/// - app: The application containing the menu.
/// - window: The application window containing the menu.
public func addMenuItem(menu: Libadwaita.Menu, app: GTUIApp, window: GTUIApplicationWindow?) {
let submenu = Libadwaita.Menu()
_ = menu.append(label, submenu: submenu)
public func addMenuItem(menu: OpaquePointer?, app: GTUIApp, window: GTUIApplicationWindow?) {
let submenu = g_menu_new()
g_menu_append_submenu(menu, label, submenu?.cast())
for element in submenuContent {
element.addMenuItems(menu: submenu, app: app, window: window)
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/Adwaita/Model/ArrayBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// https://gist.github.com/JadenGeller/c375fc15ad5900a0ddac4ed8ba8307a9
//

import Foundation

/// The ``ArrayBuilder`` is a simple result builder that outputs an array of any type.
///
/// You can define any array using Swift's DSL:
Expand Down
18 changes: 15 additions & 3 deletions Sources/Adwaita/Model/Data Flow/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by david-swift on 06.08.23.
//

import CAdw
import Foundation
import Libadwaita

/// A property wrapper for properties in a view that should be stored throughout view updates.
@propertyWrapper
Expand Down Expand Up @@ -110,11 +110,23 @@ public struct State<Value>: StateProtocol {
}
}

/// The directory used for storing user data.
/// - Returns: The URL.
public static func userDataDir() -> URL {
.init(fileURLWithPath: .init(cString: g_get_user_data_dir()))
}

/// Copy a text to the clipboard.
/// - Parameter text: The text.
public static func copy(_ text: String) {
let clipboard = gdk_display_get_clipboard(gdk_display_get_default())
gdk_clipboard_set_text(clipboard, text)
}

/// Get the settings directory path.
/// - Returns: The path.
private func dirPath() -> URL {
NativePeer
.getUserDataDirectory()
Self.userDataDir()
.appendingPathComponent(content.storage.folder ?? GTUIApp.appID, isDirectory: true)
}

Expand Down
44 changes: 44 additions & 0 deletions Sources/Adwaita/Model/Enumerations/Alignment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Alignment.swift
// Adwaita
//
// Created by david-swift on 21.01.24.
//

import CAdw

/// The alignment for a widget.
public enum Alignment: Int {

/// The widget will fill the available space.
case fill
/// The widget will start at the beginning of the available space.
case start
/// The widget will end at the end of the available space.
case end
/// The widget will be centered in the available space.
case center
/// The widget will be baseline aligned in the available space.
case baselineFill
/// The widget will be baseline aligned at the start of the available space.
case baselineCenter

/// Get the GtkAlign alignment.
public var cAlign: GtkAlign {
switch self {
case .fill:
return GTK_ALIGN_FILL
case .start:
return GTK_ALIGN_START
case .end:
return GTK_ALIGN_END
case .center:
return GTK_ALIGN_CENTER
case .baselineFill:
return GTK_ALIGN_BASELINE_FILL
case .baselineCenter:
return GTK_ALIGN_BASELINE_CENTER
}
}

}
20 changes: 20 additions & 0 deletions Sources/Adwaita/Model/Enumerations/Edge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Edge.swift
// Adwaita
//
// Created by david-swift on 21.01.24.
//

/// The edges for a widget.
public enum Edge {

/// The leading (start) edge.
case leading
/// The trailing (end) edge.
case trailing
/// The top edge.
case top
/// The bottom edge.
case bottom

}
Loading

0 comments on commit d8de611

Please sign in to comment.