Files
phranck db8ea40c0a Refactor: Fix SwiftLint warnings and refactor StatusBar to _StatusBarCore pattern
- Fix 80 SwiftLint warnings (159 -> 79): vertical_whitespace, prefer_self_in_static_references, modifier_order, trailing_newline, trailing_whitespace, prefer_for_where, unneeded_synthesized_initializer, redundant_type_annotation, implicit_optional_initialization, superfluous_disable_command, shorthand_optional_binding, syntactic_sugar, empty_string, vertical_whitespace_closing_braces, identifier_name in BadgeModifier
- Refactor StatusBar from direct Renderable to _StatusBarCore pattern (public View with real body wrapping private Renderable core)
2026-02-15 02:35:18 +01:00

96 lines
2.6 KiB
Swift
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 🖥 TUIKit Terminal UI Kit for Swift
// ViewBuilder.swift
//
// Created by LAYERED.work
// License: MIT
import TUIkitCore
/// A result builder for View hierarchies.
///
/// The `@ViewBuilder` enables a declarative syntax similar to SwiftUI:
///
/// ```swift
/// VStack {
/// Text("Line 1")
/// Text("Line 2")
/// if showMore {
/// Text("Line 3")
/// }
/// }
/// ```
///
/// The builder supports:
/// - Single views
/// - Multiple views (unlimited, via Parameter Packs)
/// - Conditionals (`if`, `if-else`)
/// - Optional views (`if let`)
/// - Arrays of views (`for-in`)
@MainActor
@resultBuilder
public struct ViewBuilder {
// MARK: - Single View
/// Builds a single view.
public static func buildBlock<Content: View>(_ content: Content) -> Content {
content
}
// MARK: - Multiple Views (Parameter Pack)
/// Builds multiple views into a TupleView using Swift Parameter Packs.
///
/// This single overload replaces the previous 9 arity-specific `buildBlock`
/// overloads (`TupleView2` through `TupleView10`), removing the 10-child limit.
public static func buildBlock<each C: View>(
_ content: repeat each C
) -> TupleView<repeat each C> {
TupleView(repeat each content)
}
// MARK: - Conditionals
/// Supports the true branch of an if-else.
public static func buildEither<TrueContent: View, FalseContent: View>(
first content: TrueContent
) -> ConditionalView<TrueContent, FalseContent> {
.trueContent(content)
}
/// Supports the false branch of an if-else.
public static func buildEither<TrueContent: View, FalseContent: View>(
second content: FalseContent
) -> ConditionalView<TrueContent, FalseContent> {
.falseContent(content)
}
/// Supports optional views (if let, if without else).
public static func buildOptional<Content: View>(_ content: Content?) -> Content? {
content
}
/// Supports availability limiting.
public static func buildLimitedAvailability<Content: View>(_ content: Content) -> Content {
content
}
// MARK: - Arrays
/// Supports for-in loops.
public static func buildArray<Content: View>(_ components: [Content]) -> ViewArray<Content> {
ViewArray(components)
}
// MARK: - Expression
/// Converts a single expression into a view.
public static func buildExpression<Content: View>(_ expression: Content) -> Content {
expression
}
/// Supports optional expressions.
public static func buildExpression<Content: View>(_ expression: Content?) -> Content? {
expression
}
}