Files
TUIkit/Sources/TUIkit/Extensions/View+Environment.swift
T
phranck 1ab4b697a2 Refactor: Restructure source tree with palette rename, file splits, and Renderable co-location
- Move files into Environment/, Focus/, State/, Styling/, StatusBar/ directories
- Split Theme.swift into Palette protocol + 6 individual palette files in Styling/Palettes/
- Rename Phosphor palettes: GreenPhosphorPalette → GreenPalette, etc. (types and IDs)
- Remove deprecated .greenPhosphor/.amberPhosphor/.whitePhosphor/.redPhosphor accessors
- Split StatusBar.swift (983 LOC) → StatusBar.swift + StatusBarItem.swift
- Extract ButtonRow and ButtonRowBuilder from Button.swift → ButtonRow.swift
- Dissolve ViewRenderer.swift: move Renderable conformances to each type's own file
- Move AnyView from Menu.swift to Core/PrimitiveViews.swift
- Update DocC articles, README, and all test files
- 506 tests passing, build verified
2026-01-31 00:38:01 +01:00

68 lines
1.6 KiB
Swift

//
// View+Environment.swift
// TUIkit
//
// Environment injection view modifiers: environment, appearance, theme.
//
// MARK: - Environment
extension View {
/// Sets an environment value for this view and its children.
///
/// - Parameters:
/// - keyPath: The key path to the environment value.
/// - value: The value to set.
/// - Returns: A view with the modified environment.
public func environment<V>(
_ keyPath: WritableKeyPath<EnvironmentValues, V>,
_ value: V
) -> some View {
EnvironmentModifier(content: self, keyPath: keyPath, value: value)
}
}
// MARK: - Appearance
extension View {
/// Sets the appearance for this view and its descendants.
///
/// # Example
///
/// ```swift
/// ContentView()
/// .appearance(.rounded)
///
/// // Local override
/// Panel("ASCII Style") {
/// content()
/// }
/// .appearance(.ascii)
/// ```
///
/// - Parameter appearance: The appearance to apply.
/// - Returns: A view with the appearance applied.
public func appearance(_ appearance: Appearance) -> some View {
environment(\.appearance, appearance)
}
}
// MARK: - Palette
extension View {
/// Sets the color palette for this view and its descendants.
///
/// # Example
///
/// ```swift
/// ContentView()
/// .palette(GreenPalette())
/// ```
///
/// - Parameter palette: The palette to apply.
/// - Returns: A view with the palette applied.
public func palette(_ palette: any Palette) -> some View {
environment(\.palette, palette)
}
}