Skip to content

Commit

Permalink
Merge pull request #4 from p-x9/feature/config-model
Browse files Browse the repository at this point in the history
add `TouchPointStyle`
  • Loading branch information
p-x9 authored Apr 14, 2023
2 parents 23a01e0 + 367e4cd commit 8c7c3e9
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 16 deletions.
16 changes: 8 additions & 8 deletions Sources/TouchTracker/Cocoa/TouchPointUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class TouchPointUIView: UIWindow {
}
var radius: CGFloat

var color: UIColor = .red
var color: UIColor

var isBordered: Bool = true
var borderColor: UIColor = .black
var borderWidth: CGFloat = 1
var isBordered: Bool
var borderColor: UIColor
var borderWidth: CGFloat

var isDropShadow: Bool = true
var shadowColor: UIColor = .black
var shadowRadius: CGFloat = 3
var isDropShadow: Bool
var shadowColor: UIColor
var shadowRadius: CGFloat

var image: UIImage?

var isShowLocation: Bool = false
var isShowLocation: Bool

lazy var imageView: UIImageView = {
let view = UIImageView()
Expand Down
15 changes: 15 additions & 0 deletions Sources/TouchTracker/Cocoa/TouchTrackingUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ public class TouchTrackingUIView: UIView {
UIWindow.hook()
}

@available(iOS 14.0, *)
public convenience init(style: TouchPointStyle) {
self.init(
radius: style.radius,
color: UIColor(style.color),
isBordered: style.isBordered,
borderColor: UIColor(style.borderColor),
borderWidth: style.borderWidth,
isDropShadow: style.isDropShadow,
shadowColor: UIColor(style.shadowColor),
shadowRadius: style.shadowRadius,
isShowLocation: style.isShowLocation
)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
55 changes: 55 additions & 0 deletions Sources/TouchTracker/Model/TouchPointStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// TouchPointStyle.swift
//
//
// Created by p-x9 on 2023/04/14.
//
//

import SwiftUI

public struct TouchPointStyle: Equatable {
/// radius of mark on touched point
public var radius: CGFloat
/// color of mark on touched point
public var color: Color

/// add a border to the mark of the touched point, or
public var isBordered: Bool
/// border color of mark on touched point
public var borderColor: Color
/// border width of mark on touched point
public var borderWidth: CGFloat

/// add shadow to the mark of the touched point, or
public var isDropShadow: Bool
/// shadow color of mark on touched point
public var shadowColor: Color
/// shadow radius of mark on touched point
public var shadowRadius: CGFloat

/// show coordinates label or not
public var isShowLocation: Bool

public init(
radius: CGFloat = 20,
color: Color = .red,
isBordered: Bool = false,
borderColor: Color = .black,
borderWidth: CGFloat = 1,
isDropShadow: Bool = true,
shadowColor: Color = .black,
shadowRadius: CGFloat = 3,
isShowLocation: Bool = false
) {
self.radius = radius
self.color = color
self.isBordered = isBordered
self.borderColor = borderColor
self.borderWidth = borderWidth
self.isDropShadow = isDropShadow
self.shadowColor = shadowColor
self.shadowRadius = shadowRadius
self.isShowLocation = isShowLocation
}
}
13 changes: 13 additions & 0 deletions Sources/TouchTracker/TouchTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ extension TouchTrackingView {
set(enabled, for: \.isShowLocation)
}

public func setTouchPointStyle(_ style: TouchPointStyle) -> Self {
self
.set(style.radius, for: \.radius)
.set(style.color, for: \.color)
.set(style.isBordered, for: \.isBordered)
.set(style.borderColor, for: \.borderColor)
.set(style.borderWidth, for: \.borderWidth)
.set(style.isDropShadow, for: \.isDropShadow)
.set(style.shadowColor, for: \.shadowColor)
.set(style.shadowRadius, for: \.shadowRadius)
.set(style.isShowLocation, for: \.isShowLocation)
}

private func set<T>(_ value: T, for keyPath: WritableKeyPath<TouchTrackingView, T>) -> Self {
var new = self
new[keyPath: keyPath] = value
Expand Down
16 changes: 8 additions & 8 deletions Sources/TouchTracker/TrackPointView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ struct TouchPointView: View {
let location: CGPoint
let radius: CGFloat

var color: Color = .red
var color: Color

var isBordered: Bool = true
var borderColor: Color = .black
var borderWidth: CGFloat = 1
var isBordered: Bool
var borderColor: Color
var borderWidth: CGFloat

var isDropShadow: Bool = true
var shadowColor: Color = .black
var shadowRadius: CGFloat = 3
var isDropShadow: Bool
var shadowColor: Color
var shadowRadius: CGFloat

var image: Image?

var isShowLocation: Bool = false
var isShowLocation: Bool

var locationText: some View {
let x = String(format: "%.1f", location.x)
Expand Down

0 comments on commit 8c7c3e9

Please sign in to comment.