From fe54617a07fda7d9f34f8995d4a547fe9137f793 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 28 Aug 2023 16:19:14 -0500 Subject: [PATCH] moving intrinsicContentSize around into properties sections. Signed-off-by: Matt Bruce --- VDS/Classes/SelectorBase.swift | 42 +++++++++++-------- VDS/Components/Buttons/Button/Button.swift | 24 +++++------ .../Buttons/TextLink/TextLink.swift | 10 ++--- VDS/Components/Icon/Icon.swift | 12 +++--- VDS/Components/Line/Line.swift | 34 +++++++-------- VDS/Components/Toggle/Toggle.swift | 29 ++++++------- VDS/Components/Toggle/ToggleView.swift | 13 +++--- 7 files changed, 82 insertions(+), 82 deletions(-) diff --git a/VDS/Classes/SelectorBase.swift b/VDS/Classes/SelectorBase.swift index 5ca0a83e..3dbde5c4 100644 --- a/VDS/Classes/SelectorBase.swift +++ b/VDS/Classes/SelectorBase.swift @@ -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() diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index 33dda940..c2620a64 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -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 { diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 0112db87..3f7d59f5 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -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 - } - } diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 8ffbc89d..873609f6 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -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 //-------------------------------------------------- diff --git a/VDS/Components/Line/Line.swift b/VDS/Components/Line/Line.swift index b78a30a6..484bc055 100644 --- a/VDS/Components/Line/Line.swift +++ b/VDS/Components/Line/Line.swift @@ -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 + } } diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 06d49407..26990090 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -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 - } - } } diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index bf9eb4c8..ed94e9c8 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -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