mirror of
https://github.com/phranck/TUIkit.git
synced 2026-06-20 09:54:37 +00:00
Appearance controls the visual structure (border style) of UI controls, while Theme controls colors. Together they create a complete look. New types: - Appearance: Defines borderStyle for all controls - Appearance.ID: Type-safe identifier (no magic strings) - AppearanceManager: Environment-based cycling (no singleton) - AppearanceRegistry: Available appearances Predefined appearances: - .rounded (default) - Curved corners - .sharp - 90-degree corners - .double - Double-line borders - .heavy - Thick/bold borders - .ascii - Maximum terminal compatibility (+, -, |) Updated components to use appearance.borderStyle as default: - Menu, Button, Panel, Card, Box, Alert, Dialog - BorderModifier (.border() modifier) Added 'a' key shortcut to cycle through appearances. Also added BorderStyle.ascii for ASCII-only terminals. All 189 tests passing.
57 lines
1.3 KiB
Swift
57 lines
1.3 KiB
Swift
//
|
|
// Box.swift
|
|
// TUIKit
|
|
//
|
|
// A simple bordered container view.
|
|
//
|
|
|
|
/// A simple bordered container view.
|
|
///
|
|
/// `Box` wraps content in a border without additional styling.
|
|
/// Use `Card` if you need padding and background as well.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```swift
|
|
/// Box {
|
|
/// Text("Boxed content")
|
|
/// }
|
|
///
|
|
/// Box(.doubleLine, color: .yellow) {
|
|
/// VStack {
|
|
/// Text("Line 1")
|
|
/// Text("Line 2")
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
public struct Box<Content: View>: View {
|
|
/// The content of the box.
|
|
public let content: Content
|
|
|
|
/// The border style (nil uses appearance default).
|
|
public let borderStyle: BorderStyle?
|
|
|
|
/// The border color.
|
|
public let borderColor: Color?
|
|
|
|
/// Creates a box with the specified border.
|
|
///
|
|
/// - Parameters:
|
|
/// - borderStyle: The border style (default: appearance borderStyle).
|
|
/// - color: The border color (default: theme border).
|
|
/// - content: The content of the box.
|
|
public init(
|
|
_ borderStyle: BorderStyle? = nil,
|
|
color: Color? = nil,
|
|
@ViewBuilder content: () -> Content
|
|
) {
|
|
self.content = content()
|
|
self.borderStyle = borderStyle
|
|
self.borderColor = color
|
|
}
|
|
|
|
public var body: some View {
|
|
content.border(borderStyle, color: borderColor)
|
|
}
|
|
}
|