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),
alignment: .center
).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)) }
// .offset(x: 10)
@ -201,44 +203,29 @@ private struct SegRow: View {
var ribbonId: Int64
var body: some View {
var retView = Text("")
// .onTapGesture {
// // selectedLine = seg.id
// // Print(selectedLine)
// Print("meow")
// // Print(verse.body)
// var attributedString: AttributedString {
// // var result = AttributedString("Hello World!")
// var result = AttributedString(verse.verse)
// // result.underlineStyle = Text.LineStyle(
// // pattern: .dot, color: .white)
// return result
// }
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 result = AttributedString("Hello World!")
var result = AttributedString(verse.body)
// 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(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())
// 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())
@ -257,24 +244,38 @@ private struct SegRow: View {
// selectedLine = seg.id
// 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."
let arrayOfText = myText.components(separatedBy: " ")
var segSplit = seg.body.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])
HStack (spacing: 2) {
if index == 0 {
Text(String(verse.verse))
.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)))
}
Text(arrayOfText[index])
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
.font(Font.custom("AveriaSerifLibre-Regular", size: 20))
.foregroundColor(Color.white)
// .background(Color.black)
.padding(.horizontal, 0)
.onTapGesture {
@ -282,9 +283,15 @@ private struct SegRow: View {
Print(index)
}
}
// .if( index == 0 ) { $0.offset(x: -6) }
}
}
}
return retView
}
}
// return retView
return newView } }
struct ContentView: View {
@State var viewState = CGSize.zero