Skip to content

Commit

Permalink
Adding optional labelWidthRatio so the width ratio constrain between …
Browse files Browse the repository at this point in the history
…label and content is optional.
  • Loading branch information
michelf committed Feb 24, 2024
1 parent 1e7976f commit 5ab65da
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/MFXUI/Forms/Form.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class MFFormView: UXView {
}
}

public init(layout: Layout = .default, @UXViewBuilder _ subviews: () -> [UXView]) {
public init(layout: Layout = .default, labelWidthRatio: CGFloat? = nil, @UXViewBuilder _ subviews: () -> [UXView]) {
self.stack = UXStackView(axis: .vertical, spacing: MFFormView.rowSpacing, subviews)

let labelGuide = UXLayoutGuide()
Expand Down Expand Up @@ -69,9 +69,11 @@ open class MFFormView: UXView {
contentGuide.trailingAnchor.constraint(equalTo: trailingAnchor),
])

labelGuide.widthAnchor.constraint(equalTo: contentGuide.widthAnchor, multiplier: 0.5)
.withPriority(.defaultHigh)
.isActive = true
if let labelWidthRatio {
labelGuide.widthAnchor.constraint(equalTo: contentGuide.widthAnchor, multiplier: labelWidthRatio)
.withPriority(.defaultHigh)
.isActive = true
}
labelGuide.widthAnchor.constraint(lessThanOrEqualTo: contentGuide.widthAnchor, multiplier: 1)
.withPriority(.required)
.isActive = true
Expand Down

0 comments on commit 5ab65da

Please sign in to comment.