Skip to content

Commit 1c45c26

Browse files
authored
negative frame fix (#23)
1 parent 1c94552 commit 1c45c26

File tree

6 files changed

+19
-52
lines changed

6 files changed

+19
-52
lines changed

Examples/SlidersExamples.xcodeproj/project.pbxproj

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
isa = PBXProject;
214214
attributes = {
215215
LastSwiftUpdateCheck = 1100;
216-
LastUpgradeCheck = 1120;
216+
LastUpgradeCheck = 1200;
217217
TargetAttributes = {
218218
FA61E9B2231365E3006A5B6B = {
219219
CreatedOnToolsVersion = 11.0;
@@ -384,7 +384,7 @@
384384
"$(inherited)",
385385
"@executable_path/../Frameworks",
386386
);
387-
MACOSX_DEPLOYMENT_TARGET = 10.15;
387+
MACOSX_DEPLOYMENT_TARGET = 11.0;
388388
MARKETING_VERSION = 1.0.0;
389389
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
390390
MTL_FAST_MATH = YES;
@@ -456,7 +456,7 @@
456456
"$(inherited)",
457457
"@executable_path/../Frameworks",
458458
);
459-
MACOSX_DEPLOYMENT_TARGET = 10.15;
459+
MACOSX_DEPLOYMENT_TARGET = 11.0;
460460
MARKETING_VERSION = 1.0.0;
461461
MTL_ENABLE_DEBUG_INFO = NO;
462462
MTL_FAST_MATH = YES;
@@ -484,6 +484,7 @@
484484
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
485485
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
486486
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
487+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
487488
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
488489
CLANG_WARN_STRICT_PROTOTYPES = YES;
489490
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -498,6 +499,8 @@
498499
GCC_WARN_UNINITIALIZED_AUTOS = YES;
499500
GCC_WARN_UNUSED_FUNCTION = YES;
500501
GCC_WARN_UNUSED_VARIABLE = YES;
502+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
503+
MACOSX_DEPLOYMENT_TARGET = 11.0;
501504
ONLY_ACTIVE_ARCH = YES;
502505
};
503506
name = Debug;
@@ -517,6 +520,7 @@
517520
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
518521
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
519522
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
523+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
520524
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
521525
CLANG_WARN_STRICT_PROTOTYPES = YES;
522526
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -530,6 +534,8 @@
530534
GCC_WARN_UNINITIALIZED_AUTOS = YES;
531535
GCC_WARN_UNUSED_FUNCTION = YES;
532536
GCC_WARN_UNUSED_VARIABLE = YES;
537+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
538+
MACOSX_DEPLOYMENT_TARGET = 11.0;
533539
};
534540
name = Release;
535541
};
@@ -592,7 +598,7 @@
592598
GCC_WARN_UNUSED_FUNCTION = YES;
593599
GCC_WARN_UNUSED_VARIABLE = YES;
594600
INFOPLIST_FILE = "SlidersExamples iOS/Info.plist";
595-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
601+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
596602
LD_RUNPATH_SEARCH_PATHS = (
597603
"$(inherited)",
598604
"@executable_path/Frameworks",
@@ -608,7 +614,7 @@
608614
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
609615
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
610616
SWIFT_VERSION = 5.0;
611-
TARGETED_DEVICE_FAMILY = "1,2";
617+
TARGETED_DEVICE_FAMILY = "1,2,6";
612618
};
613619
name = Debug;
614620
};
@@ -665,7 +671,7 @@
665671
GCC_WARN_UNUSED_FUNCTION = YES;
666672
GCC_WARN_UNUSED_VARIABLE = YES;
667673
INFOPLIST_FILE = "SlidersExamples iOS/Info.plist";
668-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
674+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
669675
LD_RUNPATH_SEARCH_PATHS = (
670676
"$(inherited)",
671677
"@executable_path/Frameworks",
@@ -680,7 +686,7 @@
680686
SWIFT_COMPILATION_MODE = wholemodule;
681687
SWIFT_OPTIMIZATION_LEVEL = "-O";
682688
SWIFT_VERSION = 5.0;
683-
TARGETED_DEVICE_FAMILY = "1,2";
689+
TARGETED_DEVICE_FAMILY = "1,2,6";
684690
VALIDATE_PRODUCT = YES;
685691
};
686692
name = Release;

