added custom

- container size
- icon size
- badgeIndicator Offset

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-06-12 15:13:47 -05:00
parent 40129d8ce9
commit c4b77dfc63

View File

@ -143,10 +143,7 @@ open class ButtonIcon: Control, Changeable {
/// Sets the size of button icon and icon. /// Sets the size of button icon and icon.
open var size: Size = .large { didSet { setNeedsUpdate() } } open var size: Size = .large { didSet { setNeedsUpdate() } }
/// Sets the size of button icon and icon.
open var customSize: Int? { didSet { setNeedsUpdate() } }
/// If provided, the button icon will have a box shadow. /// If provided, the button icon will have a box shadow.
open var floating: Bool = false { didSet { setNeedsUpdate() } } open var floating: Bool = false { didSet { setNeedsUpdate() } }
@ -169,10 +166,20 @@ open class ButtonIcon: Control, Changeable {
setNeedsUpdate() setNeedsUpdate()
} }
} }
/// Used to move the icon inside the button in both x and y axis. /// Used to move the icon inside the button in both x and y axis.
open var iconOffset: CGPoint = .init(x: 0, y: 0) { didSet { setNeedsUpdate() } } open var iconOffset: CGPoint = .init(x: 0, y: 0) { didSet { setNeedsUpdate() } }
/// Sets a custom size of button icon container.
open var customContainerSize: Int? { didSet { setNeedsUpdate() } }
/// Sets a custom size of the icon.
open var customIconSize: Int? { didSet { setNeedsUpdate() } }
/// Sets a custom badgeIndicator offset
open var customBadgeIndicatorOffset: CGPoint? { didSet { setNeedsUpdate() } }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration // MARK: - Configuration
//-------------------------------------------------- //--------------------------------------------------
@ -444,8 +451,11 @@ open class ButtonIcon: Control, Changeable {
icon.name = currentIconName icon.name = currentIconName
let color = iconColorConfiguration.getColor(self) let color = iconColorConfiguration.getColor(self)
icon.color = color icon.color = color
icon.size = iconSize if let customIconSize {
icon.customSize = customSize icon.customSize = customIconSize
} else {
icon.size = iconSize
}
icon.isEnabled = isEnabled icon.isEnabled = isEnabled
} else { } else {
icon.reset() icon.reset()
@ -480,8 +490,8 @@ open class ButtonIcon: Control, Changeable {
//updating current container size //updating current container size
var iconLayoutSize = size.containerSize var iconLayoutSize = size.containerSize
if let customSize { if let customContainerSize {
iconLayoutSize = CGFloat(customSize) iconLayoutSize = CGFloat(customContainerSize)
} }
// check to see if this is fitToIcon // check to see if this is fitToIcon
if fitToIcon && kind == .ghost { if fitToIcon && kind == .ghost {
@ -503,10 +513,11 @@ open class ButtonIcon: Control, Changeable {
layer.borderWidth = 0 layer.borderWidth = 0
} }
badgeIndicatorCenterXConstraint?.constant = badgeIndicatorOffset.x + badgeIndicatorDefaultSize.width/2 let offSet = customBadgeIndicatorOffset ?? badgeIndicatorOffset
badgeIndicatorCenterYConstraint?.constant = badgeIndicatorOffset.y + badgeIndicatorDefaultSize.height/2 badgeIndicatorCenterXConstraint?.constant = offSet.x + badgeIndicatorDefaultSize.width/2
badgeIndicatorLeadingConstraint?.constant = badgeIndicatorOffset.x badgeIndicatorCenterYConstraint?.constant = offSet.y + badgeIndicatorDefaultSize.height/2
badgeIndicatorTrailingConstraint?.constant = badgeIndicatorOffset.x + badgeIndicatorDefaultSize.width badgeIndicatorLeadingConstraint?.constant = offSet.x
badgeIndicatorTrailingConstraint?.constant = offSet.x + badgeIndicatorDefaultSize.width
if showBadgeIndicator { if showBadgeIndicator {
updateExpandDirectionalConstraints() updateExpandDirectionalConstraints()