swipe works better but not done

undo
saint 2024-06-07 11:24:33 -04:00
parent 678400c05e
commit f202589f89
9 changed files with 1906 additions and 641 deletions

View File

@ -1 +0,0 @@
{"xcodeproj": "/Users/saint/code/gloss/gloss.xcodeproj", "projectFile": "/Users/saint/code/gloss/gloss.xcodeproj", "scheme": "gloss", "projectCommand": "-project '/Users/saint/code/gloss/gloss.xcodeproj'"}

52
BookmarkIcon.swift Normal file
View File

@ -0,0 +1,52 @@
//
// BookmarkIcon.swift
// gloss
//
// Created by Saint on 6/4/24.
//
import Foundation
import SwiftUI
struct BookmarkIcon: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
let width = rect.size.width
let height = rect.size.height
path.move(to: CGPoint(x: 0.75*width, y: 0.08333*height))
path.addLine(to: CGPoint(x: 0.25*width, y: 0.08333*height))
path.addLine(to: CGPoint(x: 0.25*width, y: 0.16667*height))
path.addLine(to: CGPoint(x: 0.74998*width, y: 0.16667*height))
path.addLine(to: CGPoint(x: 0.74998*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.66666*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.66666*width, y: 0.75*height))
path.addLine(to: CGPoint(x: 0.58332*width, y: 0.75*height))
path.addLine(to: CGPoint(x: 0.58332*width, y: 0.66667*height))
path.addLine(to: CGPoint(x: 0.41666*width, y: 0.66667*height))
path.addLine(to: CGPoint(x: 0.41666*width, y: 0.75*height))
path.addLine(to: CGPoint(x: 0.33332*width, y: 0.75*height))
path.addLine(to: CGPoint(x: 0.33332*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.24999*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.24999*width, y: 0.08334*height))
path.addLine(to: CGPoint(x: 0.16666*width, y: 0.08334*height))
path.addLine(to: CGPoint(x: 0.16666*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.24999*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.24999*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.33332*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.33332*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.41666*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.41666*width, y: 0.75*height))
path.addLine(to: CGPoint(x: 0.58332*width, y: 0.75*height))
path.addLine(to: CGPoint(x: 0.58332*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.66666*width, y: 0.83333*height))
path.addLine(to: CGPoint(x: 0.66666*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.74998*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.74998*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.83331*width, y: 0.91667*height))
path.addLine(to: CGPoint(x: 0.83331*width, y: 0.08334*height))
path.addLine(to: CGPoint(x: 0.75*width, y: 0.08334*height))
path.addLine(to: CGPoint(x: 0.75*width, y: 0.08333*height))
path.closeSubpath()
return path
}
}

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@ struct SegRow: View {
let arrayOfText = verse.body.components(separatedBy: " ")
let lineHeight = CGFloat(30)
let fontSize = CGFloat(20)
let fontSize = CGFloat(18)
let highlightColor = "470000"
ForEach(0 ..< arrayOfText.count, id: \.self) { index in
HStack(spacing: 0) {

View File

@ -15,16 +15,12 @@ struct NaviBar: View {
var body: some View {
var iconSize = CGFloat(25)
VStack {
HStack {
// Print("meow navi reloaded back ribbon: \(backRibbon[0])")
Print("rendering navi")
Print("dog backRibbon: \(backRibbon)")
HStack(spacing: 30) {
BackArrow()
.frame(width: CGFloat(30), height: CGFloat(30))
.frame(width: iconSize, height: iconSize)
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
// .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
.if(paneConnector.hasMoved) { $0.foregroundColor(Color.black) }
.if(!paneConnector.hasMoved) { $0.foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) }
.onTapGesture {
@ -64,8 +60,13 @@ struct NaviBar: View {
}
}
BookmarkIcon()
.frame(width: iconSize, height: iconSize)
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
.foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
ForwardArrow()
.frame(width: CGFloat(30), height: CGFloat(30))
.frame(width: iconSize, height: iconSize)
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
.foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
.onTapGesture {
@ -85,6 +86,29 @@ struct NaviBar: View {
loading: false)
}
}
// Rectangle()
// .fill(Color(red: 0.1, green: 0.1, blue: 0.1))
// .frame(width: iconSize, height: iconSize)
// BackArrow()
// .frame(width: iconSize, height: iconSize)
// .background(Color(red: 0.1, green: 0.1, blue: 0.1))
// BookmarkIcon()
// .frame(width: iconSize, height: iconSize)
// .background(Color(red: 0.1, green: 0.1, blue: 0.1))
// .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
// ForwardArrow()
// .frame(width: iconSize, height: iconSize)
// .background(Color(red: 0.1, green: 0.1, blue: 0.1))
// .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
}
.cornerRadius(5)
}

View File

@ -61,8 +61,15 @@ struct StatsPanel: View {
}
VStack(spacing: 5) {
let fr = allRibbons[0]
let currentPos = (fr.currentLevel - fr.minLevel) %% totalLevels
let text = "current pos: \(currentPos)"
Text(text)
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
.font(Font.custom("AveriaSerifLibre-Regular", size: fontSize))
ForEach(RibbonMap(ribbons: allRibbons), id: \.self) { ribbon in
Print("quack3: \(ribbon)")
RibbonDebug(ribbonDebug: ribbon)
}
}
@ -76,18 +83,26 @@ func RibbonMap(ribbons: [Ribbon]) -> [[String]] {
var debugString = RibbonDebugPrint(ribbon:r)
retStrings.append(debugString)
}
return retStrings
let sortedStats = retStrings.sorted {
Int($0[0])! > Int($1[0])!
}
return sortedStats
}
func RibbonDebugPrint(ribbon: Ribbon) -> [String] {
var ribbonStats = [String]()
let undoPos = (ribbon.undoLevel - ribbon.minLevel) %% totalLevels
ribbonStats.append("\(undoPos)")
ribbonStats.append("id: \(ribbon.id) ")
ribbonStats.append("scrollOffset: \(ribbon.scrollOffset)")
ribbonStats.append("scrollId: \(ribbon.scrollId)")
ribbonStats.append("undoLevel: \(ribbon.undoLevel)")
ribbonStats.append("currentLevel: \(ribbon.currentLevel)")
ribbonStats.append("minLevel: \(ribbon.minLevel)")
ribbonStats.append("maxLevel: \(ribbon.maxLevel)")
// ribbonStats.append("undoLevel: \(ribbon.undoLevel)")
// ribbonStats.append("currentLevel: \(ribbon.currentLevel)")
// ribbonStats.append("minLevel: \(ribbon.minLevel)")
// ribbonStats.append("maxLevel: \(ribbon.maxLevel)")
return ribbonStats
}
@ -99,10 +114,7 @@ struct RibbonDebug: View {
VStack {
VStack {
// let ribbonStats = RibbonDebugPrint(ribbon: ribbon)
Print("quack2: \(ribbonDebug)")
ForEach(ribbonDebug, id: \.self) {
Print("quack2 : \($0)")
Text($0)
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
.font(Font.custom("AveriaSerifLibre-Regular", size: fontSize))

View File

@ -11,6 +11,7 @@
851259B22C05299200BE70F8 /* ForwardArrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259B12C05299200BE70F8 /* ForwardArrow.swift */; };
851259B62C07560800BE70F8 /* NaviBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259B52C07560800BE70F8 /* NaviBar.swift */; };
851259B82C0A145500BE70F8 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259B72C0A145500BE70F8 /* Stats.swift */; };
851259BA2C0F355D00BE70F8 /* BookmarkIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259B92C0F355D00BE70F8 /* BookmarkIcon.swift */; };
8514D5BC299EFB780054F185 /* store.db in Resources */ = {isa = PBXBuildFile; fileRef = 8514D5BB299EFB780054F185 /* store.db */; };
8514D5BF299F04710054F185 /* GRDB in Frameworks */ = {isa = PBXBuildFile; productRef = 8514D5BE299F04710054F185 /* GRDB */; };
852774C129A150B100458CA7 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852774C029A150B100458CA7 /* Line.swift */; };
@ -53,6 +54,7 @@
851259B12C05299200BE70F8 /* ForwardArrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForwardArrow.swift; sourceTree = "<group>"; };
851259B52C07560800BE70F8 /* NaviBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NaviBar.swift; sourceTree = "<group>"; };
851259B72C0A145500BE70F8 /* Stats.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stats.swift; sourceTree = "<group>"; };
851259B92C0F355D00BE70F8 /* BookmarkIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkIcon.swift; sourceTree = "<group>"; };
8514D5BB299EFB780054F185 /* store.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = store.db; sourceTree = "<group>"; };
852774C029A150B100458CA7 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
8528897429B2B86B003F2E16 /* CrownOfThorns.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrownOfThorns.swift; sourceTree = "<group>"; };
@ -116,6 +118,7 @@
85431A7C2905F4F500EE0760 = {
isa = PBXGroup;
children = (
851259B92C0F355D00BE70F8 /* BookmarkIcon.swift */,
851259B12C05299200BE70F8 /* ForwardArrow.swift */,
851259AF2C05281300BE70F8 /* BackButton.swift */,
857C34482BFB7DC800661A63 /* Fenestra.swift */,
@ -296,6 +299,7 @@
85431A922905F4F600EE0760 /* Persistence.swift in Sources */,
857C34492BFB7DC800661A63 /* Fenestra.swift in Sources */,
85942EEB29AD55A400307621 /* RibbonRequest.swift in Sources */,
851259BA2C0F355D00BE70F8 /* BookmarkIcon.swift in Sources */,
85431A8B2905F4F500EE0760 /* ContentView.swift in Sources */,
851259B02C05281300BE70F8 /* BackButton.swift in Sources */,
85942EF529B108C600307621 /* Seg.swift in Sources */,

View File

@ -79,7 +79,7 @@ struct AppDatabase {
}
// change this to nuke/remake the database
try db.create(table: "foo1") { t in
try db.create(table: "foo2") { t in
t.autoIncrementedPrimaryKey("id")
t.column("ribbonId", .integer).notNull()
}
@ -417,7 +417,7 @@ extension AppDatabase {
currentLevel: 0,
minLevel: 0,
maxLevel: 0,
title: "Gospel of Mark",
title: "Gospel of Mark and other dogmatic works",
book: "bible.mark",
scrollId: "1",
scrollOffset: 300).inserted(db)

View File

@ -16,9 +16,6 @@ let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "network
var currentId: String?
var currentOffset: CGFloat?
//var gTracker: VisibilityTracker<String>?
var printCount: Int64 = 0
var disableDrop = false
public extension UserDefaults {
@ -45,11 +42,9 @@ func createUndoState(selectedRibbon: Ribbon,
{
let updateThreshold = 30
print("meow updating ribbon")
var updatedRibbon = selectedRibbon
var scrollOffsetToSave = Int(floor(paneConnector.currentOffset))
var scrollIdToSave = paneConnector.currentId
print("meow scrolloffsets \(scrollIdToSave) \(scrollOffsetToSave)")
var offsetDiff = abs(scrollOffsetToSave - updatedRibbon.scrollOffset) > 30
@ -61,7 +56,6 @@ func createUndoState(selectedRibbon: Ribbon,
print("meow bumping")
let ret = try await appDatabase.bumpRibbon(&updatedRibbon)
print("meow finished bumping")
return ret
}
print("meow no bump")
@ -130,8 +124,9 @@ struct RibbonCrown: View {
var draggedRibbon: Ribbon?
var isDragging: Bool
var height = CGFloat(45)
var scale = 0.65
var height = CGFloat(41)
var width = CGFloat(70)
var scale = 0.70
@Environment(\.appDatabase) private var appDatabase
@ -152,8 +147,8 @@ struct RibbonCrown: View {
Text(ribbon.title)
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
.frame(minWidth: CGFloat(70),
maxWidth: CGFloat(70),
.frame(minWidth: width,
maxWidth: width,
minHeight: height,
maxHeight: height,
alignment: .center)
@ -189,6 +184,7 @@ struct RibbonCrown: View {
}
}
// object used for JSON decoding of verses
class Verse: NSObject, Codable {
var body: String
var verse: Int
@ -214,9 +210,6 @@ func makeVerseView(seg: SegDenorm) -> some View {
}
class PaneConnector: NSObject, ObservableObject {
// var scrollId: String
// var scrollOffset: CGFloat
// var setScrollOffset: CGFloat
var showOverlay: Bool = false
@Published var refresh: Bool = false
@Published var vertSep = CGFloat(20)
@ -225,7 +218,6 @@ class PaneConnector: NSObject, ObservableObject {
var visibilityTracker: VisibilityTracker<String>?
@Published var scrollId = ""
@Published var scrollOffset = CGFloat()
// @Published var hasMoved = false
@Published var hasMoved = false
var setScrollOffset: CGFloat?
@ -233,7 +225,7 @@ class PaneConnector: NSObject, ObservableObject {
struct ContentView: View {
// this is for the whole view swiping
@State var viewState = CGSize.zero
@State var mainSwipe = CGSize.zero
@State var pulledOut = CGSize.zero
@State var selection = 0
@ -273,6 +265,7 @@ struct ContentView: View {
ZStack(alignment: .top) {
VStack(alignment: .leading) {
VStack {
ForEach(ribbons) { ribbon in
RibbonCrown(ribbon: ribbon,
paneConnector: paneConnector,
@ -305,123 +298,133 @@ struct ContentView: View {
VStack {
NaviBar(paneConnector: paneConnector)
StatsPanel(paneConnector: paneConnector)
.offset(y:20)
}
.frame(maxWidth: 250)
.offset(x: geometry.size.width - 330)
// .frame(maxWidth: 300)
.offset(x: geometry.size.width - 300)
VStack {
// Top pane
// if viewState.width > -50 {
// dragOffset = viewState.width + pulledOut.width + 50
// }
Pane(paneConnector: paneConnector,
selectedRibbon: selectedRibbon,
width: geometry.size.width - 50,
height: geometry.size.height / 2,
width: geometry.size.width - 15,
height: geometry.size.height + 20,
dragOffset: dragOffset)
//////
Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
.gesture(
DragGesture()
.onChanged { gesture in
///////////////////////////////////
paneConnector.vertSep = paneConnector.vertSep - gesture.translation.height
Print(gesture.translation.width)
Print(gesture.translation.height)
// Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
// .gesture(
// DragGesture()
// .onChanged { gesture in
// paneConnector.vertSep = paneConnector.vertSep - gesture.translation.height
// }
// )
Print("drag")
}
)
// // Bottom pane
// ScrollViewReader { _ in
// VisibilityTrackingScrollView(action: handleVisibilityChanged2) {
// // ScrollView {
ScrollViewReader { _ in
VisibilityTrackingScrollView(action: handleVisibilityChanged2) {
// ScrollView {
LazyVStack {
ForEach(segs) { seg in
SegRow(seg: seg,
ribbonId: selectedRibbon[0].id!)
.id("\(seg.id)")
.padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20))
.trackVisibility(id: "\(seg.id)")
// .onChange(of: geometry.frame(in: .named("scrollView"))) { imageRect in
// Print(imageRect)
// Print(outerProxy)
// if isInView(innerRect: imageRect, isIn: outerProxy) {
// visibleIndex.insert(item)
// } else {
// visibleIndex.remove(item)
// LazyVStack {
// ForEach(segs) { seg in
// SegRow(seg: seg,
// ribbonId: selectedRibbon[0].id!)
// .id("\(seg.id)")
// .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20))
// .trackVisibility(id: "\(seg.id)")
// }
// }
}
}
.background(Color(red: 0.18, green: 0.18, blue: 0.18))
}
// .background(Color(red: 0.18, green: 0.18, blue: 0.18))
// }
.onAppear {
Print("APPEAR")
// .onAppear {
// Print("APPEAR")
// }
// .listStyle(PlainListStyle())
// }
// .zIndex(1)
// .background(Color(red: 0.2, green: 0.2, blue: 0.2))
///////////////////////////////////
}
.listStyle(PlainListStyle())
}
.zIndex(1)
.background(Color(red: 0.2, green: 0.2, blue: 0.2))
.frame(width: geometry.size.width - 50)
}
.offset(x: 30, y: 0)
.offset(x: 20, y: 0)
.offset(x: pulledOut.width)
.offset(x: viewState.width, y: viewState.height)
.offset(x: mainSwipe.width, y: mainSwipe.height)
.gesture(
DragGesture()
.onChanged { gesture in
let margin = CGFloat(50)
let dragThreshold = CGFloat(10)
let margin = CGFloat(30)
let rightSwipeLimit = CGFloat(110)
let leftSwipeLimit = CGFloat(-200)
print("mao viewState :\(viewState.width)")
print("mao mainSwipe :\(mainSwipe.width)")
print(pulledOut.width)
// threshold of how much to swipe before the view drags
if abs(gesture.translation.width) > dragThreshold {
viewState.width = gesture.translation.width
var swipeWidth = gesture.translation.width
var swipeActual = gesture.translation.width + pulledOut.width
if swipeWidth > 0 {
if swipeActual > rightSwipeLimit {
swipeWidth = rightSwipeLimit + pow(swipeActual - rightSwipeLimit, 0.8)
}
if viewState.width < -margin && pulledOut.width <= 0 {
dragOffset = margin + viewState.width + pulledOut.width
mainSwipe.width = swipeWidth - pulledOut.width
} else {
if swipeActual < leftSwipeLimit {
swipeWidth = leftSwipeLimit - pow(-swipeActual + leftSwipeLimit, 0.8)
}
mainSwipe.width = swipeWidth - pulledOut.width
}
if viewState.width > 0 && pulledOut.width != 0 {
dragOffset = margin + viewState.width + pulledOut.width
// dragOffset is what is used to make the text be readable
// with the right pane being visible
// if mainSwipe.width < -margin && pulledOut.width <= 0 {
if mainSwipe.width < -margin && pulledOut.width <= 0 {
dragOffset = margin + mainSwipe.width + pulledOut.width
}
if mainSwipe.width > 0 && pulledOut.width < 0 {
dragOffset = margin + mainSwipe.width + pulledOut.width
}
}
.onEnded { _ in
let pulledOutRight = CGFloat(-300)
let pulledOutLeft = CGFloat(200)
let margin = CGFloat(50)
let pulledOutRight = CGFloat(-200)
let pulledOutLeft = CGFloat(110)
let margin = CGFloat(30)
var setPulledOutWith = CGFloat(0)
var setDragOffset = CGFloat(0)
if viewState.width < 0 && pulledOut.width > 0 {
if mainSwipe.width < 0 && pulledOut.width > 0 {
setPulledOutWith = CGFloat(0)
} else if viewState.width > 0 && pulledOut.width < 0 {
} else if mainSwipe.width > 0 && pulledOut.width < 0 {
setPulledOutWith = CGFloat(0)
} else if viewState.width < 0 && pulledOut.width == 0 {
} else if (mainSwipe.width < 0 && pulledOut.width < 0) ||
(mainSwipe.width < 0 && pulledOut.width == 0) {
setPulledOutWith = pulledOutRight
setDragOffset = margin + setPulledOutWith
} else if abs(viewState.width + pulledOut.width) > 30 {
} else if abs(mainSwipe.width + pulledOut.width) > 30 {
setPulledOutWith = pulledOutLeft
}
withAnimation(.spring(response: 0.2)) {
pulledOut.width = setPulledOutWith
dragOffset = setDragOffset
viewState = .zero
mainSwipe = .zero
}
}
)
}
}
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
}
func handleVisibilityChanged2(_: String, change _: VisibilityChange, tracker _: VisibilityTracker<String>) {}
}