From 4c484ccd9079f8bb81836b4f90af1e5ca96d76c9 Mon Sep 17 00:00:00 2001 From: saint Date: Thu, 16 May 2024 15:49:27 -0400 Subject: [PATCH] Highlighting works totally now --- HexColor.swift | 37 ++++++++++++++ gloss.xcodeproj/project.pbxproj | 4 ++ gloss/ContentView.swift | 88 +++++---------------------------- 3 files changed, 54 insertions(+), 75 deletions(-) create mode 100644 HexColor.swift diff --git a/HexColor.swift b/HexColor.swift new file mode 100644 index 0000000..b39b1c4 --- /dev/null +++ b/HexColor.swift @@ -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 + ) + } +} diff --git a/gloss.xcodeproj/project.pbxproj b/gloss.xcodeproj/project.pbxproj index 6861ff3..387d765 100644 --- a/gloss.xcodeproj/project.pbxproj +++ b/gloss.xcodeproj/project.pbxproj @@ -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 = ""; }; 85942EFC29B11C0A00307621 /* john_export.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = john_export.json; sourceTree = ""; }; 85942EFD29B11C0B00307621 /* mark_export.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = mark_export.json; sourceTree = ""; }; + 8594ED972BF6845F001213F2 /* HexColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexColor.swift; sourceTree = ""; }; 85E00E7B29F34D2D00FF9E78 /* ScrollState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollState.swift; sourceTree = ""; }; 85E00E7D29F34D3700FF9E78 /* ScrollStateRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollStateRequest.swift; sourceTree = ""; }; 85F01DF72978787800F317B4 /* AveriaSerifLibre-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "AveriaSerifLibre-Regular.ttf"; sourceTree = ""; }; @@ -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 */, diff --git a/gloss/ContentView.swift b/gloss/ContentView.swift index c3b1f57..0e1084b 100644 --- a/gloss/ContentView.swift +++ b/gloss/ContentView.swift @@ -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() 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..