From 1c45c26d219e6df49b96e56452326b05751eddb9 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 9 Sep 2020 10:55:23 -0700 Subject: [PATCH] negative frame fix (#23) --- .../SlidersExamples.xcodeproj/project.pbxproj | 20 +++++---- .../xcschemes/SlidersExamples iOS.xcscheme | 2 +- .../xcschemes/SlidersExamples macOS.xcscheme | 2 +- Package.swift | 4 +- Sources/Sliders/Base/LinearRangeMath.swift | 2 +- Sources/Sliders/Base/LinearValueMath.swift | 41 +------------------ 6 files changed, 19 insertions(+), 52 deletions(-) diff --git a/Examples/SlidersExamples.xcodeproj/project.pbxproj b/Examples/SlidersExamples.xcodeproj/project.pbxproj index df2d425..fa03623 100644 --- a/Examples/SlidersExamples.xcodeproj/project.pbxproj +++ b/Examples/SlidersExamples.xcodeproj/project.pbxproj @@ -213,7 +213,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1100; - LastUpgradeCheck = 1120; + LastUpgradeCheck = 1200; TargetAttributes = { FA61E9B2231365E3006A5B6B = { CreatedOnToolsVersion = 11.0; @@ -384,7 +384,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.15; + MACOSX_DEPLOYMENT_TARGET = 11.0; MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; @@ -456,7 +456,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.15; + MACOSX_DEPLOYMENT_TARGET = 11.0; MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; @@ -484,6 +484,7 @@ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -498,6 +499,8 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + MACOSX_DEPLOYMENT_TARGET = 11.0; ONLY_ACTIVE_ARCH = YES; }; name = Debug; @@ -517,6 +520,7 @@ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -530,6 +534,8 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + MACOSX_DEPLOYMENT_TARGET = 11.0; }; name = Release; }; @@ -592,7 +598,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "SlidersExamples iOS/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -608,7 +614,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,6"; }; name = Debug; }; @@ -665,7 +671,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "SlidersExamples iOS/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -680,7 +686,7 @@ SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,6"; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/Examples/SlidersExamples.xcodeproj/xcshareddata/xcschemes/SlidersExamples iOS.xcscheme b/Examples/SlidersExamples.xcodeproj/xcshareddata/xcschemes/SlidersExamples iOS.xcscheme index 1fdcd35..7acfa33 100644 --- a/Examples/SlidersExamples.xcodeproj/xcshareddata/xcschemes/SlidersExamples iOS.xcscheme +++ b/Examples/SlidersExamples.xcodeproj/xcshareddata/xcschemes/SlidersExamples iOS.xcscheme @@ -1,6 +1,6 @@ , bounds: ClosedRange = 0.0...1.0, lowerStartOffset: CGFloat = 0, lowerEndOffset: CGFloat = 0, upperStartOffset: CGFloat = 0, upperEndOffset: CGFloat = 0) -> CGFloat { let offsetLowerValue = distanceFrom(value: range.lowerBound, availableDistance: overallLength, bounds: bounds, leadingOffset: lowerStartOffset, trailingOffset: lowerEndOffset) let offsetUpperValue = distanceFrom(value: range.upperBound, availableDistance: overallLength, bounds: bounds, leadingOffset: upperStartOffset, trailingOffset: upperEndOffset) - return offsetUpperValue - offsetLowerValue + return max(0, offsetUpperValue - offsetLowerValue) } diff --git a/Sources/Sliders/Base/LinearValueMath.swift b/Sources/Sliders/Base/LinearValueMath.swift index 0ea8090..215877f 100644 --- a/Sources/Sliders/Base/LinearValueMath.swift +++ b/Sources/Sliders/Base/LinearValueMath.swift @@ -5,6 +5,7 @@ import SwiftUI /// Calculates distance from zero in points @inlinable func distanceFrom(value: CGFloat, availableDistance: CGFloat, bounds: ClosedRange = 0.0...1.0, leadingOffset: CGFloat = 0, trailingOffset: CGFloat = 0) -> CGFloat { + guard availableDistance > leadingOffset + trailingOffset else { return 0 } let boundsLenght = bounds.upperBound - bounds.lowerBound let relativeValue = (value - bounds.lowerBound) / boundsLenght let offset = (leadingOffset - ((leadingOffset + trailingOffset) * relativeValue)) @@ -20,43 +21,3 @@ import SwiftUI let validatedValue = min(bounds.upperBound, max(bounds.lowerBound, steppedNewValue)) return validatedValue } - - - - - - -//// Deprications - -/// Return a relative value for value in bounds -/// Example: For value 3.0 in bounds 2.0...4.0 returns 0.5 -@inlinable func relativeValueFrom(value: CGFloat, bounds: ClosedRange = 0.0...1.0) -> CGFloat { - let boundsLenght = bounds.upperBound - bounds.lowerBound - return (value - bounds.lowerBound) / boundsLenght -} - -/// Calculates relative position from 0.0 to 1.0 in given lenght where zero offset is in the center. -/// Example: For offset 0 in lenght 100 returns 0.5 -@inlinable func relativeValueFrom(overallLength: CGFloat, centerOffset: CGFloat) -> CGFloat { - (centerOffset + (overallLength / 2)) / overallLength -} - -/// Calculates value for relative point in bounds with step. -/// Example: For relative value 0.5 in range 2.0..4.0 produces 3.0 -@inlinable func valueFrom(relativeValue: CGFloat, bounds: ClosedRange = 0.0...1.0, step: CGFloat = 0.001) -> CGFloat { - let newValue = bounds.lowerBound + (relativeValue * (bounds.upperBound - bounds.lowerBound)) - let steppedNewValue = (round(newValue / step) * step) - let validatedValue = min(bounds.upperBound, max(bounds.lowerBound, steppedNewValue)) - return validatedValue -} - -/// Available length should pass width minus slider length. -@inlinable func offsetFromCenterToValue(overallLength: CGFloat, value: CGFloat, bounds: ClosedRange = 0.0...1.0, startOffset: CGFloat = 0, endOffset: CGFloat = 0) -> CGFloat { - let computedRelativeValue = relativeValueFrom(value: value, bounds: bounds) - let offset = (startOffset - ((startOffset + endOffset) * computedRelativeValue)) - return offset + (computedRelativeValue * overallLength) - (overallLength / 2) -} - -/// Range - -