Skip to content

Commit

Permalink
Add horizontal right alignment support (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gutty1 authored Apr 2, 2023
1 parent 9d8e973 commit a0d1b3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Parchment/Classes/PagingCollectionViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,24 @@ open class PagingCollectionViewLayout: UICollectionViewLayout, PagingLayout {
// all the other cases we want to center them if the menu
// alignment is set to .center
default:
if case .center = options.menuHorizontalAlignment {
switch options.menuHorizontalAlignment {
case .center:
// Subtract the menu insets as they should not have an effect on
// whether or not we should center the items.
let offset = (view.bounds.width - previousFrame.maxX - adjustedMenuInsets.left) / 2
for attributes in layoutAttributes.values {
attributes.frame = attributes.frame.offsetBy(dx: offset, dy: 0)
}
case .right:
// Subtract the menu insets as they should not have an effect on
// whether or not we should right align the items.
let offset = (view.bounds.width - previousFrame.maxX - adjustedMenuInsets.right)
for attributes in layoutAttributes.values {
attributes.frame = attributes.frame.offsetBy(dx: offset, dy: 0)
}

default:
break
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Parchment/Enums/PagingMenuHorizontalAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ public enum PagingMenuHorizontalAlignment {
// when PagingMenuItemSize is .fixed and the sum of the widths
// of all the paging items are less than the paging menu
case center
// Allows all paging items to be right centered within the paging menu
// when PagingMenuItemSize is .fixed and the sum of the widths
// of all the paging items are less than the paging menu
case right
}

0 comments on commit a0d1b3c

Please sign in to comment.