Highlighting works totally now

undo
saint 2024-05-16 15:49:27 -04:00
parent f107e746b8
commit 4c484ccd90
3 changed files with 54 additions and 75 deletions

37
HexColor.swift Normal file
View File

@ -0,0 +1,37 @@
//
// HexColor.swift
// gloss
//
// Created by Saint on 5/16/24.
//
import Foundation
import SwiftUI
extension Color {
init(hex: String) {
let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
var int: UInt64 = 0
Scanner(string: hex).scanHexInt64(&int)
let a, r, g, b: UInt64
switch hex.count {
case 3: // RGB (12-bit)
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
case 6: // RGB (24-bit)
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
case 8: // ARGB (32-bit)
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
default:
(a, r, g, b) = (1, 1, 1, 0)
}
self.init(
.sRGB,
red: Double(r) / 255,
green: Double(g) / 255,
blue: Double(b) / 255,
opacity: Double(a) / 255
)
}
}

View File

@ -35,6 +35,7 @@
85942EF929B1150B00307621 /* SegDenorm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85942EF829B1150B00307621 /* SegDenorm.swift */; };
85942EFE29B11C0B00307621 /* john_export.json in Resources */ = {isa = PBXBuildFile; fileRef = 85942EFC29B11C0A00307621 /* john_export.json */; };
85942EFF29B11C0B00307621 /* mark_export.json in Resources */ = {isa = PBXBuildFile; fileRef = 85942EFD29B11C0B00307621 /* mark_export.json */; };
8594ED982BF6845F001213F2 /* HexColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8594ED972BF6845F001213F2 /* HexColor.swift */; };
85E00E7C29F34D2D00FF9E78 /* ScrollState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85E00E7B29F34D2D00FF9E78 /* ScrollState.swift */; };
85E00E7E29F34D3700FF9E78 /* ScrollStateRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85E00E7D29F34D3700FF9E78 /* ScrollStateRequest.swift */; };
85F01DF82978787800F317B4 /* AveriaSerifLibre-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 85F01DF72978787800F317B4 /* AveriaSerifLibre-Regular.ttf */; };
@ -69,6 +70,7 @@
85942EF829B1150B00307621 /* SegDenorm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegDenorm.swift; sourceTree = "<group>"; };
85942EFC29B11C0A00307621 /* john_export.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = john_export.json; sourceTree = "<group>"; };
85942EFD29B11C0B00307621 /* mark_export.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = mark_export.json; sourceTree = "<group>"; };
8594ED972BF6845F001213F2 /* HexColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexColor.swift; sourceTree = "<group>"; };
85E00E7B29F34D2D00FF9E78 /* ScrollState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollState.swift; sourceTree = "<group>"; };
85E00E7D29F34D3700FF9E78 /* ScrollStateRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollStateRequest.swift; sourceTree = "<group>"; };
85F01DF72978787800F317B4 /* AveriaSerifLibre-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "AveriaSerifLibre-Regular.ttf"; sourceTree = "<group>"; };
@ -104,6 +106,7 @@
85431A7C2905F4F500EE0760 = {
isa = PBXGroup;
children = (
8594ED972BF6845F001213F2 /* HexColor.swift */,
85E00E7B29F34D2D00FF9E78 /* ScrollState.swift */,
85E00E7D29F34D3700FF9E78 /* ScrollStateRequest.swift */,
8528897429B2B86B003F2E16 /* CrownOfThorns.swift */,
@ -280,6 +283,7 @@
85431A8B2905F4F500EE0760 /* ContentView.swift in Sources */,
85942EF529B108C600307621 /* Seg.swift in Sources */,
85E00E7C29F34D2D00FF9E78 /* ScrollState.swift in Sources */,
8594ED982BF6845F001213F2 /* HexColor.swift in Sources */,
8528897529B2B86B003F2E16 /* CrownOfThorns.swift in Sources */,
85E00E7E29F34D3700FF9E78 /* ScrollStateRequest.swift in Sources */,
85942EE929AD51A100307621 /* Ribbon.swift in Sources */,

View File

