updated for label changes
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
20e053ab5f
commit
1410f30178
@ -10,17 +10,17 @@ import VDS
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
extension UIView {
|
extension UIView {
|
||||||
public func makeWrapper(edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> UIView {
|
public func makeWrapper(edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> View {
|
||||||
UIView.makeWrapper(for: self, edgeSpacing: edgeSpacing, isTrailing: isTrailing)
|
UIView.makeWrapper(for: self, edgeSpacing: edgeSpacing, isTrailing: isTrailing)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> UIView {
|
public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> View {
|
||||||
makeWrapperWithConstraints(for: view, edgeSpacing: edgeSpacing, isTrailing: isTrailing).view
|
makeWrapperWithConstraints(for: view, edgeSpacing: edgeSpacing, isTrailing: isTrailing).view
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func makeWrapperWithConstraints(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> (view: UIView, container: NSLayoutConstraint.Container) {
|
public static func makeWrapperWithConstraints(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> (view: View, container: NSLayoutConstraint.Container) {
|
||||||
let container = NSLayoutConstraint.Container()
|
let container = NSLayoutConstraint.Container()
|
||||||
let wrapper = UIView().with {
|
let wrapper = View().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
}
|
}
|
||||||
wrapper.addSubview(view)
|
wrapper.addSubview(view)
|
||||||
|
|||||||
@ -27,9 +27,16 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
FontCategoryPickerSelectorView(title: "",
|
FontCategoryPickerSelectorView(title: "",
|
||||||
picker: self.picker)
|
picker: self.picker)
|
||||||
}()
|
}()
|
||||||
|
//------------------------------------
|
||||||
|
//testing only remove later
|
||||||
|
//------------------------------------
|
||||||
|
var pointSizeRange = Slider()
|
||||||
var lineheightRange = Slider()
|
var lineheightRange = Slider()
|
||||||
var lineSpacingRange = Slider()
|
var lineSpacingRange = Slider()
|
||||||
var baselineOffsetRange = Slider()
|
var topInsetRange = Slider()
|
||||||
|
var bottomInsetRange = Slider()
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
var currentStyle: TextStyle!
|
var currentStyle: TextStyle!
|
||||||
var boldSwitch = Toggle()
|
var boldSwitch = Toggle()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
@ -44,27 +51,24 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
stack.addArrangedSubview(component)
|
stack.addArrangedSubview(component)
|
||||||
stack.addArrangedSubview(lineHeightLabel)
|
stack.addArrangedSubview(lineHeightLabel)
|
||||||
|
|
||||||
addContentTopView(view: stack)
|
addContentTopView(view: component)
|
||||||
|
|
||||||
setupPicker()
|
setupPicker()
|
||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
var defaultLineHeightLabel: UILabel?
|
var defaultLineHeightLabel: UILabel?
|
||||||
|
var defaultPointLabel: UILabel?
|
||||||
|
var calculatedLabel = UILabel()
|
||||||
override func allTextFields() -> [TextField]? { [textField] }
|
override func allTextFields() -> [TextField]? { [textField] }
|
||||||
|
|
||||||
override func setupForm(){
|
override func setupForm(){
|
||||||
super.setupForm()
|
super.setupForm()
|
||||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||||
addFormRow(label: "Bold", view: boldSwitch)
|
addFormRow(label: "Bold", view: boldSwitch)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
||||||
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
|
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
|
||||||
addFormRow(label: "Text Size", view: textSizePickerSelectorView)
|
addFormRow(label: "Text Size", view: textSizePickerSelectorView)
|
||||||
let view = addFormRow(label: "Line Height", view: lineheightRange)
|
|
||||||
addFormRow(label: "Line Spacing", view: lineSpacingRange)
|
|
||||||
addFormRow(label: "Baseline Offset", view: baselineOffsetRange)
|
|
||||||
defaultLineHeightLabel = view.viewWithTag(1) as? UILabel
|
|
||||||
addFormRow(label: "Text", view: textField)
|
addFormRow(label: "Text", view: textField)
|
||||||
|
|
||||||
disabledSwitch.onChange = { [weak self] sender in
|
disabledSwitch.onChange = { [weak self] sender in
|
||||||
@ -85,6 +89,34 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
self?.lineHeightLabel.text = text
|
self?.lineHeightLabel.text = text
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
#warning("testing only remove later")
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
let testingSection = FormSection()
|
||||||
|
testingSection.title = "Temporary Settings"
|
||||||
|
testingSection.addFormRow(label: "Calculated", view: calculatedLabel)
|
||||||
|
let pointView = testingSection.addFormRow(label: "Font Size", view: pointSizeRange)
|
||||||
|
let view = 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? UILabel
|
||||||
|
defaultPointLabel = pointView.viewWithTag(1) as? UILabel
|
||||||
|
append(section: testingSection)
|
||||||
|
|
||||||
|
pointSizeRange.maximumValue = 20.0
|
||||||
|
pointSizeRange.minimumValue = 0.0
|
||||||
|
pointSizeRange.value = 0.0
|
||||||
|
pointSizeRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
|
guard let self else { return }
|
||||||
|
let textStyle = self.component.textStyle
|
||||||
|
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
||||||
|
fontFace: textStyle.fontFace,
|
||||||
|
pointSize: CGFloat(slider.value),
|
||||||
|
lineHeight: textStyle.lineHeight,
|
||||||
|
letterSpacing: textStyle.letterSpacing,
|
||||||
|
edgeInsets: textStyle.edgeInsets)
|
||||||
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
lineheightRange.maximumValue = 20.0
|
lineheightRange.maximumValue = 20.0
|
||||||
lineheightRange.minimumValue = 0.0
|
lineheightRange.minimumValue = 0.0
|
||||||
lineheightRange.value = 2.0
|
lineheightRange.value = 2.0
|
||||||
@ -95,46 +127,49 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
fontFace: textStyle.fontFace,
|
fontFace: textStyle.fontFace,
|
||||||
pointSize: textStyle.pointSize,
|
pointSize: textStyle.pointSize,
|
||||||
lineHeight: CGFloat(slider.value),
|
lineHeight: CGFloat(slider.value),
|
||||||
letterSpacing: textStyle.letterSpacing)
|
|
||||||
}).store(in: &subscribers)
|
|
||||||
|
|
||||||
lineSpacingRange.maximumValue = 80.0
|
|
||||||
lineSpacingRange.minimumValue = 0.0
|
|
||||||
lineSpacingRange.value = 0.0
|
|
||||||
lineSpacingRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
|
||||||
guard let self else { return }
|
|
||||||
let textStyle = self.component.textStyle
|
|
||||||
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
|
||||||
fontFace: textStyle.fontFace,
|
|
||||||
pointSize: textStyle.pointSize,
|
|
||||||
lineHeight: textStyle.lineHeight,
|
|
||||||
letterSpacing: textStyle.letterSpacing,
|
letterSpacing: textStyle.letterSpacing,
|
||||||
lineSpacing: CGFloat(slider.value),
|
edgeInsets: textStyle.edgeInsets)
|
||||||
baselineOffset: textStyle.baselineOffset
|
|
||||||
)
|
|
||||||
}).store(in: &subscribers)
|
|
||||||
|
|
||||||
baselineOffsetRange.maximumValue = 100
|
|
||||||
baselineOffsetRange.minimumValue = -100
|
|
||||||
baselineOffsetRange.value = 0.0
|
|
||||||
baselineOffsetRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
|
||||||
guard let self else { return }
|
|
||||||
let textStyle = self.component.textStyle
|
|
||||||
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
|
||||||
fontFace: textStyle.fontFace,
|
|
||||||
pointSize: textStyle.pointSize,
|
|
||||||
lineHeight: textStyle.lineHeight,
|
|
||||||
letterSpacing: textStyle.letterSpacing,
|
|
||||||
lineSpacing: textStyle.lineSpacing,
|
|
||||||
baselineOffset: CGFloat(slider.value)
|
|
||||||
)
|
|
||||||
}).store(in: &subscribers)
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
|
topInsetRange.maximumValue = 20.0
|
||||||
|
topInsetRange.minimumValue = -20
|
||||||
|
topInsetRange.value = 0
|
||||||
|
topInsetRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
|
guard let self else { return }
|
||||||
|
let textStyle = self.component.textStyle
|
||||||
|
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
||||||
|
fontFace: textStyle.fontFace,
|
||||||
|
pointSize: textStyle.pointSize,
|
||||||
|
lineHeight: textStyle.lineHeight,
|
||||||
|
letterSpacing: textStyle.letterSpacing,
|
||||||
|
edgeInsets: .init(top: CGFloat(slider.value), left: 0, bottom: CGFloat(bottomInsetRange.value), right: 0))
|
||||||
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
|
bottomInsetRange.maximumValue = 20.0
|
||||||
|
bottomInsetRange.minimumValue = -20
|
||||||
|
bottomInsetRange.value = 0
|
||||||
|
bottomInsetRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
|
guard let self else { return }
|
||||||
|
let textStyle = self.component.textStyle
|
||||||
|
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
||||||
|
fontFace: textStyle.fontFace,
|
||||||
|
pointSize: textStyle.pointSize,
|
||||||
|
lineHeight: textStyle.lineHeight,
|
||||||
|
letterSpacing: textStyle.letterSpacing,
|
||||||
|
edgeInsets: .init(top: CGFloat(topInsetRange.value), left: 0, bottom: CGFloat(slider.value), right: 0))
|
||||||
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
|
component.publisher(for: \.bounds)
|
||||||
|
.sink { [weak self] rect in
|
||||||
|
self?.calculatedLabel.text = "Actual height: \(rect.height)"
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupModel() {
|
func setupModel() {
|
||||||
component.text = "Label Component"
|
component.text = "Helg¹ worldg Hell¹ worldg"
|
||||||
component.textStyle = .featureSmall
|
component.textStyle = .featureXLarge
|
||||||
lineHeightLabel.text = component.text
|
lineHeightLabel.text = component.text
|
||||||
lineHeightLabel.font = component.textStyle.font
|
lineHeightLabel.font = component.textStyle.font
|
||||||
|
|
||||||
@ -147,15 +182,18 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
//set the font
|
//set the font
|
||||||
fontCategory = .feature
|
fontCategory = .feature
|
||||||
fontCategoryPickerSelectorView.text = "Feature"
|
fontCategoryPickerSelectorView.text = "Feature"
|
||||||
textSize = .small
|
textSize = .xlarge
|
||||||
textSizePickerSelectorView.text = "Small"
|
textSizePickerSelectorView.text = "XLarge"
|
||||||
updateLabelStyle()
|
updateLabelStyle()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func showDebug(show: Bool) {
|
override func showDebug(show: Bool) {
|
||||||
super.showDebug(show: show)
|
component.layer.borderColor = UIColor.blue.cgColor
|
||||||
lineHeightLabel.debugBorder(show: show)
|
component.layer.borderWidth = show ? 1 : 0
|
||||||
|
|
||||||
|
lineHeightLabel.layer.borderColor = UIColor.blue.cgColor
|
||||||
|
lineHeightLabel.layer.borderWidth = show ? 1 : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//Picker
|
//Picker
|
||||||
@ -177,22 +215,32 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
textSizePickerSelectorView.text = textSize?.rawValue ?? ""
|
textSizePickerSelectorView.text = textSize?.rawValue ?? ""
|
||||||
updateLabelStyle()
|
updateLabelStyle()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateLabelStyle(){
|
func updateLabelStyle(){
|
||||||
if let style = fontCategory.style(for: textSize, isBold: isBold) {
|
if let style = fontCategory.style(for: textSize, isBold: isBold) {
|
||||||
component.textStyle = style
|
component.textStyle = style
|
||||||
currentStyle = style
|
currentStyle = style
|
||||||
|
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
#warning("testing only remove later")
|
||||||
|
//--------------------------------------------------------------
|
||||||
let defaultLineHeight = style.font.lineHeight
|
let defaultLineHeight = style.font.lineHeight
|
||||||
lineHeightLabel.font = style.font
|
lineHeightLabel.font = style.font
|
||||||
lineheightRange.maximumValue = Float(defaultLineHeight) * 1.50
|
lineheightRange.maximumValue = Float(defaultLineHeight) * 1.50
|
||||||
lineheightRange.minimumValue = Float(defaultLineHeight) * 0.50
|
lineheightRange.minimumValue = Float(defaultLineHeight) * 0.50
|
||||||
lineheightRange.value = Float(style.lineHeight)
|
lineheightRange.value = Float(style.lineHeight)
|
||||||
defaultLineHeightLabel?.text = "Line Height - d:\(defaultLineHeight) s:\(currentStyle.lineHeight)"
|
pointSizeRange.value = Float(style.pointSize)
|
||||||
|
pointSizeRange.maximumValue = Float(style.pointSize) * 1.50
|
||||||
|
pointSizeRange.minimumValue = Float(style.pointSize) * 0.50
|
||||||
|
topInsetRange.value = Float(style.edgeInsets.top)
|
||||||
|
bottomInsetRange.value = Float(style.edgeInsets.bottom)
|
||||||
|
defaultLineHeightLabel?.text = "Line Height - d:\(defaultLineHeight) s:\(style.lineHeight)"
|
||||||
|
defaultPointLabel?.text = "Font Size - s:\(style.pointSize)"
|
||||||
|
//--------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupPicker(){
|
func setupPicker(){
|
||||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||||
self?.component.surface = item
|
self?.component.surface = item
|
||||||
@ -211,5 +259,6 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
self?.fontCategory = item
|
self?.fontCategory = item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user