diff --git a/BackButton.swift b/BackButton.swift new file mode 100644 index 0000000..0c99999 --- /dev/null +++ b/BackButton.swift @@ -0,0 +1,55 @@ +// +// BackButton.swift +// gloss +// +// Created by Saint on 5/27/24. +// + +import Foundation +import SwiftUI +struct BackArrow: 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.83333*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.83333*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.25*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.25*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.16667*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.16667*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.25*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.25*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.83333*width, y: 0.45833*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.41667*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.29167*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.41667*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.20833*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.20833*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.29167*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.41667*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.33333*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.70833*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.41667*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.79167*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.79167*height)) + path.addLine(to: CGPoint(x: 0.41667*width, y: 0.70833*height)) + path.closeSubpath() + return path + } +} diff --git a/ForwardArrow.swift b/ForwardArrow.swift new file mode 100644 index 0000000..250b494 --- /dev/null +++ b/ForwardArrow.swift @@ -0,0 +1,56 @@ +// +// ForwardArrow.swift +// gloss +// +// Created by Saint on 5/27/24. +// + +import Foundation +import SwiftUI + +struct ForwardArrow: 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.16667*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.16667*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.75*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.75*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.83333*width, y: 0.54167*height)) + path.addLine(to: CGPoint(x: 0.83333*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.75*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.75*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.45833*height)) + path.addLine(to: CGPoint(x: 0.16667*width, y: 0.45833*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.58333*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.375*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.29167*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.58333*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.29167*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.20833*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.20833*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.29167*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.58333*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.66667*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.625*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.70833*height)) + path.closeSubpath() + path.move(to: CGPoint(x: 0.58333*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.70833*height)) + path.addLine(to: CGPoint(x: 0.5*width, y: 0.79167*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.79167*height)) + path.addLine(to: CGPoint(x: 0.58333*width, y: 0.70833*height)) + path.closeSubpath() + return path + } +} diff --git a/gloss.xcodeproj/project.pbxproj b/gloss.xcodeproj/project.pbxproj index a76ccad..fd3256a 100644 --- a/gloss.xcodeproj/project.pbxproj +++ b/gloss.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 851259B02C05281300BE70F8 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259AF2C05281300BE70F8 /* BackButton.swift */; }; + 851259B22C05299200BE70F8 /* ForwardArrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259B12C05299200BE70F8 /* ForwardArrow.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 */; }; @@ -45,6 +47,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 851259AF2C05281300BE70F8 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = ""; }; + 851259B12C05299200BE70F8 /* ForwardArrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForwardArrow.swift; sourceTree = ""; }; 8514D5BB299EFB780054F185 /* store.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = store.db; sourceTree = ""; }; 852774C029A150B100458CA7 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = ""; }; 8528897429B2B86B003F2E16 /* CrownOfThorns.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrownOfThorns.swift; sourceTree = ""; }; @@ -108,6 +112,8 @@ 85431A7C2905F4F500EE0760 = { isa = PBXGroup; children = ( + 851259B12C05299200BE70F8 /* ForwardArrow.swift */, + 851259AF2C05281300BE70F8 /* BackButton.swift */, 857C34482BFB7DC800661A63 /* Fenestra.swift */, 8594ED972BF6845F001213F2 /* HexColor.swift */, 85E00E7B29F34D2D00FF9E78 /* ScrollState.swift */, @@ -285,6 +291,7 @@ 857C34492BFB7DC800661A63 /* Fenestra.swift in Sources */, 85942EEB29AD55A400307621 /* RibbonRequest.swift in Sources */, 85431A8B2905F4F500EE0760 /* ContentView.swift in Sources */, + 851259B02C05281300BE70F8 /* BackButton.swift in Sources */, 85942EF529B108C600307621 /* Seg.swift in Sources */, 85E00E7C29F34D2D00FF9E78 /* ScrollState.swift in Sources */, 8594ED982BF6845F001213F2 /* HexColor.swift in Sources */, @@ -301,6 +308,7 @@ 8528897C29BD69B2003F2E16 /* VisibilityTrackingScrollView.swift in Sources */, 85942EF929B1150B00307621 /* SegDenorm.swift in Sources */, 85431A9C2905F5D800EE0760 /* SwiftUIView.swift in Sources */, + 851259B22C05299200BE70F8 /* ForwardArrow.swift in Sources */, 8528897E29BD69B2003F2E16 /* VisibilityTracker.swift in Sources */, 85942EF729B108EA00307621 /* SegDenormRequest.swift in Sources */, 8528897D29BD69B2003F2E16 /* VisibilityTrackingModifier.swift in Sources */, diff --git a/gloss/ContentView.swift b/gloss/ContentView.swift index fbe6a4f..f9c5d59 100644 --- a/gloss/ContentView.swift +++ b/gloss/ContentView.swift @@ -205,14 +205,13 @@ struct ContentView: View { @State var viewState = CGSize.zero @State var pulledOut = CGSize.zero + @State var selection = 0 + @StateObject var paneConnector = PaneConnector() @State var refresh: Bool = false - @State var endedDrag = true - @State var readOffset = CGPoint() - @State var dragOffset = CGFloat() @Query(SegDenormRequest(book: "bible.john")) private var segs: [SegDenorm] @@ -269,6 +268,54 @@ struct ContentView: View { .background(Color(red: 0.1, green: 0.1, blue: 0.1)) .frame(alignment: .topLeading) + VStack { + HStack { + BackArrow() + .frame(width: CGFloat(30), height: CGFloat(30)) + .scaledToFit() + .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) + .tag(0) + + ForwardArrow() + .frame(width: CGFloat(30), height: CGFloat(30)) + .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) + .tag(1) + + Text("cat") + .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) + .tag(2) + } + .cornerRadius(15) + + HStack { + BackArrow() + .frame(width: CGFloat(30), height: CGFloat(30)) + .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) + .if(selection == 0) { $0.background(Color.white) } + .if(selection != 0) { $0.background(Color.black) } + .onTapGesture { + withAnimation(.spring(response: 0.2)) { + self.selection = 0 + } + } + + ForwardArrow() + .frame(width: CGFloat(30), height: CGFloat(30)) + .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) + .if(selection == 1) { $0.background(Color.white) } + .if(selection != 1) { $0.background(Color.black) } + .onTapGesture { + withAnimation(.spring(response: 0.2)) { + self.selection = 1 + } + } + } + + .background(Color.black) + .cornerRadius(5) + } + .offset(x: geometry.size.width - 300) + VStack { // Top pane Pane(paneConnector: paneConnector, @@ -332,33 +379,30 @@ struct ContentView: View { DragGesture() .onChanged { gesture in - if endedDrag { - endedDrag = false - - //TODO: should this still be adjusted - //scrollOffset = readOffset.y - 20 - } - Print(viewState.width) - if abs(gesture.translation.width) > 20 { + print(viewState.width) + print(pulledOut.width) + // threshold of how much to swipe before the view drags + if abs(gesture.translation.width) > 10 { viewState.width = gesture.translation.width - if gesture.translation.width < -50, pulledOut.width == CGFloat(0) { - dragOffset = gesture.translation.width + 50 - } + // if gesture.translation.width < -50, pulledOut.width == CGFloat(0) { + // } } } .onEnded { _ in - endedDrag = true - var pulledOutWidth = CGFloat(0) - if viewState.width < 0 { - pulledOutWidth = CGFloat(0) + var setPulledOutWith = CGFloat(0) + if viewState.width < 0 && pulledOut.width > 0 { + setPulledOutWith = CGFloat(0) + } else if viewState.width > 0 && pulledOut.width < 0 { + setPulledOutWith = CGFloat(0) + } else if viewState.width < 0 && pulledOut.width == 0 { + setPulledOutWith = CGFloat(-200) } else if abs(viewState.width + pulledOut.width) > 30 { - pulledOutWidth = CGFloat(200) + setPulledOutWith = CGFloat(200) } withAnimation(.spring(response: 0.2)) { - pulledOut.width = pulledOutWidth + pulledOut.width = setPulledOutWith viewState = .zero - dragOffset = .zero } } )