From 49bae9c706a8572abcbd0ca709e6b3298c23579b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Jun 2023 15:28:13 -0500 Subject: [PATCH] added dynamic lineHeight Signed-off-by: Matt Bruce --- .../BadgeIndicator/BadgeIndicator.swift | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/VDS/Components/BadgeIndicator/BadgeIndicator.swift b/VDS/Components/BadgeIndicator/BadgeIndicator.swift index 6fa6d212..4554f11f 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -59,25 +59,40 @@ open class BadgeIndicator: View { case medium = "Medium" case small = "Small" - public var padding: CGFloat { + public var inset: CGFloat { + return textStyle.pointSize * 0.3333 +// switch self { +// case .xxlarge: +// return 8 +// case .xlarge: +// return 6 +// case .large: +// return 6 +// case .medium: +// return 6 +// case .small: +// return 4 +// } + } + + public var lineHeight: CGFloat { switch self { case .xxlarge: - return 8 + return 29 case .xlarge: - return 6 + return 24 case .large: - return 6 + return 20 case .medium: - return 6 + return 18 case .small: - return 4 + return 16 } } public var textStyle: TextStyle { let style = TextStyle.bodySmall var pointSize: CGFloat = VDSTypography.fontSizeBody12 - switch self { case .xxlarge: pointSize = VDSTypography.fontSizeTitle24 @@ -95,11 +110,21 @@ open class BadgeIndicator: View { pointSize = VDSTypography.fontSizeBody12 } +// var ratio: CGFloat = 1.3333 // less than 14 +// if pointSize > 13 && pointSize < 16 { +// ratio = 1.28 +// } else if pointSize > 15 && pointSize < 19 { +// ratio = 1.25 +// } else if pointSize > 19 { +// ratio = 1.20 +// } + let calculatedLineHeight = pointSize * 1.265//ratio + print("lineHeight\noriginal: \(lineHeight)\ncalculated:\(calculatedLineHeight)") return TextStyle(rawValue: "\(self.rawValue)BadgeIndicator", fontFace: style.fontFace, pointSize: pointSize, - lineHeight: pointSize * (16.0 / 12.0), + lineHeight: calculatedLineHeight, letterSpacing: style.letterSpacing) } @@ -242,7 +267,7 @@ open class BadgeIndicator: View { backgroundColor = backgroundColorConfiguration.getColor(self) label.useAttributedText = true - label.edgeInset = .init(top: 0, left: textSize.padding, bottom: 0, right: textSize.padding) + label.edgeInset = .init(top: 0, left: textSize.inset, bottom: 0, right: textSize.inset) label.font = textSize.textStyle.font label.textColor = textColorConfiguration.getColor(self) label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()