From 30a4b1e0f749f62671334d57fd1b706f042e537c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Aug 2024 15:41:50 -0500 Subject: [PATCH] refactored more code Signed-off-by: Matt Bruce --- .../ButtonGroup/ButtonGroupPositionLayout.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 02a93556..00ff747c 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -68,13 +68,10 @@ class ButtonCollectionViewRow { //getting available button space since textlinks need their space let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace - totalSpacingBetweenAttributes - var maxButtonWidth = buttonsAvailableSpace / buttonCount - var buttonCalculatedPercentage: CGFloat = 0.0 let buttonEqualSpacing = buttonsAvailableSpace / buttonCount - - // test sizing - let testSize = maxButtonWidth * CGFloat(buttonAttributes.count) - + var maxButtonWidth = buttonEqualSpacing //default to equal spacing + var buttonCalculatedPercentage: CGFloat = 0.0 + //check to see if you have buttons and there is a percentage if let buttonPercentage, hasButtons, buttonPercentage > 0 { buttonCalculatedPercentage = CGFloat(buttonPercentage / 100.0) @@ -83,12 +80,14 @@ class ButtonCollectionViewRow { } //resize the buttonAttributes - if maxButtonWidth >= Button.Size.large.minimumWidth && !buttonAttributes.isEmpty { - if testSize <= buttonsAvailableSpace { + if maxButtonWidth >= Button.Size.large.minimumWidth { + //if there is enough room for all buttons + if maxButtonWidth * buttonCount <= buttonsAvailableSpace { for attribute in buttonAttributes { attribute.frame.size.width = buttonCalculatedPercentage.isZero ? min(attribute.frame.size.width, maxButtonWidth) : maxButtonWidth } } else { + //if not enough room, give all buttons the same width for attribute in buttonAttributes { attribute.frame.size.width = buttonEqualSpacing }