motion-layout
motion-layout copied to clipboard
Add ability to override constraint options
Assuming that we always want to use NSLayoutFormatAlignAllCenterX/Y causes certain layouts to become impossible to create. This minor change adds the ability to optionally pass the options for each constraint individually, as so:
layout.vertical '|-padding-[headline]->=0-[byline]-padding-|', NSLayoutFormatAlignAllLeft
layout.horizontal '|-[headline]-|'
The default behavior is unchanged, and this change should be fully backwards compatible.
:+1: I support this pull request and I suppose to change the default Option to the cocoa default option NSLayoutFormatDirectionLeadingToTrailing. explanation: if we want to create a pretty simple layout like [AVIEW]-[BVIEW] [____CVIEW ___] it should be possible without unambiguous Constraint:
Motion::Layout.new do |layout|
layout.view self.view
layout.subviews 'A' => aview, 'B' => bview, 'C' => cview
layout.vertical "|[A]-[C(==A)]|"
layout.vertical "|[B(==A)]"
layout.horizontal "|[A]-[B(==A)]|" ## this causes the error
layout.horizontal "|[C]|"
end
with the current option this would cause an error:
<NSLayoutConstraint:0x4012303e0 H:[A]-(NSSpace(8))-[B] (Names: B:0x40122e600, A:0x40122e220 )>
This should be the final result with the default Option:
