From ac45ae5b20b1b216c552e07ed7aa01ea984415d6 Mon Sep 17 00:00:00 2001 From: saint Date: Wed, 12 Jun 2024 12:19:30 -0400 Subject: [PATCH] chap number view prelim --- Pane.swift | 63 +++++++++++++++++++++++++++-------------- SegDenorm.swift | 3 +- SegDenormRequest.swift | 2 +- gloss/ContentView.swift | 7 +++++ 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/Pane.swift b/Pane.swift index 045962b..013616d 100644 --- a/Pane.swift +++ b/Pane.swift @@ -14,46 +14,63 @@ import WrappingHStack struct SegRow: View { var seg: SegDenorm var ribbonId: Int64 + var width: CGFloat @State var highlights = Set() + @State var chapVisible = false + let intraWordSpacing = CGFloat(1.6) var body: some View { var segSplit = seg.body.components(separatedBy: ";;") let decoder = JSONDecoder() - var retView = WrappingHStack(alignment: .leading, horizontalSpacing: 0) { - ForEach(0 ..< segSplit.count, id: \.self) { segIndex in + var retView = VStack { + Text("\(seg.chap)") + .frame(width: width) + .padding(.vertical, 10) - let verse = try! decoder.decode(Verse.self, from: segSplit[segIndex].data(using: .utf8)!) - let arrayOfText = verse.body.components(separatedBy: " ") + .if(chapVisible) { $0.foregroundColor(mainTextColor) } + .if(!chapVisible) { $0.foregroundColor(secondBackgroundColor) } - let lineHeight = CGFloat(30) - let fontSize = CGFloat(18) - let highlightColor = "470000" - ForEach(0 ..< arrayOfText.count, id: \.self) { index in - HStack(spacing: 0) { - if index == 0 { - Text("") + .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) + .background(secondBackgroundColor) + // .background(mainBackgroundColor) + .onTapGesture { + chapVisible.toggle() + } + WrappingHStack(alignment: .leading, horizontalSpacing: 0) { + ForEach(0 ..< segSplit.count, id: \.self) { segIndex in + + let verse = try! decoder.decode(Verse.self, from: segSplit[segIndex].data(using: .utf8)!) + let arrayOfText = verse.body.components(separatedBy: " ") + + let lineHeight = CGFloat(30) + let fontSize = CGFloat(18) + let highlightColor = "470000" + ForEach(0 ..< arrayOfText.count, id: \.self) { index in + HStack(spacing: 0) { + if index == 0 { + Text("") .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } - VStack(spacing: 0) { - ZStack { - Text(" ") + VStack(spacing: 0) { + ZStack { + Text(" ") .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } - Text(String(verse.verse)) + Text(String(verse.verse)) .font(Font.custom("AveriaSerifLibre-Regular", size: 10)) .padding(.horizontal, 0) .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } + } + .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } } - .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } } - } - Text(arrayOfText[index]) + Text(arrayOfText[index]) .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) @@ -69,9 +86,10 @@ struct SegRow: View { self.highlights.insert(verse.verse) } } + } + .frame(height: 16) // intra line spacing + .padding(.vertical, 0) } - .frame(height: 16) // intra line spacing - .padding(.vertical, 0) } } } @@ -104,10 +122,11 @@ struct Pane: View { LazyVStack { ForEach(segs) { seg in SegRow(seg: seg, - ribbonId: selectedRibbon[0].id!) + ribbonId: selectedRibbon[0].id!, + width: width) .id("\(seg.id)") .offset(x: -dragOffset) - .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20)) + .padding(EdgeInsets(top: 10, leading: 20, bottom: 20, trailing: 20)) .trackVisibility(id: "\(seg.id)") } } diff --git a/SegDenorm.swift b/SegDenorm.swift index fcea00a..c407b3c 100644 --- a/SegDenorm.swift +++ b/SegDenorm.swift @@ -11,6 +11,7 @@ struct SegDenorm: Identifiable, Equatable { var body: String // var lineIds: [Int64] var book: String + var chap: Int64 } extension SegDenorm { @@ -27,7 +28,7 @@ extension SegDenorm: Codable, FetchableRecord, MutablePersistableRecord { // static let id = Column(CodingKeys.id) // static let book = Column(CodingKeys.book) // } - + // /// Updates a player id after it has been inserted in the database. // mutating func didInsert(_ inserted: InsertionSuccess) { // id = inserted.rowID diff --git a/SegDenormRequest.swift b/SegDenormRequest.swift index 2fadd4d..a74c9f8 100644 --- a/SegDenormRequest.swift +++ b/SegDenormRequest.swift @@ -43,7 +43,7 @@ struct SegDenormRequest: Queryable { var book = ret[0].book var sql = """ - select seg_id as id, seg.book as book, group_concat(line.body, ';;') as body from \ + select seg_id as id, line.chap as chap, seg.book as book, group_concat(line.body, ';;') as body from \ (select * from seg where seg.book = '\(book)') as seg \ join (select * from line where line.book = '\(book)') as line \ on seg.line_id = line.line_id group by seg.seg_id diff --git a/gloss/ContentView.swift b/gloss/ContentView.swift index 53a9bc3..20414a2 100644 --- a/gloss/ContentView.swift +++ b/gloss/ContentView.swift @@ -18,6 +18,11 @@ var currentOffset: CGFloat? var disableDrop = false +//TODO: move to globals file +let mainBackgroundColor = Color(red: 0.1, green: 0.1, blue: 0.1) +let mainTextColor = Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)) +let secondBackgroundColor = Color(red: 0.18, green: 0.18, blue: 0.18) + public extension UserDefaults { func optionalInt(forKey defaultName: String) -> Int? { let defaults = self @@ -484,6 +489,8 @@ struct ContentView: View { startSwipeState = nil startSwipeDir = nil + print("foo") + // if mainSwipe.width < 0 && pulledOut.width > 0 { // setPulledOutWith = CGFloat(0) // } else if mainSwipe.width > 0 && pulledOut.width < 0 {