@ -201,68 +201,20 @@ func makeVerseView(seg: SegDenorm) -> some View {
private struct SegRow: View {
var seg: SegDenorm
var ribbonId: Int64
@State var highlights = 0
@State var highlights = Set<Int>()
var body: some View {
// var attributedString: AttributedString {
// // var result = AttributedString("Hello World!")
// var result = AttributedString(verse.verse)
// // result.underlineStyle = Text.LineStyle(
// // pattern: .dot, color: .white)
// return result
// }
// retView = retView + Text(String(ribbonId))
// // retView = retView + Text(attributedString)
// // Text(seg.body)
// // .contentShape(Rectangle())
// .font(Font.custom("AveriaSerifLibre-Regular", size: 10))
// .baselineOffset(6.0)
// .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
// retView = retView +
// Text(attributedString)
// .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
// .font(Font.custom("AveriaSerifLibre-Regular", size: 20))
// // .frame(maxWidth: .infinity, alignment: .leading)
// // .contentShape(Rectangle())
// .listRowBackground(Color(red: 0.2, green: 0.8, blue: 0.2))
// .listRowInsets(EdgeInsets())
// .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20))
// .listRowSeparator(.hidden)
// .id(String(seg.id) + "body" + String(i))
// .id(seg.id)
// .listRowBackground(Color(red: 0.2, green: 0.8, blue: 0.2))
// .listRowInsets(EdgeInsets())
// .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20))
// .listRowSeparator(.hidden)
// .id(String(seg.id) + "verse" + String(i))
// .id(seg.id)
// .onTapGesture {
// selectedLine = seg.id
// Print(selectedLine)
// }
var segSplit = seg.body.components(separatedBy: ";;")
let decoder = JSONDecoder()
// var retView = WrappingHStack(alignment: .leading, horizontalSpacing: 3.5) {
var retView = WrappingHStack(alignment: .leading, horizontalSpacing: 0) {
// segSplit.enumerated().forEach { _, item in
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(20)
let highlightColor = "470000"
ForEach(0..<arrayOfText.count, id: \.self) { index in
HStack (spacing: 0) {
if index == 0 {
@ -270,36 +222,21 @@ private struct SegRow: View {
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 == verse.verse ) { $0.background(Color.blue) }
// Rectangle()
// .if( self.highlights == verse.verse ) { $0.fill(.blue) }
// .frame(width: 2)
// .frame(height:lineHeight)
// .if( self.highlights != verse.verse ) { $0.opacity(0) }
.if( self.highlights.contains(verse.verse) ) { $0.background(Color.init(hex: highlightColor)) }
VStack (spacing: 0) {
// Rectangle()
// .fill(.blue)
// .frame(width: 6, height: 1)
// // .if( self.highlights == verse.verse ) { $0.opacity(1.0) }
// // .if( self.highlights != verse.verse ) { $0.opacity(0.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 == verse.verse ) { $0.background(Color.blue) }
.if( self.highlights.contains(verse.verse) ) { $0.background(Color.init(hex: highlightColor)) }
Text(String(verse.verse))
.contentShape(Rectangle())
.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 == verse.verse ) { $0.background(Color.blue) }
.if( self.highlights.contains(verse.verse) ) { $0.background(Color.init(hex: highlightColor)) }
}
.if( self.highlights == verse.verse ) { $0.background(Color.blue) }
.if( self.highlights.contains(verse.verse) ) { $0.background(Color.init(hex: highlightColor)) }
}
}
@ -308,7 +245,7 @@ private struct SegRow: View {
.font(Font.custom("AveriaSerifLibre-Regular", size: fontSize))
.padding(.horizontal, 1.5) // intra word spacing
.if( self.highlights == verse.verse ) { $0.background(Color.blue) }
.if( self.highlights.contains(verse.verse) ) { $0.background(Color.init(hex: highlightColor)) }
.foregroundColor(Color.white)
@ -316,16 +253,17 @@ private struct SegRow: View {
.onTapGesture {
Print(arrayOfText[index])
Print(verse.verse)
self.highlights = verse.verse
if self.highlights.contains(verse.verse) {
self.highlights.remove(verse.verse)
} else {
self.highlights.insert(verse.verse)
}
}
}
.frame(height:16) // intra line spacing
.padding(.vertical, 0)
// .if( index == 0 ) { $0.offset(x: -6) }
}
}
}
return retView
}