moving intrinsicContentSize around into properties sections.
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d6cefaf980
commit
fe54617a07
@ -28,7 +28,24 @@ public protocol SelectorControlable: Control, Changeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open class SelectorBase: Control, SelectorControlable {
|
open class SelectorBase: Control, SelectorControlable {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializers
|
||||||
|
//--------------------------------------------------
|
||||||
|
required public init() {
|
||||||
|
super.init(frame: .zero)
|
||||||
|
}
|
||||||
|
|
||||||
|
public override init(frame: CGRect) {
|
||||||
|
super.init(frame: .zero)
|
||||||
|
}
|
||||||
|
|
||||||
|
public required init?(coder: NSCoder) {
|
||||||
|
super.init(coder: coder)
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Public Properties
|
||||||
|
//--------------------------------------------------
|
||||||
open var onChangeSubscriber: AnyCancellable? {
|
open var onChangeSubscriber: AnyCancellable? {
|
||||||
willSet {
|
willSet {
|
||||||
if let onChangeSubscriber {
|
if let onChangeSubscriber {
|
||||||
@ -69,33 +86,22 @@ open class SelectorBase: Control, SelectorControlable {
|
|||||||
|
|
||||||
open var selectorColorConfiguration = ControlColorConfiguration() { didSet { setNeedsUpdate() }}
|
open var selectorColorConfiguration = ControlColorConfiguration() { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
|
open override var intrinsicContentSize: CGSize { size }
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Private Properties
|
||||||
|
//--------------------------------------------------
|
||||||
private var selectorView = View()
|
private var selectorView = View()
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal var shapeLayer: CAShapeLayer?
|
internal var shapeLayer: CAShapeLayer?
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Initializers
|
|
||||||
//--------------------------------------------------
|
|
||||||
required public init() {
|
|
||||||
super.init(frame: .zero)
|
|
||||||
}
|
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
|
||||||
super.init(frame: .zero)
|
|
||||||
}
|
|
||||||
|
|
||||||
public required init?(coder: NSCoder) {
|
|
||||||
super.init(coder: coder)
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
||||||
open override var intrinsicContentSize: CGSize { size }
|
|
||||||
|
|
||||||
/// Executed on initialization for this View.
|
/// Executed on initialization for this View.
|
||||||
open override func initialSetup() {
|
open override func initialSetup() {
|
||||||
super.initialSetup()
|
super.initialSetup()
|
||||||
|
|||||||
@ -45,7 +45,7 @@ open class Button: ButtonBase, Useable {
|
|||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// The ButtonSize available to this type of Buttonable.
|
/// The ButtonSize available to this type of Buttonable.
|
||||||
open override var availableSizes: [ButtonSize] { [.large, .small] }
|
open override var availableSizes: [ButtonSize] { [.large, .small] }
|
||||||
@ -80,6 +80,17 @@ open class Button: ButtonBase, Useable {
|
|||||||
size == .large ? TextStyle.boldBodyLarge : TextStyle.boldBodySmall
|
size == .large ? TextStyle.boldBodyLarge : TextStyle.boldBodySmall
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
|
open override var intrinsicContentSize: CGSize {
|
||||||
|
guard let width, width > 0 else {
|
||||||
|
var superSize = super.intrinsicContentSize
|
||||||
|
superSize.height = size.height
|
||||||
|
return superSize
|
||||||
|
}
|
||||||
|
|
||||||
|
return CGSize(width: width > size.minimumWidth ? width : size.minimumWidth, height: size.height)
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Configuration Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -169,17 +180,6 @@ open class Button: ButtonBase, Useable {
|
|||||||
|
|
||||||
invalidateIntrinsicContentSize()
|
invalidateIntrinsicContentSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
||||||
open override var intrinsicContentSize: CGSize {
|
|
||||||
guard let width, width > 0 else {
|
|
||||||
var superSize = super.intrinsicContentSize
|
|
||||||
superSize.height = size.height
|
|
||||||
return superSize
|
|
||||||
}
|
|
||||||
|
|
||||||
return CGSize(width: width > size.minimumWidth ? width : size.minimumWidth, height: size.height)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal extension ButtonSize {
|
internal extension ButtonSize {
|
||||||
|
|||||||
@ -75,6 +75,11 @@ open class TextLink: ButtonBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
|
open override var intrinsicContentSize: CGSize {
|
||||||
|
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -118,9 +123,4 @@ open class TextLink: ButtonBase {
|
|||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
||||||
open override var intrinsicContentSize: CGSize {
|
|
||||||
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,11 @@ open class Icon: View {
|
|||||||
open var name: Name? { didSet { setNeedsUpdate() }}
|
open var name: Name? { didSet { setNeedsUpdate() }}
|
||||||
open var customSize: Int? { didSet { setNeedsUpdate() }}
|
open var customSize: Int? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
|
open override var intrinsicContentSize: CGSize {
|
||||||
|
dimensions
|
||||||
|
}
|
||||||
|
|
||||||
//functions
|
//functions
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
@ -109,12 +114,7 @@ open class Icon: View {
|
|||||||
color = VDSColor.paletteBlack
|
color = VDSColor.paletteBlack
|
||||||
imageView.image = nil
|
imageView.image = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
||||||
open override var intrinsicContentSize: CGSize {
|
|
||||||
dimensions
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -41,9 +41,20 @@ open class Line: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open var style: Style = .primary { didSet { setNeedsUpdate() } }
|
open var style: Style = .primary { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
open var orientation: Orientation = .horizontal { didSet { setNeedsUpdate() } }
|
open var orientation: Orientation = .horizontal { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
|
open override var intrinsicContentSize: CGSize {
|
||||||
|
if orientation == .vertical {
|
||||||
|
return .init(width: 1, height: bounds.height)
|
||||||
|
} else {
|
||||||
|
return .init(width: bounds.width, height: 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration
|
// MARK: - Configuration
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -57,23 +68,6 @@ open class Line: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
||||||
open override var intrinsicContentSize: CGSize {
|
|
||||||
if orientation == .vertical {
|
|
||||||
return .init(width: 1, height: bounds.height)
|
|
||||||
} else {
|
|
||||||
return .init(width: bounds.width, height: 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resets to default settings.
|
|
||||||
open override func reset() {
|
|
||||||
super.reset()
|
|
||||||
style = .primary
|
|
||||||
orientation = .horizontal
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
@ -88,4 +82,10 @@ open class Line: View {
|
|||||||
invalidateIntrinsicContentSize()
|
invalidateIntrinsicContentSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resets to default settings.
|
||||||
|
open override func reset() {
|
||||||
|
super.reset()
|
||||||
|
style = .primary
|
||||||
|
orientation = .horizontal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,8 +131,20 @@ open class Toggle: Control, Changeable {
|
|||||||
|
|
||||||
open var value: AnyHashable? { didSet { setNeedsUpdate() }}
|
open var value: AnyHashable? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
|
open override var intrinsicContentSize: CGSize {
|
||||||
|
if showLabel {
|
||||||
|
label.sizeToFit()
|
||||||
|
let size = CGSize(width: label.frame.width + spacingBetween + toggleContainerSize.width,
|
||||||
|
height: max(toggleContainerSize.height, label.frame.height))
|
||||||
|
return size
|
||||||
|
} else {
|
||||||
|
return toggleContainerSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// Executed on initialization for this View.
|
/// Executed on initialization for this View.
|
||||||
open override func initialSetup() {
|
open override func initialSetup() {
|
||||||
@ -256,19 +268,4 @@ open class Toggle: Control, Changeable {
|
|||||||
NSLayoutConstraint.deactivate(labelConstraints)
|
NSLayoutConstraint.deactivate(labelConstraints)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Overrides
|
|
||||||
//--------------------------------------------------
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
||||||
open override var intrinsicContentSize: CGSize {
|
|
||||||
if showLabel {
|
|
||||||
label.sizeToFit()
|
|
||||||
let size = CGSize(width: label.frame.width + spacingBetween + toggleContainerSize.width,
|
|
||||||
height: max(toggleContainerSize.height, label.frame.height))
|
|
||||||
return size
|
|
||||||
} else {
|
|
||||||
return toggleContainerSize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,6 +75,9 @@ open class ToggleView: Control, Changeable {
|
|||||||
|
|
||||||
open var value: AnyHashable? { didSet { setNeedsUpdate() }}
|
open var value: AnyHashable? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
|
open override var intrinsicContentSize: CGSize { toggleSize }
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Configuration Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -103,7 +106,7 @@ open class ToggleView: Control, Changeable {
|
|||||||
private var knobTrailingConstraint: NSLayoutConstraint?
|
private var knobTrailingConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// Executed on initialization for this View.
|
/// Executed on initialization for this View.
|
||||||
open override func initialSetup() {
|
open override func initialSetup() {
|
||||||
@ -188,13 +191,7 @@ open class ToggleView: Control, Changeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Private Functions
|
||||||
//--------------------------------------------------
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
|
||||||
open override var intrinsicContentSize: CGSize { toggleSize }
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Toggle
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private func constrainKnob(){
|
private func constrainKnob(){
|
||||||
knobLeadingConstraint?.isActive = false
|
knobLeadingConstraint?.isActive = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user