Skip to content

Commit

Permalink
negative frame fix (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
ay42 committed Sep 9, 2020
1 parent 1c94552 commit 1c45c26
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 52 deletions.
20 changes: 13 additions & 7 deletions Examples/SlidersExamples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 1120;
LastUpgradeCheck = 1200;
TargetAttributes = {
FA61E9B2231365E3006A5B6B = {
CreatedOnToolsVersion = 11.0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
};
Expand Down Expand Up @@ -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",
Expand All @@ -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;
};
Expand Down Expand Up @@ -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",
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1120"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1120"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.2
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Sliders",
platforms: [
.iOS(.v13), .macOS(.v10_15)
.iOS(.v14), .macOS(.v11)
],
products: [
.library(name: "Sliders", targets: ["Sliders"])
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sliders/Base/LinearRangeMath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import SwiftUI
@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 {
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)
}
41 changes: 1 addition & 40 deletions Sources/Sliders/Base/LinearValueMath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SwiftUI

/// Calculates distance from zero in points
@inlinable func distanceFrom(value: CGFloat, availableDistance: CGFloat, bounds: ClosedRange<CGFloat> = 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))
Expand All @@ -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<CGFloat> = 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<CGFloat> = 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<CGFloat> = 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


0 comments on commit 1c45c26

Please sign in to comment.