Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#46] 드롭 피드백 만들기 #48

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TeamLongHair/TeamLongHair/Model/LinkModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class Link {
@Attribute(.unique) var id: UUID
@Relationship(deleteRule: .cascade) var detail: LinkDetail // Link 객체 삭제하면, 가지고 있던 디테일 객체도 같이 삭제.
@Relationship(deleteRule: .cascade) var subLinks: [Link] // link 객체 삭제하면, 가지고 있던 서브링크 객체도 같이 삭제.
@Attribute(.ephemeral)var isLinkTargeted: Bool = false

init(detail: LinkDetail) {
self.id = UUID()
Expand Down
26 changes: 21 additions & 5 deletions TeamLongHair/TeamLongHair/Project/Page/Canvas/CanvasView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ struct CanvasView: View {
// 왜냐하면 하위 링크가 늘어났을 때 선이 끝까지 안 그려지는 버그가 있었어서
if let last = selectedPage.links.last {
if last.id != $link.id {
VStack(spacing: 0) {
ZStack {
Spacer()
.frame(height: 118 * (sizeOfNode / 244) * 0.5)
.frame(height: 118 * (sizeOfNode / 244))
Rectangle()
.frame(minWidth: 244 * 2 * (sizeOfNode / 244), maxWidth: .infinity, maxHeight: 1)
.foregroundStyle(.gray700)
Expand All @@ -59,6 +59,8 @@ struct CanvasView: View {
$link.subLinks.wrappedValue.append(draggedLink)
}
return true
} isTargeted: { isTargeted in
link.isLinkTargeted = isTargeted
}
} else {
LinkNode(sizeOfNode: $sizeOfNode, link: $link, isSelected: false)
Expand All @@ -72,20 +74,31 @@ struct CanvasView: View {
$link.subLinks.wrappedValue.append(draggedLink)
}
return true
} isTargeted: { isTargeted in
link.isLinkTargeted = isTargeted
}
}
// 수직으로 반복해서 그려주기
if !$link.subLinks.wrappedValue.isEmpty {
DrawNodes(sizeOfNode: $sizeOfNode, selectedPage: $selectedPage, links: $link.subLinks, selectedLink: $selectedLink)
}

if link.isLinkTargeted {
RoundedRectangle(cornerRadius: 8 * (sizeOfNode / 244))
.stroke(style: StrokeStyle(dash: [8 * (sizeOfNode / 244)]))
.frame(width: sizeOfNode, height: 118 * (sizeOfNode / 244))
.foregroundStyle(.purple500)
.padding(.top, 60 * (sizeOfNode / 244))
.padding(.leading, (122 + 32) * (sizeOfNode / 244))
}
}
}
}
}
}
// 창을 늘려도 그래프가 유지됐으면 좋겠어서 고정
.fixedSize()
.padding(150)
.padding(300)
}
.background(.canvas)
// 이거 하면 뷰가 그려지지 않은 빈 공간에서도 제스처를 인식한대요
Expand All @@ -98,7 +111,7 @@ struct CanvasView: View {
self.lastScaleValue = value.magnification
let newScale = self.sizeOfNode * delta

if newScale < 540 && newScale > 90 {
if newScale < 400 && newScale > 180 {
self.sizeOfNode = newScale
}
}
Expand All @@ -110,9 +123,12 @@ struct CanvasView: View {
.overlay(alignment: .bottomTrailing) {
HStack {
Text(Image(systemName: "plus.magnifyingglass"))
Text("\(sizeOfNode * (1 / 180) * 100)%")
Text("\(sizeOfNode * (1 / 200) * 100)%")
}
}
.onAppear {
sizeOfNode = 200
}
}

func moveLink(links: inout [Link], id: String) {
Expand Down
19 changes: 16 additions & 3 deletions TeamLongHair/TeamLongHair/Project/Page/Canvas/DrawNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ struct DrawNodes: View {
var body: some View {
ForEach(Array(zip(links.indices, $links)), id: \.0) { index, $link in
HStack(alignment: .top, spacing: 0) {
ZStack {
VStack {
Spacer()
.frame(width: (122 + 32) * (sizeOfNode / 244), height: (118 + 120) * (sizeOfNode / 244))
.frame(width: (122 + 32) * (sizeOfNode / 244), height: (59 + 60) * (sizeOfNode / 244))
HStack {
Spacer()
.frame(width: 244 * (sizeOfNode / 244) / 2)
.frame(width: 244 * (sizeOfNode / 244) / 2, height: 0)
Rectangle()
.frame(width: 32 * (sizeOfNode / 244), height: 1)
.foregroundStyle(.gray700)
Expand All @@ -50,6 +50,8 @@ struct DrawNodes: View {
$link.subLinks.wrappedValue.append(draggedLink)
}
return true
} isTargeted: { isTargeted in
link.isLinkTargeted = isTargeted
}
.padding(.top, 60 * (sizeOfNode / 244))
.padding(.trailing, 20 * (sizeOfNode / 244))
Expand All @@ -66,6 +68,8 @@ struct DrawNodes: View {
$link.subLinks.wrappedValue.append(draggedLink)
}
return true
} isTargeted: { isTargeted in
link.isLinkTargeted = isTargeted
}
.padding(.top, 60 * (sizeOfNode / 244))
.padding(.trailing, 20 * (sizeOfNode / 244))
Expand All @@ -74,6 +78,15 @@ struct DrawNodes: View {
if !$link.subLinks.wrappedValue.isEmpty {
DrawNodes(sizeOfNode: $sizeOfNode, selectedPage: $selectedPage, links: $link.subLinks, selectedLink: $selectedLink)
}

if link.isLinkTargeted {
RoundedRectangle(cornerRadius: 8 * (sizeOfNode / 244))
.stroke(style: StrokeStyle(dash: [8 * (sizeOfNode / 244)]))
.frame(width: sizeOfNode, height: 118 * (sizeOfNode / 244))
.foregroundStyle(.purple500)
.padding(.top, 60 * (sizeOfNode / 244))
.padding(.leading, (122 + 32) * (sizeOfNode / 244))
}
}
}
.overlay(alignment: .leading) {
Expand Down