Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience methods for adding children to stacks #143

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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