Update documentation to latest changes

This commit is contained in:
david-swift 2024-10-15 15:31:09 +02:00
parent f1643efd76
commit 04b705b1de
79 changed files with 268 additions and 238 deletions

View File

@ -19,7 +19,7 @@ struct CustomText: Widget {
}
```
This widget can be called in a view body using `CustomText(text: "Hello, world!")`.
Now, add the two functions required by the protocol:
Now, add the function required by the protocol:
```swift
import CAdw
@ -27,37 +27,36 @@ struct CustomText: Widget {
var text: String
public func container(modifiers: [(View) -> View]) -> ViewStorage { }
public func update(_ storage: ViewStorage, modifiers: [(View) -> View], updateProperties: Bool) { }
}
```
Import CAdw which exposes the whole C Libadwaita and Gtk API to Swift.
## The `container(modifiers:)` function
This function initializes the widget when the widget appears for the first time.
It expects a ``ViewStorage`` as the return type.
In our case, this function is very simple:
```swift
func container(modifiers: [(View) -> View]) -> ViewStorage {
.init(gtk_label_new(text)?.opaque())
}
```
## The `update(_:modifiers:updateProperties:)` function
Whenever a state of the app changes, the ``Widget/update(_:modifiers:updateProperties:)`` function of the widget gets called.
You get the view storage that you have previously initialized as a parameter.
Update the storage to reflect the current state of the widget:
```swift
func update(_ storage: ViewStorage, modifiers: [(View) -> View], updateProperties: Bool) {
if updateProperties {
gtk_label_set_label(storage.pointer, text)
func initializeWidget() -> Any {
gtk_label_new(text)?.opaque()
}
}
```
## Containers
Some widgets act as containers that accept other widgets as children.
In that case, use the ``ViewStorage``'s `content` property for storing their view storages.
In the ``Widget/update(_:modifiers:updateProperties:)`` function, update the children's storages.
Take a look at the code of the container widgets in this library as a reference.
## Updates
The widget will be rendered as expected, but updates do not work currently.
To mark properties as a widget property, use the ``Property`` property wrapper.
```swift
import CAdw
struct CustomText: Widget {
@Property(
set: { gtk_label_set_label($0, text) },
pointer: OpaquePointer.self
)
var text: String
func initializeWidget() -> Any {
gtk_label_new(text)?.opaque()
}
}
```
## More Complex Widgets
If a property should allow two-way traffic (able to modify inside of the widget, e.g. the `isOn` property of a checkbox which can be updated when the user clicks the checkbox), use ``BindingProperty``. For views, use ``ViewProperty``.
More help is available [here](https://meta.aparoksha.dev/documentation/meta/createbackend).

View File

@ -12,13 +12,13 @@ Find detailed information in the [Flatpak documentation](https://docs.flatpak.or
This is the only code that should be submitted to Flathub.
There will be a new repository created under `flathub/app-id` that hosts the manifest.
### SDK Extension for Swift 5
### SDK Extension for Swift 6
I recommend using the SDK Extension for building the app.
Add the following snippet.
```json
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.swift5"
"org.freedesktop.Sdk.Extension.swift6"
]
```

View File

@ -85,7 +85,7 @@ Find more information in the [template repository](https://github.com/AparokshaU
### Basics
- <doc:CreatingViews>
- <doc:Windows>
- <doc:WindowsDoc>
- <doc:KeyboardShortcuts>
### Advanced

View File

@ -11,15 +11,16 @@ import Adwaita
@main
struct HelloWorld: App {
let id = "io.github.david_swift.HelloWorld"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.HelloWorld")
var scene: Scene {
Window(id: "content") { _ in
// These are the views:
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
}
@ -38,9 +39,11 @@ Create custom views by declaring types that conform to the ``View`` protocol:
struct ContentView: View {
var view: Body {
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
}

View File

@ -26,14 +26,15 @@ import Adwaita
@main
struct HelloWorld: App {
let id = "io.github.david_swift.HelloWorld"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.david_swift.HelloWorld")
var scene: Scene {
Window(id: "content") { _ in
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
// Add the shortcut "Ctrl + W" for closing the window
.keyboardShortcut("w".ctrl()) { window in
@ -52,14 +53,15 @@ import Adwaita
@main
struct HelloWorld: App {
let id = "io.github.david_swift.HelloWorld"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.david_swift.HelloWorld")
var scene: Scene {
Window(id: "content") { _ in
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
// Add the shortcut "Ctrl + Q" for terminating the app
.appKeyboardShortcut("q".ctrl()) { app in
@ -76,7 +78,7 @@ Here is an example using a menu button:
```swift
struct TestView: View {
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
Menu(icon: .default(icon: .openMenu), app: app) {

View File

@ -11,20 +11,23 @@ Whenever the last one disappears, the app terminates.
@main
struct HelloWorld: App {
let id = "io.github.david_swift.HelloWorld"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.HelloWorld")
var scene: Scene {
Window(id: "content") { _ in
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
// Add a second window:
Window(id: "window-2") { _ in
HeaderBar.empty()
Text("Window 2")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
}
@ -39,22 +42,25 @@ Another use case is showing a window:
@main
struct HelloWorld: App {
let id = "io.github.david_swift.HelloWorld"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.HelloWorld")
var scene: Scene {
Window(id: "content") { _ in
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
Window(id: "control") { _ in
HeaderBar.empty()
Button("Show Window") {
// Show the window with the identifier "content":
app.showWindow("content")
}
.padding()
.topToolbar {
HeaderBar.empty()
}
}
}
@ -66,70 +72,64 @@ It should be used for opening windows that cannot be presented more than once
and for moving a window that is already open into the foreground.
## Adding windows
You can call the ``GTUIApp/addWindow(_:parent:)`` function instead of ``GTUIApp/showWindow(_:)``
You can call the ``AdwaitaApp/addWindow(_:)`` function instead of ``AdwaitaApp/showWindow(_:)``
if you want to add and focus another instance of a window type:
```swift
@main
struct HelloWorld: App {
let id = "io.github.david_swift.HelloWorld"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.HelloWorld")
var scene: Scene {
Window(id: "content") { _ in
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
Window(id: "control") { _ in
HeaderBar.empty()
Button("Add Window") {
// Add a new instance of the "content" window type
app.addWindow("content")
}
.padding()
.topToolbar {
HeaderBar.empty()
}
}
}
}
```
It can be used to add an overlay window to a certain instance of a window type
by specifying the `parent` parameter, e.g. in the example above:
```swift
Window(id: "control") { window in
HeaderBar.empty()
Button("Add Child Window") {
// Add the new instance as a child window of this window
app.addWindow("content", parent: window)
}
.padding()
}
```
## Customizing the initial number of windows
By default, every window type of the app's scene appears once when the app starts.
It's possible to customize how many windows are being presented at the app's startup:
```swift
@main
struct HelloWorld: App {
let id = "io.github.david_swift.HelloWorld"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.HelloWorld")
var scene: Scene {
// Open no window of the "content" type
Window(id: "content", open: 0) { _ in
HeaderBar.empty()
Text("Hello, world!")
.padding()
.topToolbar {
HeaderBar.empty()
}
}
// Open two windows of the "control" type
Window(id: "control", open: 2) { _ in
HeaderBar.empty()
Button("Show Window") {
app.addWindow("content")
}
.padding()
.topToolbar {
HeaderBar.empty()
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@ -6,8 +6,7 @@ import Adwaita
@main
struct AdwaitaTemplate: App {
let id = "io.github.AparokshaUI.AdwaitaTemplate"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.AparokshaUI.AdwaitaTemplate")
var scene: Scene {
Window(id: "main") { window in

View File

@ -0,0 +1,42 @@
{
"originHash" : "af6fb6b129be2ee0c0916fac48a05560178b7f22f7940f6ab37ceda75820b4e4",
"pins" : [
{
"identity" : "adwaita",
"kind" : "remoteSourceControl",
"location" : "https://github.com/AparokshaUI/Adwaita",
"state" : {
"revision" : "c82957e2398a766458ff22129db26b46de75248b",
"version" : "0.2.6"
}
},
{
"identity" : "levenshteintransformations",
"kind" : "remoteSourceControl",
"location" : "https://github.com/david-swift/LevenshteinTransformations",
"state" : {
"revision" : "002c3ae5c48f30d61c96045fd3ceb9928aa778d2",
"version" : "0.1.3"
}
},
{
"identity" : "localized",
"kind" : "remoteSourceControl",
"location" : "https://github.com/AparokshaUI/Localized",
"state" : {
"revision" : "8135771fc0852cdea4361674d964d1c2e048db05",
"version" : "0.3.0"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams",
"state" : {
"revision" : "3036ba9d69cf1fd04d433527bc339dc0dc75433d",
"version" : "5.1.3"
}
}
],
"version" : 3
}

View File

@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
@ -9,15 +9,15 @@ let package = Package(
.macOS(.v13)
],
dependencies: [
.package(url: "https://github.com/AparokshaUI/Adwaita", from: "0.2.0"),
.package(url: "https://github.com/AparokshaUI/Localized", from: "0.2.0")
.package(url: "https://git.aparoksha.dev/aparoksha/adwaita-swift", from: "0.1.0"),
.package(url: "https://git.aparoksha.dev/aparoksha/localized", from: "0.1.0")
],
targets: [
.executableTarget(
name: "AdwaitaTemplate",
dependencies: [
.product(name: "Adwaita", package: "Adwaita"),
.product(name: "Localized", package: "Localized")
.product(name: "Adwaita", package: "adwaita-swift"),
.product(name: "Localized", package: "localized")
],
path: "Sources",
resources: [

View File

@ -1,10 +1,10 @@
{
"app-id": "io.github.AparokshaUI.AdwaitaTemplate",
"runtime": "org.gnome.Platform",
"runtime-version": "46",
"runtime-version": "47",
"sdk": "org.gnome.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.swift5"
"org.freedesktop.Sdk.Extension.swift6"
],
"command": "AdwaitaTemplate",
"finish-args": [
@ -14,8 +14,8 @@
"--socket=wayland"
],
"build-options": {
"append-path": "/usr/lib/sdk/swift5/bin",
"prepend-ld-library-path": "/usr/lib/sdk/swift5/lib"
"append-path": "/usr/lib/sdk/swift6/bin",
"prepend-ld-library-path": "/usr/lib/sdk/swift6/lib"
},
"cleanup": [
"/include",
@ -40,7 +40,7 @@
}
],
"build-commands": [
"swift build -c release --static-swift-stdlib",
"swift build -c debug --static-swift-stdlib",
"install -Dm755 .build/release/AdwaitaTemplate /app/bin/AdwaitaTemplate",
"install -Dm644 data/io.github.AparokshaUI.AdwaitaTemplate.metainfo.xml $DESTDIR/app/share/metainfo/io.github.AparokshaUI.AdwaitaTemplate.metainfo.xml",
"install -Dm644 data/io.github.AparokshaUI.AdwaitaTemplate.desktop $DESTDIR/app/share/applications/io.github.AparokshaUI.AdwaitaTemplate.desktop",

View File

@ -7,7 +7,7 @@ import Adwaita
struct ContentView: View {
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
Text("Hello, world!")

View File

@ -8,7 +8,7 @@ import Adwaita
struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
Text("Hello, world!")

View File

@ -9,7 +9,7 @@ struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Task> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -9,7 +9,7 @@ struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Task> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -9,7 +9,7 @@ struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Task> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -9,7 +9,7 @@ struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Binding<Task>> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -9,7 +9,7 @@ struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Binding<Task>> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -9,7 +9,7 @@ struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Binding<Task>> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -9,7 +9,7 @@ struct ContentView: View {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Binding<Task>> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -8,8 +8,7 @@ import Adwaita
@main
struct Subtasks: App {
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { _ in

View File

@ -12,7 +12,7 @@ struct TaskList: View {
@State private var showAddDialog = false
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {
@ -33,7 +33,7 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
@ -43,7 +43,7 @@ struct TaskList: View {
.frame(maxWidth: 500)
}
var dialog: View {
var dialog: AnyView {
Form {
EntryRow(Loc.label, text: $addDialogText)
.entryActivated {
@ -69,7 +69,7 @@ struct TaskList: View {
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {

View File

@ -12,7 +12,7 @@ struct TaskList: View {
@State private var showAddDialog = false
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {

View File

@ -12,7 +12,7 @@ struct TaskList: View {
@State private var showAddDialog = false
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {

View File

@ -13,7 +13,7 @@ struct TaskList: View {
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {

View File

@ -13,7 +13,7 @@ struct TaskList: View {
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {

View File

@ -13,7 +13,7 @@ struct TaskList: View {
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
var app: GTUIApp
var app: AdwaitaApp
var deleteTask: (() -> Void)?
var view: Body {

View File

@ -13,7 +13,7 @@ struct TaskList: View {
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
var app: GTUIApp
var app: AdwaitaApp
var deleteTask: (() -> Void)?
var view: Body {

View File

@ -13,7 +13,7 @@ struct TaskList: View {
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
var app: GTUIApp
var app: AdwaitaApp
var deleteTask: (() -> Void)?
var view: Body {

View File

@ -13,7 +13,7 @@ struct TaskList: View {
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
var app: GTUIApp
var app: AdwaitaApp
var deleteTask: (() -> Void)?
var view: Body {

View File

@ -9,7 +9,7 @@ struct ContentView: WindowView {
@State("tasks") private var tasks: [Task] = []
@State private var destination: NavigationStack<Binding<Task>> = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -12,7 +12,7 @@ struct ContentView: WindowView {
@State("width") private var width = 500
@State("height") private var height = 400
@State("maximized") private var maximized = false
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -12,7 +12,7 @@ struct ContentView: WindowView {
@State("width") private var width = 500
@State("height") private var height = 450
@State("maximized") private var maximized = false
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -12,7 +12,7 @@ struct ContentView: WindowView {
@State("width") private var width = 500
@State("height") private var height = 450
@State("maximized") private var maximized = false
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
NavigationView($destination, "Subtasks") { task in

View File

@ -8,8 +8,7 @@ import Adwaita
@main
struct Subtasks: App {
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { _ in

View File

@ -8,8 +8,7 @@ import Adwaita
@main
struct Subtasks: App {
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { _ in

View File

@ -13,7 +13,7 @@ struct TaskList: View {
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
var app: GTUIApp
var app: AdwaitaApp
var deleteTask: (() -> Void)?
var view: Body {

View File

@ -14,7 +14,7 @@ struct TaskList: View {
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
@State private var showAboutDialog = false
var app: GTUIApp
var app: AdwaitaApp
var deleteTask: (() -> Void)?
var view: Body {

View File

@ -14,7 +14,7 @@ struct TaskList: View {
@State private var focusEntry: Signal = .init()
@State private var showDeleteDialog = false
@State private var showAboutDialog = false
var app: GTUIApp
var app: AdwaitaApp
var deleteTask: (() -> Void)?
var view: Body {

View File

@ -6,8 +6,7 @@ import Adwaita
@main
struct Subtasks: App {
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { window in

View File

@ -8,8 +8,7 @@ import Adwaita
@main
struct Subtasks: App {
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { window in

View File

@ -13,8 +13,7 @@ struct Subtasks: App {
.init(label: "World"),
.init(label: "Complete", done: true)
]
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { window in

View File

@ -13,8 +13,7 @@ struct Subtasks: App {
.init(label: "World"),
.init(label: "Complete", done: true)
]
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { window in

View File

@ -13,8 +13,7 @@ struct Subtasks: App {
.init(label: "World"),
.init(label: "Complete", done: true)
]
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { _ in

View File

@ -13,8 +13,7 @@ struct Subtasks: App {
.init(label: "World"),
.init(label: "Complete", done: true)
]
let id = "io.github.david_swift.Subtasks"
var app: GTUIApp!
let app: AdwaitaApp = .init(id: "io.github.david_swift.Subtasks")
var scene: Scene {
Window(id: "main") { _ in

View File

@ -17,13 +17,13 @@ struct TaskList: View {
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
}

View File

@ -17,7 +17,7 @@ struct TaskList: View {
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {
@ -25,6 +25,7 @@ struct TaskList: View {
.iconName(Icon.default(icon: .goNext).string)
}
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")

View File

@ -17,7 +17,7 @@ struct TaskList: View {
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {
@ -25,9 +25,9 @@ struct TaskList: View {
.iconName(Icon.default(icon: .goNext).string)
}
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
.topToolbar {

View File

@ -18,14 +18,14 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {
@ -33,9 +33,9 @@ struct TaskList: View {
.iconName(Icon.default(icon: .goNext).string)
}
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}

View File

@ -18,23 +18,23 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -23,23 +23,23 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -26,13 +26,13 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
@ -44,13 +44,13 @@ struct TaskList: View {
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -27,17 +27,17 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
var dialog: View {
var dialog: AnyView {
Form {
EntryRow("Label", text: $addDialogText)
.frame(minWidth: 250)
@ -49,13 +49,13 @@ struct TaskList: View {
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -29,17 +29,17 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
var dialog: View {
var dialog: AnyView {
Form {
EntryRow("Label", text: $addDialogText)
.frame(minWidth: 250)
@ -57,19 +57,19 @@ struct TaskList: View {
tasks.append(.init(label: addDialogText))
cancel()
}
.style("suggested-action")
.suggested()
}
.showEndTitleButtons(false)
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -29,17 +29,17 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
var dialog: View {
var dialog: AnyView {
Form {
EntryRow("Label", text: $addDialogText)
.entryActivated {
@ -59,19 +59,19 @@ struct TaskList: View {
Button("Add") {
add()
}
.style("suggested-action")
.suggested()
}
.showEndTitleButtons(false)
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -11,7 +11,7 @@ struct TaskList: View {
@State private var showAddDialog = false
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {
@ -31,17 +31,17 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
var dialog: View {
var dialog: AnyView {
Form {
EntryRow("Label", text: $addDialogText)
.entryActivated {
@ -61,19 +61,19 @@ struct TaskList: View {
Button("Add") {
add()
}
.style("suggested-action")
.suggested()
}
.showEndTitleButtons(false)
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -11,7 +11,7 @@ struct TaskList: View {
@State private var showAddDialog = false
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {
@ -31,17 +31,17 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
var dialog: View {
var dialog: AnyView {
Form {
EntryRow("Label", text: $addDialogText)
.entryActivated {
@ -61,19 +61,19 @@ struct TaskList: View {
Button("Add") {
add()
}
.style("suggested-action")
.suggested()
}
.showEndTitleButtons(false)
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -11,7 +11,7 @@ struct TaskList: View {
@State private var showAddDialog = false
@State private var addDialogText = ""
@State private var focusEntry: Signal = .init()
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
ScrollView {
@ -32,17 +32,17 @@ struct TaskList: View {
}
}
var list: View {
var list: AnyView {
List(tasks, selection: nil) { task in
taskRow(task: task)
}
.boxedList()
.valign(.start)
.padding(20)
.style("boxed-list")
.frame(maxWidth: 500)
}
var dialog: View {
var dialog: AnyView {
Form {
EntryRow(Loc.label, text: $addDialogText)
.entryActivated {
@ -62,19 +62,19 @@ struct TaskList: View {
Button(Loc.add) {
add()
}
.style("suggested-action")
.suggested()
}
.showEndTitleButtons(false)
}
}
func taskRow(task: Task) -> View {
func taskRow(task: Task) -> AnyView {
ActionRow()
.title(task.label)
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
.suffix {

View File

@ -15,8 +15,8 @@ struct TaskList: View {
ActionRow()
.title(task.label)
}
.boxedList()
.padding()
.style("boxed-list")
}
}

View File

@ -16,8 +16,8 @@ struct TaskList: View {
.title(task.label)
}
.valign(.start)
.boxedList()
.padding()
.style("boxed-list")
}
}

View File

@ -17,13 +17,13 @@ struct TaskList: View {
.prefix {
CheckButton()
.active($tasks[id: task.id, default: .init(label: "")].done)
.style("selection-mode")
.selectionMode()
.valign(.center)
}
}
.boxedList()
.valign(.start)
.padding()
.style("boxed-list")
}
}

View File

@ -6,8 +6,7 @@ import Adwaita
@main
struct AdwaitaTemplate: App {
let id = "io.github.AparokshaUI.AdwaitaTemplate"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.AparokshaUI.AdwaitaTemplate")
var scene: Scene {
Window(id: "main") { window in

View File

@ -6,8 +6,7 @@ import Adwaita
@main
struct AdwaitaTemplate: App {
let id = "io.github.AparokshaUI.AdwaitaTemplate"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.AparokshaUI.AdwaitaTemplate")
var scene: Scene {
Window(id: "main") { window in
@ -20,8 +19,8 @@ struct AdwaitaTemplate: App {
struct Content: View {
var app: GTUIApp
var window: GTUIApplicationWindow
var app: AdwaitaApp
var window: AdwaitaApplicationWindow
var view: Body {
Text(Loc.helloWorld)

View File

@ -6,8 +6,7 @@ import Adwaita
@main
struct AdwaitaTemplate: App {
let id = "io.github.AparokshaUI.AdwaitaTemplate"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.AparokshaUI.AdwaitaTemplate")
var scene: Scene {
Window(id: "main") { window in
@ -20,8 +19,8 @@ struct AdwaitaTemplate: App {
struct Content: View {
var app: GTUIApp
var window: GTUIApplicationWindow
var app: AdwaitaApp
var window: AdwaitaApplicationWindow
var view: Body {
Button(Loc.helloWorld) {

View File

@ -6,8 +6,7 @@ import Adwaita
@main
struct AdwaitaTemplate: App {
let id = "io.github.AparokshaUI.AdwaitaTemplate"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.AparokshaUI.AdwaitaTemplate")
var scene: Scene {
Window(id: "main") { window in
@ -21,8 +20,8 @@ struct AdwaitaTemplate: App {
struct Content: View {
@State private var startAlign = false
var app: GTUIApp
var window: GTUIApplicationWindow
var app: AdwaitaApp
var window: AdwaitaApplicationWindow
var view: Body {
Button("Toggle Start Alignment") {

View File

@ -6,8 +6,7 @@ import Adwaita
@main
struct AdwaitaTemplate: App {
let id = "io.github.AparokshaUI.AdwaitaTemplate"
var app: GTUIApp!
let app = AdwaitaApp(id: "io.github.AparokshaUI.AdwaitaTemplate")
var scene: Scene {
Window(id: "main") { window in
@ -21,8 +20,8 @@ struct AdwaitaTemplate: App {
struct Content: View {
@State private var startAlign = false
var app: GTUIApp
var window: GTUIApplicationWindow
var app: AdwaitaApp
var window: AdwaitaApplicationWindow
var view: Body {
ButtonView(startAlign: $startAlign)

View File

@ -16,7 +16,7 @@
@Image(source: "ChangeDirectory.png", alt: "The GNOME Console app.")
}
@Step {
Clone the template repository into the `Subtasks` directory using `git clone https://github.com/AparokshaUI/AdwaitaTemplate Subtasks`.
Clone the template repository into the `Subtasks` directory using `git clone https://git.aparoksha.dev/aparoksha/adwaita-template Subtasks`.
@Image(source: "CloneTemplateSubtasks.png", alt: "The GNOME Console app.")
}
@Step {

View File

@ -1,9 +0,0 @@
@Article {
@Intro(title: "About Flatpak") {
In the previous tutorial, you have named various files required for distributing apps via Flatpak.
}
@
}

View File

@ -34,7 +34,7 @@
@Image(source: "ChangeDirectory.png", alt: "The GNOME Console app.")
}
@Step {
Clone the template repository into the `HelloWorld` directory using `git clone https://github.com/AparokshaUI/AdwaitaTemplate HelloWorld`.
Clone the template repository into the `HelloWorld` directory using `git clone https://git.aparoksha.dev/aparoksha/adwaita-template HelloWorld`.
This creates a directory `HelloWorld` containing the content of the [Adwaita Template](https://github.com/AparokshaUI/AdwaitaTemplate).
@Image(source: "GitClone.png", alt: "The GNOME Console app.")

View File

@ -22,7 +22,7 @@
A window contains _views_.
You can call other views inside of views (such as the ``Text`` or `ToolbarView` in this example).
Methods like ``View/padding(_:_:)`` and ``View/topToolbar(visible:_:)`` often used to tweak views or wrap views into other views (you'll get more familiar with them soon).
Methods like ``AnyView/padding(_:_:)`` and ``AnyView/topToolbar(visible:_:)`` are often used to tweak views or wrap views into other views (you'll get more familiar with them soon).
@Code(name: "AdwaitaTemplate.swift", file: "AdwaitaTemplate1.swift")
}
@Step {
@ -73,7 +73,7 @@
@Binding var section: String
@State private var title = "Title"
var app: GTUIApp
var app: AdwaitaApp
var view: Body {
...

View File

@ -1,14 +1,14 @@
@Article {
@Intro(title: "The GNOME project") {
Learn about the GNOME project and how you can get involved.
@Intro(title: "The GNOME Project") {
Learn about the GNOME Project and how you can get involved.
}
@ContentAndMedia {
# GNOME shell
The GNOME shell is a popular open-source desktop environment for Linux.
The GNOME shell is a popular open source desktop environment for Linux.
There is a vast app ecosystem built using its modern Adwaita design language, enabling a unique consistency across the platform.
GNOME apps follow strictly the philosophy "do one thing and do it well", and using them requires little technical knowledge.
GNOME apps strictly follow the philosophy "do one thing and do it well", and using them requires little technical knowledge.
You can find more information in the [GNOME Human Interface Guidelines](https://developer.gnome.org/hig/index.html).
![The GNOME desktop environment showing some apps.](Screenshot.png)
@ -17,7 +17,7 @@
@ContentAndMedia {
# Adwaita
Adwaita is not only a design language, but a [C API](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.5/) providing user interface elements, so called _widgets_, for native GNOME apps, built on top of the powerful [GTK widget toolkit](https://docs.gtk.org/gtk4/).
It offers various UI elements that support pointer, touch, and keyboard out of the box, and allows the creation of accessible apps without further configuration.
It offers various UI elements that support pointer, touch, and keyboard input out of the box, and allows the creation of accessible apps without further configuration.
There are modern controls, containers, navigation design patterns and elements for visual feedback, working great on different types of screens, including phones.
}

View File

@ -11,7 +11,7 @@
@Steps {
@Step {
Install [Asahi Linux](https://asahilinux.org/) by running the following command into a macOS terminal: **`curl https://alx.sh | sh`**
Install [Asahi Linux](https://asahilinux.org/) by running the following command in a macOS terminal: **`curl https://alx.sh | sh`**
Follow the instructions until you get to the OS selection.
@Image(source: "Asahi.svg", alt: "A laptop showing the Asahi logo.")

View File

@ -12,18 +12,18 @@
@Steps {
@Step {
You can see how creating an array in Swift with the content `[5, 10, 2, 3]` is done.
@Code(name: "main.swift", file: "Array1.swift")
@Code(name: "main.swift", file: "Array1D.swift")
}
@Step {
Let's assume Swift wouldn't offer this convenient syntax - how would you create the same array starting from an empty array?
@Code(name: "main.swift", file: "Array2.swift")
@Code(name: "main.swift", file: "Array2D.swift")
}
@Step {
The `append(_:)` function could be used for example.
In this code, it gets clearer _how_ the result of having the array in the memory is accomplished, but one would have to mentally follow the commands to construct the _what_.
Therefore, this code is more on the imperative side compared to the initial code example being rather on the declarative side.
@Code(name: "main.swift", file: "Array3.swift")
@Code(name: "main.swift", file: "Array3D.swift")
}
}
}

View File

@ -117,7 +117,7 @@
}
}
@Step {
Then, add the ``View/aboutDialog(visible:app:developer:version:icon:website:issues:)`` modifier.
Then, add the ``AnyView/aboutDialog(visible:app:developer:version:icon:website:issues:)`` modifier.
@Code(name: "TaskList.swift", file: "TaskList34.swift", previousFile: "TaskList33.swift") {
@Image(source: "Localized7.png", alt: "The window.")
}

View File

@ -30,7 +30,7 @@
@Step {
Add the ``NavigationView``.
`destination` is of the type ``NavigationStack``, which means that it stores the navigation path.
`destination` is of the type ``NavigationView/NavigationStack``, which means that it stores the navigation path.
If the path is empty, the `initialView` will be presented, otherwise, line 16 will be visible for the last element in the path which is of the type `Task`.
@Code(name: "ContentView.swift", file: "ContentView3.swift") {
@Image(source: "TaskList15.png", alt: "The window.")
@ -52,7 +52,7 @@
@Step {
In the task list view, add the destination binding parameter and implement the navigation.
You can navigate using ``NavigationStack/push(_:)`` and ``NavigationStack/pop()``.
You can navigate using ``NavigationView/NavigationStack/push(_:)`` and ``NavigationView/NavigationStack/pop()``.
@Code(name: "TaskList.swift", file: "TaskList23.swift", previousFile: "TaskList22.swift") {
@Image(source: "TaskList15.png", alt: "The window.")
}