mirror of
https://github.com/phranck/TUIkit.git
synced 2026-05-21 09:50:35 +00:00
45e73faafb
BREAKING CHANGE: Package name changed due to name collision with existing rensbreur/SwiftTUI package. Changes: - Rename package from SwiftTUI to TUIKit in Package.swift - Rename Sources/SwiftTUI to Sources/TUIKit - Rename Sources/SwiftTUIExample to Sources/TUIKitExample - Rename Tests/SwiftTUITests to Tests/TUIKitTests - Rename SwiftTUI.swift to TUIKit.swift - Update all imports: import SwiftTUI -> import TUIKit - Update all code references: SwiftTUI.renderToBuffer -> TUIKit.renderToBuffer - Update documentation comments - Rename swiftTUIVersion to tuiKitVersion All 181 tests passing.
82 lines
2.6 KiB
Swift
82 lines
2.6 KiB
Swift
//
|
|
// ContentView.swift
|
|
// TUIKitExample
|
|
//
|
|
// The main content view that routes between demo pages.
|
|
//
|
|
|
|
import TUIKit
|
|
|
|
// MARK: - Content View (Page Router)
|
|
|
|
/// The main content view that switches between pages.
|
|
///
|
|
/// This view acts as a router, displaying the appropriate demo page
|
|
/// based on the current state. It uses the `.statusBarItems()` modifier
|
|
/// to declaratively set context-sensitive status bar items.
|
|
struct ContentView: View {
|
|
var body: some View {
|
|
let state = ExampleAppState.shared
|
|
|
|
// Show current page based on state
|
|
pageContent(for: state.currentPage)
|
|
.onKeyPress { event in
|
|
switch event.key {
|
|
case .escape:
|
|
// ESC goes back to menu (or exits if already on menu)
|
|
if state.currentPage != .menu {
|
|
state.currentPage = .menu
|
|
return true // Consumed
|
|
}
|
|
return false // Let default handler exit the app
|
|
|
|
default:
|
|
return false // Let other handlers process
|
|
}
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func pageContent(for page: DemoPage) -> some View {
|
|
switch page {
|
|
case .menu:
|
|
MainMenuPage()
|
|
.statusBarItems {
|
|
StatusBarItem(shortcut: Shortcut.arrowsUpDown, label: "nav")
|
|
StatusBarItem(shortcut: Shortcut.enter, label: "select", key: .enter)
|
|
StatusBarItem(shortcut: Shortcut.range("1", "6"), label: "jump")
|
|
StatusBarItem(shortcut: Shortcut.quit, label: "quit")
|
|
}
|
|
case .textStyles:
|
|
TextStylesPage()
|
|
.statusBarItems(subPageItems)
|
|
case .colors:
|
|
ColorsPage()
|
|
.statusBarItems(subPageItems)
|
|
case .containers:
|
|
ContainersPage()
|
|
.statusBarItems(subPageItems)
|
|
case .overlays:
|
|
OverlaysPage()
|
|
.statusBarItems(subPageItems)
|
|
case .layout:
|
|
LayoutPage()
|
|
.statusBarItems(subPageItems)
|
|
case .buttons:
|
|
ButtonsPage()
|
|
.statusBarItems(subPageItems)
|
|
}
|
|
}
|
|
|
|
/// Common status bar items for sub-pages.
|
|
private var subPageItems: [any StatusBarItemProtocol] {
|
|
[
|
|
StatusBarItem(shortcut: Shortcut.escape, label: "back") {
|
|
ExampleAppState.shared.currentPage = .menu
|
|
},
|
|
StatusBarItem(shortcut: Shortcut.arrowsUpDown, label: "scroll"),
|
|
StatusBarItem(shortcut: Shortcut.quit, label: "quit")
|
|
]
|
|
}
|
|
}
|