diff --git a/Sources/Core/Model/Idle.swift b/Sources/Core/Model/Idle.swift index c28d98d..556f1ac 100644 --- a/Sources/Core/Model/Idle.swift +++ b/Sources/Core/Model/Idle.swift @@ -78,6 +78,20 @@ public struct Idle { /// An idle handler. class IdleHandler { + /// Execute the function. + /// - Parameter pointer: The closure wrapper's pointer. + static func run(pointer: gpointer?) -> Int32 { + if let pointer { + let container = Unmanaged.fromOpaque(pointer).takeUnretainedValue() + let result = container.closure() + if !result { + Unmanaged.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. /// - Parameter closure: The function. 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.fromOpaque(pointer).takeUnretainedValue() - let result = container.closure() - if !result { - Unmanaged.fromOpaque(pointer).release() - } - return result.cBool - } - return G_SOURCE_REMOVE - } - } /// A reference type holding a closure. diff --git a/Sources/Core/View/HStack.swift b/Sources/Core/View/HStack.swift index aadf90c..df34219 100644 --- a/Sources/Core/View/HStack.swift +++ b/Sources/Core/View/HStack.swift @@ -10,18 +10,27 @@ public struct HStack: SimpleView { /// The content. var content: () -> Body + /// The spacing between elements. + var spacing: Int /// Whether the linked style should be used. var linked = false /// The view's 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`. - /// - Parameter content: The view content. - public init(@ViewBuilder content: @escaping () -> Body) { + /// - Parameters: + /// - spacing: The spacing between elements. + /// - content: The view content. + public init(spacing: Int = 0, @ViewBuilder content: @escaping () -> Body) { self.content = content + self.spacing = spacing } /// Link the children. diff --git a/Sources/Core/View/VStack.swift b/Sources/Core/View/VStack.swift index e28cc64..3b93831 100644 --- a/Sources/Core/View/VStack.swift +++ b/Sources/Core/View/VStack.swift @@ -13,17 +13,19 @@ public typealias VStack = Box extension VStack { /// Initialize a `VStack`. - /// - Parameter content: The view content. - public init(@ViewBuilder content: @escaping () -> Body) { - self.init(horizontal: false, content: content) + /// - Parameters: + /// - spacing: The spacing between elements. + /// - content: The view content. + public init(spacing: Int = 0, @ViewBuilder content: @escaping () -> Body) { + self.init(horizontal: false, spacing: spacing, content: content) } /// Initialize a `VStack`. /// - Parameters: /// - horizontal: Whether the box is horizontal. /// - content: The view content. - init(horizontal: Bool, @ViewBuilder content: @escaping () -> Body) { - self.init(spacing: 0) + init(horizontal: Bool, spacing: Int, @ViewBuilder content: @escaping () -> Body) { + self.init(spacing: spacing) self = self.append(content) if horizontal { appearFunctions.append { storage, _ in