Skip to content

Commit

Permalink
Merge pull request square#143 from square/kb/stack-sugar
Browse files Browse the repository at this point in the history
Add convenience methods for adding children to stacks
  • Loading branch information
kylebshr authored Sep 10, 2020
2 parents 4cfa561 + b09d10c commit e45260c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion BlueprintUI/Sources/Layout/Stack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,32 @@ extension StackElement {
///
/// - child: The child element to add to this stack
///
mutating public func add(growPriority: CGFloat = 1.0, shrinkPriority: CGFloat = 1.0, key: AnyHashable? = nil, child: Element) {
public mutating func add(growPriority: CGFloat = 1.0, shrinkPriority: CGFloat = 1.0, key: AnyHashable? = nil, child: Element) {
children.append((
element: child,
traits: StackLayout.Traits(growPriority: growPriority, shrinkPriority: shrinkPriority),
key: key
))
}


/// Convenience method for adding a child with a grow and shrink priority of 0.0
///
/// - parameters:
/// - child: The child element to add to this stack
///
public mutating func addFixed(child: Element) {
self.add(growPriority: 0, shrinkPriority: 0, child: child)
}

/// Convenience method for adding a child with a grow and shrink priority of 1.0
///
/// - parameters:
/// - child: The child element to add to this stack
///
public mutating func addFlexible(child: Element) {
self.add(growPriority: 1, shrinkPriority: 1, child: child)
}
}


Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `addFixed(child:)` and `addFlexible(child:)` methods to `StackElement` for adding children with a grow & shrink priority of 0.0 and 1.0 respectively.

### Removed

### Changed
Expand Down

0 comments on commit e45260c

Please sign in to comment.