Skip to content

Commit 03f2c48

Browse files
[BindableViews] Fix DisplayScale.scaleWithHeight
Wasn't scaling when it should. Looked okay in most circumstances by luck. Also removed rounding. Just letting the objects receiving the values decide what to do with them. Should be more predictable.
1 parent 9033d87 commit 03f2c48

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

BindableView/Label.swift

+6-8
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,15 @@ enum DisplayScale: CGFloat, Comparable {
294294
}
295295
}
296296

297-
/// Returns the provided value scaled to the current display width relative to self. The result
298-
/// is always rounded in the direction of the scaling.
297+
/// Returns the provided value scaled to the current display width relative to self.
299298
/// - parameter value: The value to scale.
300299
func scale(_ value: CGFloat) -> CGFloat {
301300
guard self != .any else { return value }
302-
let scaled = value * (min(UIScreen.main.bounds.width, DisplayScale.maxScaling.rawValue) / rawValue)
303-
return scaled.rounded(scaled < value ? .down : .up)
301+
let scale = min(UIScreen.main.bounds.width, DisplayScale.maxScaling.rawValue) / rawValue
302+
return value * scale
304303
}
305304

306-
/// Returns the provided value scaled to the current display size relative to self. The result
307-
/// is always rounded in the direction of the scaling.
305+
/// Returns the provided value scaled to the current display size relative to self.
308306
///
309307
/// The display's width and height are considered, the latter of which relative to the maximum
310308
/// possible height for the width class. The smallest scale factor is used to scale the result.
@@ -313,8 +311,8 @@ enum DisplayScale: CGFloat, Comparable {
313311
guard self != .any else { return value }
314312
let widthScale = min(UIScreen.main.bounds.width, DisplayScale.maxScaling.rawValue) / rawValue
315313
let heightScale = min(UIScreen.main.bounds.height, DisplayScale.maxScaling.maxHeight) / maxHeight
316-
let scaled = value * min(widthScale, heightScale)
317-
return scaled.rounded(scaled < value ? .down : .up)
314+
let scale = abs(1 - widthScale) > abs(1 - heightScale) ? widthScale : heightScale
315+
return value * scale
318316
}
319317

320318
static func < (lhs: DisplayScale, rhs: DisplayScale) -> Bool {

0 commit comments

Comments
 (0)