refactored label and textfields
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
7664b1e05a
commit
5c3e6b0ea5
@ -38,7 +38,7 @@ public class TextField: UITextField {
|
||||
public func setup() {
|
||||
keyboardType = .alphabet
|
||||
returnKeyType = .done
|
||||
|
||||
autocorrectionType = .no
|
||||
resigner = publisher(for: .editingDidEndOnExit)
|
||||
.sink { [weak self] _ in
|
||||
self?.shouldResign()
|
||||
@ -79,19 +79,7 @@ public class NumericField: TextField {
|
||||
|
||||
public override func setup() {
|
||||
super.setup()
|
||||
let keypadToolbar: UIToolbar = UIToolbar().with { $0.tintColor = .white; $0.backgroundColor = .white }
|
||||
|
||||
// add a done button to the numberpad
|
||||
keypadToolbar.items=[
|
||||
UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: self, action: nil),
|
||||
UIBarButtonItem(title: " - (minus sign)", style: .done, target: self, action: #selector(insertMinus)).with { $0.tintColor = .black},
|
||||
UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: self, action: #selector(shouldResign)).with { $0.tintColor = .black}
|
||||
]
|
||||
keypadToolbar.sizeToFit()
|
||||
|
||||
// add a toolbar with a done button above the number pad
|
||||
inputAccessoryView = keypadToolbar
|
||||
keyboardType = .decimalPad
|
||||
keyboardType = .numbersAndPunctuation
|
||||
}
|
||||
|
||||
@objc public func insertMinus() {
|
||||
|
||||
@ -31,6 +31,8 @@ class LabelViewController: BaseViewController<Label> {
|
||||
//testing only remove later
|
||||
//------------------------------------
|
||||
var useMinimumLineHeight = Toggle().with { $0.isOn = NSMutableAttributedString.useMinimumLineHeight }
|
||||
var useScaledLineHeight = Toggle().with { $0.isOn = NSMutableAttributedString.useScaledLineHeight }
|
||||
|
||||
var pointSizeRange = Slider().with {
|
||||
$0.minimumValue = 5
|
||||
$0.value = 0
|
||||
@ -49,35 +51,66 @@ class LabelViewController: BaseViewController<Label> {
|
||||
}
|
||||
//------------------------------------
|
||||
var scaledMode: Bool { component.useScaledFont && TextStyle.canScaleFonts }
|
||||
var baseStyle: TextStyle!
|
||||
var baseStyle: TextStyle! {
|
||||
didSet {
|
||||
baseStyleLabel.text = descriptionFor(style: baseStyle)
|
||||
}
|
||||
}
|
||||
|
||||
func descriptionFor(style: TextStyle) -> String {
|
||||
var scaledFont = style.font.scaledFont
|
||||
var customizedDesc: String = "Name: \(style.rawValue) \nFont Face-Weight: \(style.font.fontName)"
|
||||
customizedDesc += "\nVDS LetterSpacing: \(style.letterSpacing)"
|
||||
if scaledMode {
|
||||
customizedDesc += "\nVDS PointSize: \(style.pointSize.rounded())"
|
||||
customizedDesc += "\n* iOS PointSize: \(scaledFont.pointSize.rounded())"
|
||||
} else {
|
||||
customizedDesc += "\n* VDS PointSize: \(style.pointSize.rounded())"
|
||||
}
|
||||
if scaledMode {
|
||||
if useScaledLineHeight.isOn {
|
||||
customizedDesc += "\nVDS LineHeight: \(style.lineHeight)"
|
||||
customizedDesc += "\n* VDS Ratio LineHeight: \(style.scaledLineHeight)"
|
||||
} else {
|
||||
customizedDesc += "\n* VDS LineHeight: \(style.lineHeight)"
|
||||
}
|
||||
customizedDesc += "\niOS LineHeight: \(scaledFont.lineHeight.rounded())"
|
||||
} else {
|
||||
customizedDesc += "\n* VDS LineHeight: \(style.lineHeight)"
|
||||
customizedDesc += "\niOS LineHeight: \(style.font.lineHeight.rounded())"
|
||||
}
|
||||
return customizedDesc
|
||||
}
|
||||
|
||||
var currentStyle: TextStyle! {
|
||||
didSet {
|
||||
//--------------------------------------------------------------
|
||||
#warning("testing only remove later")
|
||||
//--------------------------------------------------------------
|
||||
let lineheight = scaledMode ? currentStyle.scaledLineHeight : currentStyle.lineHeight
|
||||
let lineheightText = scaledMode ? "\(baseStyle.lineHeight.rounded()) sc\(currentStyle.scaledLineHeight)" : "\(baseStyle.lineHeight.rounded())"
|
||||
|
||||
pointSizeRange.value = Float(currentStyle.pointSize)
|
||||
pointSizeRange.value = Float(currentStyle.pointSize.rounded())
|
||||
pointSizeRange.maximumValue = Float(baseStyle.pointSize * 1.50)
|
||||
lineheightRange.value = Float(lineheight)
|
||||
lineheightRange.maximumValue = Float((scaledMode ? baseStyle.scaledLineHeight : lineheight) * 1.50)
|
||||
lineheightRange.value = Float(currentStyle.lineHeight.rounded())
|
||||
lineheightRange.maximumValue = Float(pointSizeRange.value * 1.50)
|
||||
lineheightRange.minimumValue = 1
|
||||
|
||||
topInsetRange.value = Float(currentStyle.edgeInsets.top)
|
||||
bottomInsetRange.value = Float(currentStyle.edgeInsets.bottom)
|
||||
defaultLineHeightLabel?.text = "Line Height - iOS:\(Int(currentFont.lineHeight.rounded())) VDS:\(lineheightText)"
|
||||
let text = scaledMode ? "iOS: \(Int(currentFont.pointSize.rounded()))" : ""
|
||||
defaultPointLabel?.text = "Font Size - \(text) VDS:\(currentStyle.pointSize.rounded())"
|
||||
topInsetRange.value = Float(currentStyle.edgeInsets.top).rounded()
|
||||
bottomInsetRange.value = Float(currentStyle.edgeInsets.bottom).rounded()
|
||||
updateStyleLabel()
|
||||
//--------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
|
||||
var useScaledFont = Toggle()
|
||||
var boldSwitch = Toggle()
|
||||
var disabledSwitch = Toggle()
|
||||
var textField = TextField()
|
||||
private var isBold: Bool = false
|
||||
|
||||
fileprivate func updateStyleLabel() {
|
||||
baseStyleLabel.text = descriptionFor(style: baseStyle)
|
||||
currentStyleLabel.text = descriptionFor(style: currentStyle)
|
||||
}
|
||||
|
||||
override func setup() {
|
||||
super.setup()
|
||||
|
||||
@ -94,13 +127,15 @@ class LabelViewController: BaseViewController<Label> {
|
||||
setupPicker()
|
||||
setupModel()
|
||||
}
|
||||
var defaultLineHeightLabel: Label?
|
||||
var defaultPointLabel: Label?
|
||||
var calculatedLabel = UILabel()
|
||||
var calculatedLabel = Label()
|
||||
var baseStyleLabel = Label()
|
||||
var scaledFontRow: UIView?
|
||||
|
||||
var scaledLineHeightRow: UIView?
|
||||
var currentStyleRow: UIView?
|
||||
var currentStyleLabel = Label()
|
||||
func checkForScaledFonts() {
|
||||
scaledFontRow?.isHidden = !TextStyle.canScaleFonts
|
||||
scaledLineHeightRow?.isHidden = !TextStyle.canScaleFonts
|
||||
updateLabelStyle()
|
||||
}
|
||||
|
||||
@ -112,6 +147,7 @@ class LabelViewController: BaseViewController<Label> {
|
||||
|
||||
//Scaled Fonts implementation
|
||||
scaledFontRow = addFormRow(label: "Use Scaled Font", view: useScaledFont)
|
||||
scaledLineHeightRow = addFormRow(label: "Use Scaled LineHeight", view: useScaledLineHeight)
|
||||
checkForScaledFonts()
|
||||
|
||||
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
||||
@ -148,14 +184,14 @@ class LabelViewController: BaseViewController<Label> {
|
||||
//--------------------------------------------------------------
|
||||
let testingSection = FormSection()
|
||||
testingSection.title = "Temporary Settings"
|
||||
testingSection.addFormRow(label: "Calculated", view: calculatedLabel)
|
||||
testingSection.addFormRow(label: "Original Style Props", view: baseStyleLabel)
|
||||
currentStyleRow = testingSection.addFormRow(label: "Customized Style Props", view: currentStyleLabel)
|
||||
testingSection.addFormRow(label: "Min LineHeight", view: useMinimumLineHeight)
|
||||
let pointView = testingSection.addFormRow(label: "Font Size", view: pointSizeRange)
|
||||
let view = testingSection.addFormRow(label: "Line Height", view: lineheightRange)
|
||||
testingSection.addFormRow(label: "Calculated", view: calculatedLabel)
|
||||
testingSection.addFormRow(label: "Point Size", view: pointSizeRange)
|
||||
testingSection.addFormRow(label: "Line Height", view: lineheightRange)
|
||||
testingSection.addFormRow(label: "Top Inset", view: topInsetRange)
|
||||
testingSection.addFormRow(label: "Bottom Inset", view: bottomInsetRange)
|
||||
defaultLineHeightLabel = view.viewWithTag(1) as? Label
|
||||
defaultPointLabel = pointView.viewWithTag(1) as? Label
|
||||
append(section: testingSection)
|
||||
|
||||
useMinimumLineHeight
|
||||
@ -163,6 +199,15 @@ class LabelViewController: BaseViewController<Label> {
|
||||
.sink { [weak self] toggle in
|
||||
NSMutableAttributedString.useMinimumLineHeight = toggle.isOn
|
||||
self?.component.setNeedsUpdate()
|
||||
self?.updateStyleLabel()
|
||||
}.store(in: &subscribers)
|
||||
|
||||
useScaledLineHeight
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] toggle in
|
||||
NSMutableAttributedString.useScaledLineHeight = toggle.isOn
|
||||
self?.component.setNeedsUpdate()
|
||||
self?.updateStyleLabel()
|
||||
}.store(in: &subscribers)
|
||||
|
||||
pointSizeRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||
@ -215,7 +260,7 @@ class LabelViewController: BaseViewController<Label> {
|
||||
|
||||
component.publisher(for: \.bounds)
|
||||
.sink { [weak self] rect in
|
||||
self?.calculatedLabel.text = "Actual height: \(rect.height)"
|
||||
self?.calculatedLabel.text = "Actual height (* LineHeight x Text Lines): \(rect.height)"
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//------------------------------------
|
||||
@ -305,4 +350,3 @@ extension Slider {
|
||||
CGFloat((value * 100).rounded() / 100)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user