CXTDT-464973 - Button - Width percentage parameter missing.
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
924653a726
commit
7df4f0cdf9
@ -78,6 +78,12 @@ open class Button: ButtonBase, Useable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enum used to describe the width of a fixed value or percentage of parent's width.
|
||||||
|
public enum Width {
|
||||||
|
case percentage(CGFloat)
|
||||||
|
case value(CGFloat)
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -92,14 +98,23 @@ open class Button: ButtonBase, Useable {
|
|||||||
/// The Use for this Button.
|
/// The Use for this Button.
|
||||||
open var use: Use = .primary { didSet { setNeedsUpdate() } }
|
open var use: Use = .primary { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
private var _width: CGFloat? = nil
|
private var _width: Width? = nil
|
||||||
|
|
||||||
/// If there is a width that is larger than this size's minmumWidth, the button will resize to this width.
|
/// If there is a width that is larger than this size's minmumWidth, the button will resize to this width.
|
||||||
open var width: CGFloat? {
|
open var width: Width? {
|
||||||
get { _width }
|
get { _width }
|
||||||
set {
|
set {
|
||||||
if let newValue, newValue > size.minimumWidth {
|
if let newValue {
|
||||||
_width = newValue
|
switch newValue {
|
||||||
|
case .percentage(let percentage):
|
||||||
|
if percentage <= 100.0 {
|
||||||
|
_width = newValue
|
||||||
|
}
|
||||||
|
case .value(let value):
|
||||||
|
if value > 0 && value > size.minimumWidth {
|
||||||
|
_width = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_width = nil
|
_width = nil
|
||||||
}
|
}
|
||||||
@ -118,13 +133,35 @@ open class Button: ButtonBase, Useable {
|
|||||||
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
open override var intrinsicContentSize: CGSize {
|
open override var intrinsicContentSize: CGSize {
|
||||||
guard let width, width > 0 else {
|
// get the intrinsic size
|
||||||
var superSize = super.intrinsicContentSize
|
var defaultSize = super.intrinsicContentSize
|
||||||
superSize.height = size.height
|
// ensure the size height
|
||||||
return superSize
|
defaultSize.height = size.height
|
||||||
|
|
||||||
|
// take the max width either intrinsic or size's minimumWidth
|
||||||
|
defaultSize.width = max(defaultSize.width, size.minimumWidth)
|
||||||
|
|
||||||
|
guard let width else {
|
||||||
|
return defaultSize
|
||||||
}
|
}
|
||||||
|
|
||||||
return CGSize(width: width > size.minimumWidth ? width : size.minimumWidth, height: size.height)
|
switch width {
|
||||||
|
case .percentage(let percentage):
|
||||||
|
// test the superview's width against the percentage to ensure
|
||||||
|
// it is greater than the size's minimum width
|
||||||
|
guard let superWidth = superview?.frame.width else {
|
||||||
|
return defaultSize
|
||||||
|
}
|
||||||
|
|
||||||
|
// if so set the width off percentage
|
||||||
|
defaultSize.width = max(superWidth * (percentage / 100), size.minimumWidth)
|
||||||
|
return defaultSize
|
||||||
|
|
||||||
|
case .value(let value):
|
||||||
|
// test fixed value vs minimum width and take the greater value
|
||||||
|
defaultSize.width = max(value, size.minimumWidth)
|
||||||
|
return defaultSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -216,6 +253,12 @@ open class Button: ButtonBase, Useable {
|
|||||||
|
|
||||||
invalidateIntrinsicContentSize()
|
invalidateIntrinsicContentSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override func layoutSubviews() {
|
||||||
|
super.layoutSubviews()
|
||||||
|
|
||||||
|
invalidateIntrinsicContentSize()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Use {
|
extension Use {
|
||||||
|
|||||||
@ -149,7 +149,7 @@ open class ButtonGroup: View {
|
|||||||
case .percentage(let value): percentage = value
|
case .percentage(let value): percentage = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buttons.forEach { ($0 as? Button)?.width = width }
|
buttons.forEach { if let width { ($0 as? Button)?.width = .value(width) } }
|
||||||
positionLayout.buttonPercentage = percentage
|
positionLayout.buttonPercentage = percentage
|
||||||
|
|
||||||
collectionView.reloadData()
|
collectionView.reloadData()
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
1.0.43
|
||||||
|
=======
|
||||||
|
- CXTDT-464973 - Button - Width percentage parameter missing.
|
||||||
|
|
||||||
1.0.42
|
1.0.42
|
||||||
=======
|
=======
|
||||||
- CXTDT-462698 - Tabs - Incorrect letter spacing on Large tabs
|
- CXTDT-462698 - Tabs - Incorrect letter spacing on Large tabs
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user