Examples/SlidersExamples.xcodeproj/xcshareddata/xcschemes/SlidersExamples iOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1120"
3+
LastUpgradeVersion = "1200"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Examples/SlidersExamples.xcodeproj/xcshareddata/xcschemes/SlidersExamples macOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1120"
3+
LastUpgradeVersion = "1200"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// swift-tools-version:5.2
1+
// swift-tools-version:5.3
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "Sliders",
88
platforms: [
9-
.iOS(.v13), .macOS(.v10_15)
9+
.iOS(.v14), .macOS(.v11)
1010
],
1111
products: [
1212
.library(name: "Sliders", targets: ["Sliders"])

Sources/Sliders/Base/LinearRangeMath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import SwiftUI
55
@inlinable func rangeDistance(overallLength: CGFloat, range: ClosedRange<CGFloat>, bounds: ClosedRange<CGFloat> = 0.0...1.0, lowerStartOffset: CGFloat = 0, lowerEndOffset: CGFloat = 0, upperStartOffset: CGFloat = 0, upperEndOffset: CGFloat = 0) -> CGFloat {
66
let offsetLowerValue = distanceFrom(value: range.lowerBound, availableDistance: overallLength, bounds: bounds, leadingOffset: lowerStartOffset, trailingOffset: lowerEndOffset)
77
let offsetUpperValue = distanceFrom(value: range.upperBound, availableDistance: overallLength, bounds: bounds, leadingOffset: upperStartOffset, trailingOffset: upperEndOffset)
8-
return offsetUpperValue - offsetLowerValue
8+
return max(0, offsetUpperValue - offsetLowerValue)
99
}

Sources/Sliders/Base/LinearValueMath.swift

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import SwiftUI
55

66
/// Calculates distance from zero in points
77
@inlinable func distanceFrom(value: CGFloat, availableDistance: CGFloat, bounds: ClosedRange<CGFloat> = 0.0...1.0, leadingOffset: CGFloat = 0, trailingOffset: CGFloat = 0) -> CGFloat {
8+
guard availableDistance > leadingOffset + trailingOffset else { return 0 }
89
let boundsLenght = bounds.upperBound - bounds.lowerBound
910
let relativeValue = (value - bounds.lowerBound) / boundsLenght
1011
let offset = (leadingOffset - ((leadingOffset + trailingOffset) * relativeValue))
@@ -20,43 +21,3 @@ import SwiftUI
2021
let validatedValue = min(bounds.upperBound, max(bounds.lowerBound, steppedNewValue))
2122
return validatedValue
2223
}
23-
24-
25-
26-
27-
28-
29-
//// Deprications
30-
31-
/// Return a relative value for value in bounds
32-
/// Example: For value 3.0 in bounds 2.0...4.0 returns 0.5
33-
@inlinable func relativeValueFrom(value: CGFloat, bounds: ClosedRange<CGFloat> = 0.0...1.0) -> CGFloat {
34-
let boundsLenght = bounds.upperBound - bounds.lowerBound
35-
return (value - bounds.lowerBound) / boundsLenght
36-
}
37-
38-
/// Calculates relative position from 0.0 to 1.0 in given lenght where zero offset is in the center.
39-
/// Example: For offset 0 in lenght 100 returns 0.5
40-
@inlinable func relativeValueFrom(overallLength: CGFloat, centerOffset: CGFloat) -> CGFloat {
41-
(centerOffset + (overallLength / 2)) / overallLength
42-
}
43-
44-
/// Calculates value for relative point in bounds with step.
45-
/// Example: For relative value 0.5 in range 2.0..4.0 produces 3.0
46-
@inlinable func valueFrom(relativeValue: CGFloat, bounds: ClosedRange<CGFloat> = 0.0...1.0, step: CGFloat = 0.001) -> CGFloat {
47-
let newValue = bounds.lowerBound + (relativeValue * (bounds.upperBound - bounds.lowerBound))
48-
let steppedNewValue = (round(newValue / step) * step)
49-
let validatedValue = min(bounds.upperBound, max(bounds.lowerBound, steppedNewValue))
50-
return validatedValue
51-
}
52-
53-
/// Available length should pass width minus slider length.
54-
@inlinable func offsetFromCenterToValue(overallLength: CGFloat, value: CGFloat, bounds: ClosedRange<CGFloat> = 0.0...1.0, startOffset: CGFloat = 0, endOffset: CGFloat = 0) -> CGFloat {
55-
let computedRelativeValue = relativeValueFrom(value: value, bounds: bounds)
56-
let offset = (startOffset - ((startOffset + endOffset) * computedRelativeValue))
57-
return offset + (computedRelativeValue * overallLength) - (overallLength / 2)
58-
}
59-
60-
/// Range
61-
62-

0 commit comments

Comments
 (0)