mirror of
https://github.com/phranck/TUIkit.git
synced 2026-06-20 09:54:37 +00:00
- Rename module, targets and products in Package.swift - Rename directories: Sources/TUIkit, TUIkitExample, Tests/TUIkitTests - Rename files: TUIkit.swift, TUIkit.docc/TUIkit.md - Update all import statements, module-qualified calls, file headers - Update doc comments, string literals and DocC articles - Update CI workflow, README, .swiftlint.yml and markdown docs - Merge platform badges into single combined badge in README - Add "Example App auslagern" task to to-dos.md
81 lines
2.6 KiB
Swift
81 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
|
|
// Note: Background color is set by AppRunner using theme.background
|
|
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")
|
|
}
|
|
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"),
|
|
]
|
|
}
|
|
}
|