-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from makinosp/develop
update: bump up to 0.7.0
- Loading branch information
Showing
14 changed files
with
255 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// BittenCircleMask.swift | ||
// Harmonie | ||
// | ||
// Created by xili on 2024/09/18. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct BittenCircleMask: Shape { | ||
private let biteSize: CGSize | ||
private let offsetRatio: CGFloat | ||
|
||
init(biteSize: CGSize, offsetRatio: CGFloat = 0.65) { | ||
self.biteSize = biteSize | ||
self.offsetRatio = offsetRatio | ||
} | ||
|
||
func path(in rect: CGRect) -> Path { | ||
var path = rectanglePath(rect) | ||
path.addPath(circlePath(rect)) | ||
return path | ||
} | ||
|
||
private func rectanglePath(_ rect: CGRect) -> Path { | ||
Rectangle().path(in: rect) | ||
} | ||
|
||
private func circlePath(_ rect: CGRect) -> Path { | ||
Circle() | ||
.path(in: circleRect(rect, size: biteSize)) | ||
} | ||
|
||
private func circleRect(_ rect: CGRect, size: CGSize) -> CGRect { | ||
CGRect(origin: .zero, size: size) | ||
.offsetBy(dx: offsetBy(rect.maxX), dy: offsetBy(rect.maxX)) | ||
} | ||
|
||
private func offsetBy(_ maxX: CGFloat) -> CGFloat { | ||
maxX * offsetRatio | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// BittenView.swift | ||
// Harmonie | ||
// | ||
// Created by xili on 2024/09/18. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct BittenView<Content>: View where Content: View { | ||
@State private var size: CGSize? | ||
private let content: Content | ||
private let ratio: CGFloat | ||
|
||
init(ratio: CGFloat = 0.4, @ViewBuilder content: () -> Content) { | ||
self.content = content() | ||
self.ratio = ratio | ||
} | ||
|
||
private var transformed: CGSize { | ||
guard let size = size else { return .zero } | ||
return CGSize(width: size.width * ratio, height: size.height * ratio) | ||
} | ||
|
||
var body: some View { | ||
content | ||
.mask( | ||
BittenCircleMask(biteSize: transformed) | ||
.fill(style: FillStyle(eoFill: true)) | ||
) | ||
.background { | ||
GeometryReader { geometry in | ||
Color.clear.onAppear { | ||
size = geometry.size | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
BittenView { | ||
Circle() | ||
.fill(.blue) | ||
.frame(width: 120, height: 120) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// StatusIndicator.swift | ||
// Harmonie | ||
// | ||
// Created by xili on 2024/09/19. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct StatusIndicator<S>: View where S: ShapeStyle { | ||
private let content: S | ||
private let isCutOut: Bool | ||
private let outerSize: CGSize | ||
|
||
init(_ content: S, outerSize: CGSize, isCutOut: Bool = false) { | ||
self.content = content | ||
self.outerSize = outerSize | ||
self.isCutOut = isCutOut | ||
} | ||
|
||
private var frameSize: CGSize { | ||
outerSize * 0.3 | ||
} | ||
|
||
private var cutoutSize: CGSize { | ||
outerSize * 0.15 | ||
} | ||
|
||
private var offset: CGSize { | ||
outerSize * 0.36 | ||
} | ||
|
||
var body: some View { | ||
Circle() | ||
.fill(content) | ||
.frame(size: frameSize) | ||
.overlay { | ||
Circle() | ||
.blendMode(.destinationOut) | ||
.frame(size: isCutOut ? cutoutSize : .zero) | ||
} | ||
.compositingGroup() | ||
.offset(x: offset.width, y: offset.height) | ||
} | ||
} | ||
|
||
#Preview { | ||
StatusIndicator( | ||
.blue, | ||
outerSize: CGSize(width: 120, height: 120) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// UserIcon.swift | ||
// Harmonie | ||
// | ||
// Created by makinosp on 2024/09/20. | ||
// | ||
|
||
import SwiftUI | ||
import VRCKit | ||
|
||
struct UserIcon: View { | ||
private let user: any ProfileElementRepresentable | ||
private let size: CGSize | ||
|
||
init(user: any ProfileElementRepresentable, size: CGSize) { | ||
self.user = user | ||
self.size = size | ||
} | ||
|
||
var body: some View { | ||
BittenView { | ||
CircleURLImage(imageUrl: user.imageUrl(.x256), size: size) | ||
} | ||
.overlay { | ||
StatusIndicator( | ||
user.status.color, | ||
outerSize: size, | ||
isCutOut: user.platform == .web | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// CGSize+Operator.swift | ||
// Harmonie | ||
// | ||
// Created by makinosp on 2024/09/20. | ||
// | ||
|
||
import CoreGraphics | ||
|
||
extension CGSize { | ||
static func * (lhs: CGSize, rhs: CGFloat) -> CGSize { | ||
CGSize(width: lhs.width * rhs, height: lhs.height * rhs) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.