Got it to render with the verse properly so you can click on a word and it will select it. Doing this for highlighting and other stuff

undo
saint 2024-05-15 14:20:01 -04:00
parent 9550790a17
commit fb7dd47a96
1 changed files with 63 additions and 56 deletions

View File

@ -140,6 +140,8 @@ struct RibbonCrown: View {
height: CGFloat(100 * scale), height: CGFloat(100 * scale),
alignment: .center alignment: .center
).foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) ).foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
.contentShape(.dragPreview, RoundedRectangle(cornerRadius: 32))
.if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id && isDragging) { $0.overlay(Color(red: 0.1, green: 0.1, blue: 0.1)) } .if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id && isDragging) { $0.overlay(Color(red: 0.1, green: 0.1, blue: 0.1)) }
// .offset(x: 10) // .offset(x: 10)
@ -200,45 +202,30 @@ private struct SegRow: View {
var seg: SegDenorm var seg: SegDenorm
var ribbonId: Int64 var ribbonId: Int64
var body: some View { var body: some View {
var retView = Text("")
// .onTapGesture {
// // selectedLine = seg.id
// // Print(selectedLine)
// Print("meow")
// // Print(verse.body)
// }
var segSplit = seg.body.components(separatedBy: ";;")
let decoder = JSONDecoder()
// Text(segSplit[0].body)
// .id(seg.id)
// VStack {
// ForEach(segSplit.indices) { i in
segSplit.enumerated().forEach { _, item in
let verse = try! decoder.decode(Verse.self, from: item.data(using: .utf8)!)
var attributedString: AttributedString { // var attributedString: AttributedString {
// var result = AttributedString("Hello World!") // // var result = AttributedString("Hello World!")
var result = AttributedString(verse.body) // var result = AttributedString(verse.verse)
// result.underlineStyle = Text.LineStyle( // // result.underlineStyle = Text.LineStyle(
// pattern: .dot, color: .white) // // pattern: .dot, color: .white)
return result // return result
} // }
retView = retView + Text(String(ribbonId)) // retView = retView + Text(String(ribbonId))
// retView = retView + Text(attributedString) // // retView = retView + Text(attributedString)
// Text(seg.body) // // Text(seg.body)
// .contentShape(Rectangle()) // // .contentShape(Rectangle())
.font(Font.custom("AveriaSerifLibre-Regular", size: 10)) // .font(Font.custom("AveriaSerifLibre-Regular", size: 10))
.baselineOffset(6.0) // .baselineOffset(6.0)
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) // .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
retView = retView + // retView = retView +
Text(attributedString) // Text(attributedString)
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) // .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
.font(Font.custom("AveriaSerifLibre-Regular", size: 20)) // .font(Font.custom("AveriaSerifLibre-Regular", size: 20))
// .frame(maxWidth: .infinity, alignment: .leading) // // .frame(maxWidth: .infinity, alignment: .leading)
// .contentShape(Rectangle()) // // .contentShape(Rectangle())
// .listRowBackground(Color(red: 0.2, green: 0.8, blue: 0.2)) // .listRowBackground(Color(red: 0.2, green: 0.8, blue: 0.2))
// .listRowInsets(EdgeInsets()) // .listRowInsets(EdgeInsets())
@ -257,34 +244,54 @@ private struct SegRow: View {
// selectedLine = seg.id // selectedLine = seg.id
// Print(selectedLine) // Print(selectedLine)
// } // }
}
// }
let myText = "There was a man sent from God, whose name was John. This man came for a witness, to give testimony of the light, that all men might believe through him. He was not the light, but was to give testimony of the light. That was the true light, which enlighteneth every man that cometh into this world. He was in the world, and the world was made by him, and the world knew him not." var segSplit = seg.body.components(separatedBy: ";;")
let arrayOfText = myText.components(separatedBy: " ") let decoder = JSONDecoder()
var retView = WrappingHStack(alignment: .leading, horizontalSpacing: 3.5) {
// 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: " ")
var wordSelected = ""
var newView = WrappingHStack(alignment: .leading, horizontalSpacing: 3.5) {
ForEach(0..<arrayOfText.count, id: \.self) { index in
Text(arrayOfText[index])
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) ForEach(0..<arrayOfText.count, id: \.self) { index in
.font(Font.custom("AveriaSerifLibre-Regular", size: 20)) HStack (spacing: 2) {
if index == 0 {
Text(String(verse.verse))
.contentShape(Rectangle())
.font(Font.custom("AveriaSerifLibre-Regular", size: 10))
.baselineOffset(6.0)
.foregroundColor(Color.white) .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
// .background(Color.black) }
.padding(.horizontal, 0)
.onTapGesture { Text(arrayOfText[index])
Print(arrayOfText[index]) .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
Print(index) .font(Font.custom("AveriaSerifLibre-Regular", size: 20))
.foregroundColor(Color.white)
.padding(.horizontal, 0)
.onTapGesture {
Print(arrayOfText[index])
Print(index)
}
} }
// .if( index == 0 ) { $0.offset(x: -6) }
}
} }
} }
// return retView return retView
return newView } } }
}
struct ContentView: View { struct ContentView: View {
@State var viewState = CGSize.zero @State var viewState = CGSize.zero
@ -372,10 +379,10 @@ struct ContentView: View {
refresh: $refresh, refresh: $refresh,
draggedRibbon: draggedRibbon, draggedRibbon: draggedRibbon,
isDragging: isDragging) isDragging: isDragging)
.onDrag { .onDrag {
self.draggedRibbon = ribbon self.draggedRibbon = ribbon
return NSItemProvider() return NSItemProvider()
} }
.onDrop(of: [.item], .onDrop(of: [.item],
delegate: DropViewDelegate(destinationItem: ribbon, delegate: DropViewDelegate(destinationItem: ribbon,
draggedItem: $draggedRibbon, draggedItem: $draggedRibbon,