moving intrinsicContentSize around into properties sections.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-28 16:19:14 -05:00
parent d6cefaf980
commit fe54617a07
7 changed files with 82 additions and 82 deletions

View File

@ -28,7 +28,24 @@ public protocol SelectorControlable: Control, Changeable {
}
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? {
willSet {
if let onChangeSubscriber {
@ -69,33 +86,22 @@ open class SelectorBase: Control, SelectorControlable {
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()
//--------------------------------------------------
// MARK: - Constraints
//--------------------------------------------------
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
//--------------------------------------------------
/// 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.
open override func initialSetup() {
super.initialSetup()

View File

@ -45,7 +45,7 @@ open class Button: ButtonBase, Useable {
private var initialSetupPerformed = false
//--------------------------------------------------
// MARK: - Properties
// MARK: - Public Properties
//--------------------------------------------------
/// The ButtonSize available to this type of Buttonable.
open override var availableSizes: [ButtonSize] { [.large, .small] }
@ -80,6 +80,17 @@ open class Button: ButtonBase, Useable {
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
//--------------------------------------------------
@ -169,17 +180,6 @@ open class Button: ButtonBase, Useable {
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 {

View File

@ -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
//--------------------------------------------------
@ -118,9 +123,4 @@ open class TextLink: ButtonBase {
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
}
}

View File

@ -57,6 +57,11 @@ open class Icon: View {
open var name: Name? { 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
//--------------------------------------------------
// MARK: - Overrides
@ -109,12 +114,7 @@ open class Icon: View {
color = VDSColor.paletteBlack
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
//--------------------------------------------------

View File

@ -41,9 +41,20 @@ open class Line: View {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var style: Style = .primary { 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
//--------------------------------------------------
@ -57,23 +68,6 @@ open class Line: View {
//--------------------------------------------------
// 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.
open override func setup() {
super.setup()
@ -88,4 +82,10 @@ open class Line: View {
invalidateIntrinsicContentSize()
}
/// Resets to default settings.
open override func reset() {
super.reset()
style = .primary
orientation = .horizontal
}
}

View File

@ -131,8 +131,20 @@ open class Toggle: Control, Changeable {
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.
open override func initialSetup() {
@ -256,19 +268,4 @@ open class Toggle: Control, Changeable {
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
}
}
}

View File

@ -75,6 +75,9 @@ open class ToggleView: Control, Changeable {
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
//--------------------------------------------------
@ -103,7 +106,7 @@ open class ToggleView: Control, Changeable {
private var knobTrailingConstraint: NSLayoutConstraint?
//--------------------------------------------------
// MARK: - Lifecycle
// MARK: - Overrides
//--------------------------------------------------
/// Executed on initialization for this View.
open override func initialSetup() {
@ -188,13 +191,7 @@ open class ToggleView: Control, Changeable {
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
/// The natural size for the receiving view, considering only properties of the view itself.
open override var intrinsicContentSize: CGSize { toggleSize }
//--------------------------------------------------
// MARK: - Toggle
// MARK: - Private Functions
//--------------------------------------------------
private func constrainKnob(){
knobLeadingConstraint?.isActive = false