Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let package = Package(
.library(name: "Gtk", type: libraryType, targets: ["Gtk"]),
.library(name: "Gtk3", type: libraryType, targets: ["Gtk3"]),
.executable(name: "GtkExample", targets: ["GtkExample"]),
// .library(name: "CursesBackend", type: libraryType, targets: ["CursesBackend"]),
.library(name: "TermKitBackend", type: libraryType, targets: ["TermKitBackend"]),
// .library(name: "QtBackend", type: libraryType, targets: ["QtBackend"]),
// .library(name: "LVGLBackend", type: libraryType, targets: ["LVGLBackend"]),
],
Expand Down Expand Up @@ -110,10 +110,10 @@ let package = Package(
url: "https://github.com/stackotter/swift-winui",
branch: "927e2c46430cfb1b6c195590b9e65a30a8fd98a2"
),
// .package(
// url: "https://github.com/stackotter/TermKit",
// revision: "163afa64f1257a0c026cc83ed8bc47a5f8fc9704"
// ),
.package(
url: "https://github.com/migueldeicaza/TermKit",
revision: "6b82436223a739af53b19045784b4bbc3f92505f"
),
// .package(
// url: "https://github.com/PADL/LVGLSwift",
// revision: "19c19a942153b50d61486faf1d0d45daf79e7be5"
Expand Down Expand Up @@ -252,10 +252,10 @@ let package = Package(
name: "WinUIInterop",
dependencies: []
),
// .target(
// name: "CursesBackend",
// dependencies: ["SwiftCrossUI", "TermKit"]
// ),
.target(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation (and for the TermKit package above and TermKitBackend product above that)

name: "TermKitBackend",
dependencies: ["SwiftCrossUI", .product(name: "TermKit", package: "TermKit")]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "TermKit" spelling instead of .product(name: "TermKit", package: "TermKit")

),
// .target(
// name: "QtBackend",
// dependencies: ["SwiftCrossUI", .product(name: "Qlift", package: "qlift")]
Expand Down
147 changes: 0 additions & 147 deletions Sources/CursesBackend/CursesBackend.swift

This file was deleted.

10 changes: 10 additions & 0 deletions Sources/SwiftCrossUI/Backend/AppBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public protocol AppBackend: Sendable {
/// The default amount of padding used when a user uses the ``View/padding(_:_:)``
/// modifier.
var defaultPaddingAmount: Int { get }
/// The default amount of spacing used when a user uses the ``HStack`` or ``VStack``
/// classes
var defaultStackSpacingAmount: Int { get }
/// Gets the layout width of a backend's scroll bars. Assumes that the width
/// is the same for both vertical and horizontal scroll bars (where the width
/// of a horizontal scroll bar is what pedants may call its height). If the
Expand Down Expand Up @@ -693,6 +696,8 @@ public protocol AppBackend: Sendable {
)
/// Navigates a web view to a given URL.
func navigateWebView(_ webView: Widget, to url: URL)

func limitScreenBounds(_ bounds: SIMD2<Int>) -> SIMD2<Int>
}

extension AppBackend {
Expand All @@ -709,6 +714,7 @@ extension AppBackend {
}

extension AppBackend {
public var defaultStackSpacingAmount: Int { 10 }
/// Used by placeholder implementations of backend methods.
private func todo(_ function: String = #function) -> Never {
print("\(type(of: self)): \(function) not implemented")
Expand Down Expand Up @@ -1139,4 +1145,8 @@ extension AppBackend {
) {
todo()
}

public func limitScreenBounds(_ bounds: SIMD2<Int>) -> SIMD2<Int> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be reworked to func clampWindowSize(_ size: SIMD2<Int>, for window: Window) -> SIMD2<Int>. Renamed for clarity, and extra parameter added for future proofing (future purposes could want the window in question to access properties such as scaling factors).

return bounds
}
}
4 changes: 2 additions & 2 deletions Sources/SwiftCrossUI/Scenes/WindowGroupNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
_ = update(
newScene,
proposedWindowSize: isFirstUpdate && isProgramaticallyResizable
? (newScene ?? scene).defaultSize
: backend.size(ofWindow: window),
? backend.limitScreenBounds((newScene ?? scene).defaultSize)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent these two hanging lines

: backend.limitScreenBounds(backend.size(ofWindow: window)),
backend: backend,
environment: environment,
windowSizeIsFinal: !isProgramaticallyResizable
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftCrossUI/Views/HStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ public struct HStack<Content: View>: View {
public var body: Content

/// The amount of spacing to apply between children.
private var spacing: Int
private var spacing: Int?
/// The alignment of the stack's children in the vertical direction.
private var alignment: VerticalAlignment

Expand All @@ -14,7 +14,7 @@ public struct HStack<Content: View>: View {
@ViewBuilder _ content: () -> Content
) {
body = content()
self.spacing = spacing ?? VStack<EmptyView>.defaultSpacing
self.spacing = spacing
self.alignment = alignment
}

Expand Down Expand Up @@ -45,7 +45,7 @@ public struct HStack<Content: View>: View {
environment
.with(\.layoutOrientation, .horizontal)
.with(\.layoutAlignment, alignment.asStackAlignment)
.with(\.layoutSpacing, spacing),
.with(\.layoutSpacing, spacing ?? backend.defaultStackSpacingAmount),
backend: backend,
dryRun: dryRun
)
Expand Down
8 changes: 3 additions & 5 deletions Sources/SwiftCrossUI/Views/VStack.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// A view that arranges its subviews vertically.
public struct VStack<Content: View>: View {
static var defaultSpacing: Int { 10 }

public var body: Content

/// The amount of spacing to apply between children.
private var spacing: Int
private var spacing: Int?
/// The alignment of the stack's children in the horizontal direction.
private var alignment: HorizontalAlignment

Expand All @@ -24,7 +22,7 @@ public struct VStack<Content: View>: View {
content: Content
) {
body = content
self.spacing = spacing ?? Self.defaultSpacing
self.spacing = spacing
self.alignment = alignment
}

Expand Down Expand Up @@ -55,7 +53,7 @@ public struct VStack<Content: View>: View {
environment
.with(\.layoutOrientation, .vertical)
.with(\.layoutAlignment, alignment.asStackAlignment)
.with(\.layoutSpacing, spacing),
.with(\.layoutSpacing, spacing ?? backend.defaultStackSpacingAmount),
backend: backend,
dryRun: dryRun
)
Expand Down
Loading