@@ -378,7 +378,7 @@ open class StackFrameLayout: FrameLayout {
378378 var maxHeight : CGFloat = 0
379379
380380 switch distribution {
381- case . left, . right, . top, . bottom:
381+ case . left, . right, . top, . bottom, . center :
382382 var flexibleFrames = [ FrameLayout] ( )
383383 for frameLayout in activeFrameLayouts {
384384 if frameLayout. isEmpty { continue }
@@ -418,39 +418,22 @@ open class StackFrameLayout: FrameLayout {
418418
419419 break
420420
421- case . equal, . center :
421+ case . equal:
422422 let visibleFrameLayouts = visibleFrames ( )
423- var flexibleFrames = [ FrameLayout] ( )
424- frameContentSize = CGSize ( width: contentSize. width / CGFloat( visibleFrameLayouts. count) , height: contentSize. height)
423+ let visibleFrameCount = visibleFrameLayouts. count
424+ let spaces = CGFloat ( visibleFrameCount - 1 ) * spacing
425+ let contentWidth = contentSize. width - spaces
426+ let cellWidth = contentWidth / CGFloat( visibleFrameCount)
425427
426- for frameLayout in visibleFrameLayouts {
427- if frameLayout. isFlexible {
428- flexibleFrames. append ( frameLayout)
429- continue
430- }
431-
432- frameContentSize = frameLayout. sizeThatFits ( frameContentSize)
428+ visibleFrameLayouts. forEach {
429+ frameContentSize = CGSize ( width: cellWidth, height: contentSize. height) . limitTo ( minSize: $0. minSize, maxSize: $0. maxSize)
430+ frameContentSize = $0. sizeThatFits ( frameContentSize)
433431
434- gapSpace = frameContentSize. width > 0 && frameLayout != lastFrameLayout ? spacing : 0
432+ gapSpace = frameContentSize. width > 0 && $0 != lastFrameLayout ? spacing : 0
435433 totalSpace += frameContentSize. width + gapSpace
436434 maxHeight = max ( maxHeight, frameContentSize. height)
437435 }
438436
439- let flexibleFrameCount = flexibleFrames. count
440- if flexibleFrameCount > 0 {
441- let remainingSpace = CGFloat ( flexibleFrameCount - 1 ) * spacing
442- let remainingWidth = contentSize. width - totalSpace - remainingSpace
443- let cellWidth = remainingWidth / CGFloat( flexibleFrameCount)
444-
445- flexibleFrames. forEach {
446- frameContentSize = CGSize ( width: cellWidth, height: contentSize. height)
447- frameContentSize = $0. sizeThatFits ( frameContentSize)
448-
449- totalSpace += frameContentSize. width
450- maxHeight = max ( maxHeight, frameContentSize. height)
451- }
452- }
453-
454437 break
455438
456439 case . split( let ratio) :
@@ -762,11 +745,11 @@ open class StackFrameLayout: FrameLayout {
762745 let visibleFrameLayouts = visibleFrames ( )
763746 let visibleFrameCount = visibleFrameLayouts. count
764747 let spaces = CGFloat ( visibleFrameCount - 1 ) * spacing
765- let cellSize = ( containerFrame. width - spaces) / CGFloat( Float ( visibleFrameCount) )
748+ let cellWidth = ( containerFrame. width - spaces) / CGFloat( Float ( visibleFrameCount) )
766749
767750 if isOverlapped {
768751 for frameLayout in frameLayouts {
769- frameContentSize = frameLayout. isFlexible ? containerFrame. size : CGSize ( width: cellSize , height: containerFrame. height) . limitTo ( minSize: frameLayout. minSize, maxSize: frameLayout. maxSize)
752+ frameContentSize = frameLayout. isFlexible ? containerFrame. size : CGSize ( width: cellWidth , height: containerFrame. height) . limitTo ( minSize: frameLayout. minSize, maxSize: frameLayout. maxSize)
770753
771754 targetFrame. origin. x = containerFrame. minX
772755 targetFrame. size. width = frameContentSize. width
@@ -777,14 +760,15 @@ open class StackFrameLayout: FrameLayout {
777760 }
778761
779762 for frameLayout in frameLayouts {
780- frameContentSize = CGSize ( width: cellSize , height: containerFrame. height)
763+ frameContentSize = CGSize ( width: cellWidth , height: containerFrame. height) . limitTo ( minSize : frameLayout . minSize , maxSize : frameLayout . maxSize )
781764 targetFrame. origin. x = containerFrame. minX + usedSpace
782765 targetFrame. size. width = frameContentSize. width
783766 frameLayout. frame = targetFrame
784767
785768 if frameLayout. isEmpty { continue }
786769
787- usedSpace += frameContentSize. width + spacing
770+ gapSpace = frameContentSize. width > 0 ? spacing : 0
771+ usedSpace += frameContentSize. width + gapSpace
788772 }
789773 break
790774
0 commit comments