@@ -6,14 +6,43 @@ import SwiftUI
66struct PlayerOverlay : View {
77 @ ObservedObject var app : AppState
88
9+ /// Measured natural height of the full subtitle text (for the crawl mapping).
10+ @ State private var contentHeight : CGFloat = 0
11+
912 private var tint : Color { app . playbackMode == . tts ? . blue : . purple }
1013
14+ /// Viewport height — a few lines tall so text visibly rises (Star Wars crawl).
15+ private var subtitleViewportHeight : CGFloat { max ( 160 , app . subtitleFontSize * 6.5 ) }
16+
17+ /// Teleprompter crawl with the reading line near the TOP: at progress 0 the
18+ /// first line sits just below the top (a small pad leaves a band for read
19+ /// text to fade through); as playback advances the text rises and earlier
20+ /// sentences scroll up and off the top. Clamped at the END so the last
21+ /// sentences settle at the bottom and stay on screen (don't scroll off/fade).
22+ private func crawlOffset ( progress : Double , contentH : CGFloat , viewportH : CGFloat ) -> CGFloat {
23+ let topPad = app . subtitleFontSize * 1.5
24+ let raw = topPad - CGFloat ( progress ) * contentH
25+ let minOffset = min ( topPad , viewportH - contentH ) // most-negative: end-of-content rests at the viewport bottom
26+ return max ( minOffset , raw )
27+ }
28+
29+ /// Pinned to the viewport's top edge: read text fades out gradually as it
30+ /// rises through the band. No bottom fade — so the last sentences, which
31+ /// settle at the bottom, stay fully legible.
32+ private var crawlFadeMask : LinearGradient {
33+ LinearGradient ( stops : [
34+ . init ( color : . clear , location : 0.0 ) ,
35+ . init ( color : . black , location : 0.30 ) ,
36+ . init ( color : . black , location : 1.0 ) ,
37+ ] , startPoint : . top , endPoint : . bottom )
38+ }
39+
1140 /// Widen the HUD with the subtitle font so a line holds roughly the same
1241 /// number of characters at any size — bigger text → wider panel, fewer
1342 /// wraps. Stays compact (360) when no subtitle is showing; capped so it
1443 /// never runs off a normal screen.
1544 private var hudWidth : CGFloat {
16- guard app . showSubtitle , ! app . currentChunkText . isEmpty else { return 360 }
45+ guard app . showSubtitle , ! app . spokenChunks . isEmpty else { return 360 }
1746 return min ( max ( 360 , app . subtitleFontSize * 24 ) , 760 )
1847 }
1948
@@ -56,41 +85,41 @@ struct PlayerOverlay: View {
5685 }
5786 }
5887
59- if app . showSubtitle , ! app . currentChunkText . isEmpty {
60- ScrollViewReader { proxy in
61- ScrollView {
62- VStack ( alignment : . leading , spacing : 4 ) {
63- ForEach ( Array ( app . currentSentences . enumerated ( ) ) , id : \. offset ) { i , s in
64- let cur = app . currentSentenceIndex
65- Text ( s )
66- . font ( . system ( size : app . subtitleFontSize ) )
67- . fontWeight ( i == cur ? . semibold : . regular )
68- . foregroundStyle ( i == cur ? AnyShapeStyle ( . primary ) : AnyShapeStyle ( . secondary ) )
69- . opacity ( i == cur ? 1 : max ( 0.3 , 1 - 0.25 * Double ( abs ( i - cur ) ) ) )
70- . padding ( . horizontal , i == cur ? 6 : 0 )
71- . padding ( . vertical , i == cur ? 3 : 0 )
72- . background ( i == cur ? tint . opacity ( 0.22 ) : . clear ,
73- in : RoundedRectangle ( cornerRadius : 6 ) )
74- . frame ( maxWidth : . infinity , alignment : . leading )
75- . id ( i )
76- }
77- }
78- }
79- . frame ( maxHeight : max ( 92 , app . subtitleFontSize * 5 ) )
80- . onChange ( of : app . currentSentenceIndex ) { _ , idx in
81- withAnimation ( . easeInOut ( duration : 0.25 ) ) { proxy . scrollTo ( idx , anchor : . center ) }
82- }
83- . onChange ( of : app . chunkIndex ) { _ , _ in
84- proxy . scrollTo ( 0 , anchor : . top ) // new paragraph → back to top
88+ if app . showSubtitle , ! app . crawlLines . isEmpty {
89+ // The WHOLE script is one column; it scrolls continuously so
90+ // paragraphs flow into each other (no per-paragraph reset).
91+ VStack ( alignment : . leading , spacing : 4 ) {
92+ ForEach ( app . crawlLines ) { line in
93+ let cur = app . isCurrentLine ( line )
94+ Text ( line . text )
95+ . font ( . system ( size : app . subtitleFontSize ) )
96+ // distinguish the current line by brightness only (no weight
97+ // change — that snaps and reflows, which read as abrupt)
98+ . foregroundStyle ( cur ? AnyShapeStyle ( . primary ) : AnyShapeStyle ( . secondary ) )
99+ . opacity ( cur ? 1 : 0.4 )
100+ . padding ( . horizontal , 6 )
101+ . padding ( . vertical , 3 )
102+ . frame ( maxWidth : . infinity , alignment : . leading )
103+ . animation ( . easeInOut ( duration : 0.5 ) , value : cur ) // gently fade the emphasis in/out
85104 }
86105 }
106+ . fixedSize ( horizontal : false , vertical : true ) // take full natural height (don't compress to the viewport)
107+ . background ( GeometryReader { g in // measure that natural height for the crawl mapping
108+ Color . clear
109+ . onAppear { contentHeight = g . size . height }
110+ . onChange ( of : g . size . height ) { _ , h in contentHeight = h }
111+ } )
112+ . offset ( y : crawlOffset ( progress : app . crawlFraction , contentH : contentHeight , viewportH : subtitleViewportHeight ) )
113+ . animation ( . linear ( duration : 0.12 ) , value : app . crawlFraction ) // smooth between 0.1s ticks
114+ . frame ( height : subtitleViewportHeight , alignment : . top ) // viewport: fixed window the text scrolls through
115+ . clipped ( )
116+ . mask ( crawlFadeMask ) // top-edge fade band (pinned to the viewport, not the moving text)
87117 }
88118
89- // Progress spans the width; transport stays a fixed-size, centered
90- // cluster so it doesn't grow or spread out as the subtitle/panel widen.
91- ProgressView ( value : app . progress ) . progressViewStyle ( . linear )
92-
93- HStack ( spacing : 22 ) {
119+ // Transport + progress are one fixed-size, centered cluster, so the
120+ // progress bar keeps a fixed width and nothing stretches as the
121+ // subtitle/panel widen.
122+ HStack ( spacing : 16 ) {
94123 Button { app . skipPrev ( ) } label : { Image ( systemName : " backward.fill " ) }
95124 . disabled ( ! app . canSkipPrev )
96125 Button { app . togglePause ( ) } label : {
@@ -101,6 +130,10 @@ struct PlayerOverlay: View {
101130 . help ( app . phase == . paused ? " 재개 " : " 일시정지 " )
102131 Button { app . skipNext ( ) } label : { Image ( systemName : " forward.fill " ) }
103132 . disabled ( ! app . canSkipNext )
133+
134+ ProgressView ( value : app . progress ) . progressViewStyle ( . linear )
135+ . frame ( width : 140 )
136+
104137 Button { app . stop ( ) } label : { Image ( systemName : " stop.fill " ) }
105138 . foregroundStyle ( . secondary ) . help ( " 중지 " )
106139 }
0 commit comments