Files
TUIkit/Sources/TUIkitExample/Pages/MainMenuPage.swift
T
phranck df4ee3253b Feat: AppHeader — framework-managed header bar rendered outside the view tree
AppHeader is rendered at the top of the terminal by RenderLoop, similar to
StatusBar at the bottom. Views declare header content via .appHeader { }
ViewBuilder modifier. Supports standard (thin divider) and block (half-block
with appHeaderBackground) appearance. Hidden when no content is set.
Diff cache invalidates on header height changes to prevent ghosting.
2026-02-03 21:21:41 +01:00

93 lines
3.2 KiB
Swift

// 🖥️ TUIKit — Terminal UI Kit for Swift
// MainMenuPage.swift
//
// Created by LAYERED.work
// CC BY-NC-SA 4.0
import TUIkit
/// The main menu page.
///
/// Displays a centered menu with all available demos and
/// feature highlight boxes at the bottom.
struct MainMenuPage: View {
@Binding var currentPage: DemoPage
@Binding var menuSelection: Int
var body: some View {
VStack(spacing: 1) {
Spacer(minLength: 1)
HStack {
Spacer()
Menu(
title: "Select a Demo",
items: [
MenuItem(label: "Text Styles", shortcut: "1"),
MenuItem(label: "Colors", shortcut: "2"),
MenuItem(label: "Container Views", shortcut: "3"),
MenuItem(label: "Overlays & Modals", shortcut: "4"),
MenuItem(label: "Layout System", shortcut: "5"),
MenuItem(label: "Buttons & Focus", shortcut: "6"),
MenuItem(label: "Spinners", shortcut: "7"),
MenuItem(label: "Block Theme Colors", shortcut: "8"),
],
selection: $menuSelection,
onSelect: { index in
// Navigate to the selected page
if let page = DemoPage(rawValue: index + 1) {
currentPage = page
}
},
selectedColor: .palette.accent,
// borderStyle uses appearance default
borderColor: .palette.border
)
Spacer()
}
Spacer(minLength: 1)
// Feature highlights (centered)
HStack {
Spacer()
HStack(spacing: 3) {
featureBox("Pure Swift", "No ncurses")
featureBox("Declarative", "SwiftUI-like")
featureBox("Composable", "View protocol")
}
Spacer()
}
Spacer()
}
.appHeader {
VStack {
HStack {
Text("TUIkit Example App").bold().foregroundColor(.palette.accent)
Spacer()
Text("TUIkit v\(tuiKitVersion)").foregroundColor(.palette.foregroundTertiary)
}
Text("A SwiftUI-like framework for Terminal User Interfaces")
.foregroundColor(.palette.foregroundSecondary)
.italic()
}
}
}
/// Creates a small feature highlight box.
///
/// The border style is automatically derived from the current appearance.
private func featureBox(_ title: String, _ subtitle: String) -> some View {
VStack {
Text(title)
.bold()
.foregroundColor(.palette.accent)
Text(subtitle)
.foregroundColor(.palette.foregroundSecondary)
}
.padding(EdgeInsets(horizontal: 2, vertical: 1))
.border(color: .palette.border) // Uses appearance default borderStyle
}
}