Add spacing to VStack/HStack initializers
Some checks failed
Deploy Docs / publish (push) Waiting to run
SwiftLint / SwiftLint (push) Has been cancelled

This commit is contained in:
david-swift 2025-04-11 10:31:11 +02:00
parent 4290dd4137
commit befa7d52ea
3 changed files with 33 additions and 22 deletions

View File

@ -78,6 +78,20 @@ public struct Idle {
/// An idle handler. /// An idle handler.
class IdleHandler { class IdleHandler {
/// Execute the function.
/// - Parameter pointer: The closure wrapper's pointer.
static func run(pointer: gpointer?) -> Int32 {
if let pointer {
let container = Unmanaged<ClosureContainer>.fromOpaque(pointer).takeUnretainedValue()
let result = container.closure()
if !result {
Unmanaged<ClosureContainer>.fromOpaque(pointer).release()
}
return result.cBool
}
return G_SOURCE_REMOVE
}
/// Add a function to be called whenever there are no higher priority events pending to the default main loop. /// Add a function to be called whenever there are no higher priority events pending to the default main loop.
/// - Parameter closure: The function. /// - Parameter closure: The function.
func add(_ closure: @escaping () -> Bool, priority: Int32, delay: Int64? = nil) { func add(_ closure: @escaping () -> Bool, priority: Int32, delay: Int64? = nil) {
@ -93,20 +107,6 @@ public struct Idle {
} }
} }
/// Execute the function.
/// - Parameter pointer: The closure wrapper's pointer.
static func run(pointer: gpointer?) -> Int32 {
if let pointer {
let container = Unmanaged<ClosureContainer>.fromOpaque(pointer).takeUnretainedValue()
let result = container.closure()
if !result {
Unmanaged<ClosureContainer>.fromOpaque(pointer).release()
}
return result.cBool
}
return G_SOURCE_REMOVE
}
} }
/// A reference type holding a closure. /// A reference type holding a closure.

View File

@ -10,18 +10,27 @@ public struct HStack: SimpleView {
/// The content. /// The content.
var content: () -> Body var content: () -> Body
/// The spacing between elements.
var spacing: Int
/// Whether the linked style should be used. /// Whether the linked style should be used.
var linked = false var linked = false
/// The view's body. /// The view's body.
public var view: Body { public var view: Body {
ModifierWrapper(content: VStack(horizontal: true, content: content), style: "linked", styleActive: linked) ModifierWrapper(
content: VStack(horizontal: true, spacing: spacing, content: content),
style: "linked",
styleActive: linked
)
} }
/// Initialize a `HStack`. /// Initialize a `HStack`.
/// - Parameter content: The view content. /// - Parameters:
public init(@ViewBuilder content: @escaping () -> Body) { /// - spacing: The spacing between elements.
/// - content: The view content.
public init(spacing: Int = 0, @ViewBuilder content: @escaping () -> Body) {
self.content = content self.content = content
self.spacing = spacing
} }
/// Link the children. /// Link the children.

View File

@ -13,17 +13,19 @@ public typealias VStack = Box
extension VStack { extension VStack {
/// Initialize a `VStack`. /// Initialize a `VStack`.
/// - Parameter content: The view content. /// - Parameters:
public init(@ViewBuilder content: @escaping () -> Body) { /// - spacing: The spacing between elements.
self.init(horizontal: false, content: content) /// - content: The view content.
public init(spacing: Int = 0, @ViewBuilder content: @escaping () -> Body) {
self.init(horizontal: false, spacing: spacing, content: content)
} }
/// Initialize a `VStack`. /// Initialize a `VStack`.
/// - Parameters: /// - Parameters:
/// - horizontal: Whether the box is horizontal. /// - horizontal: Whether the box is horizontal.
/// - content: The view content. /// - content: The view content.
init(horizontal: Bool, @ViewBuilder content: @escaping () -> Body) { init(horizontal: Bool, spacing: Int, @ViewBuilder content: @escaping () -> Body) {
self.init(spacing: 0) self.init(spacing: spacing)
self = self.append(content) self = self.append(content)
if horizontal { if horizontal {
appearFunctions.append { storage, _ in appearFunctions.append { storage, _ in