From 4032cd4bcff467ee390d51e673df7e51d6b82522 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 29 Oct 2014 10:30:07 +1300 Subject: [PATCH] Added more layout attributes --- Snappy/ConstraintAttributes.swift | 40 +++++++++++++++++++++++++++++++ Snappy/View+Snappy.swift | 14 +++++++++++ 2 files changed, 54 insertions(+) diff --git a/Snappy/ConstraintAttributes.swift b/Snappy/ConstraintAttributes.swift index 36c566b..4f88b35 100644 --- a/Snappy/ConstraintAttributes.swift +++ b/Snappy/ConstraintAttributes.swift @@ -61,9 +61,22 @@ internal struct ConstraintAttributes: RawOptionSetType, BooleanType { internal static var CenterY: ConstraintAttributes { return self(512) } internal static var Baseline: ConstraintAttributes { return self(1024) } + internal static var FirstBaseline: ConstraintAttributes { return self(2048) } + + internal static var LeftMargin: ConstraintAttributes { return self(4096) } + internal static var RightMargin: ConstraintAttributes { return self(8192) } + internal static var TopMargin: ConstraintAttributes { return self(16384) } + internal static var BottomMargin: ConstraintAttributes { return self(32768) } + internal static var LeadingMargin: ConstraintAttributes { return self(65536) } + internal static var TrailingMargin: ConstraintAttributes { return self(131072) } + internal static var CenterXWithinMargins: ConstraintAttributes { return self(262144) } + internal static var CenterYWithinMargins: ConstraintAttributes { return self(524288) } + internal static var Edges: ConstraintAttributes { return self(15) } internal static var Size: ConstraintAttributes { return self(192) } internal static var Center: ConstraintAttributes { return self(768) } + internal static var Margins: ConstraintAttributes { return self(61440) } + internal static var CenterWithinMargins: ConstraintAttributes { return self(786432) } internal var layoutAttributes:Array { var attrs: Array = [] @@ -100,6 +113,33 @@ internal struct ConstraintAttributes: RawOptionSetType, BooleanType { if (self & ConstraintAttributes.Baseline) { attrs.append(.Baseline) } + if (self & ConstraintAttributes.FirstBaseline) { + attrs.append(.FirstBaseline) + } + if (self & ConstraintAttributes.LeftMargin) { + attrs.append(.LeftMargin) + } + if (self & ConstraintAttributes.RightMargin) { + attrs.append(.RightMargin) + } + if (self & ConstraintAttributes.TopMargin) { + attrs.append(.TopMargin) + } + if (self & ConstraintAttributes.BottomMargin) { + attrs.append(.BottomMargin) + } + if (self & ConstraintAttributes.LeadingMargin) { + attrs.append(.LeadingMargin) + } + if (self & ConstraintAttributes.TrailingMargin) { + attrs.append(.TrailingMargin) + } + if (self & ConstraintAttributes.CenterXWithinMargins) { + attrs.append(.CenterXWithinMargins) + } + if (self & ConstraintAttributes.CenterYWithinMargins) { + attrs.append(.CenterYWithinMargins) + } return attrs } } diff --git a/Snappy/View+Snappy.swift b/Snappy/View+Snappy.swift index abb5a41..922e1f5 100644 --- a/Snappy/View+Snappy.swift +++ b/Snappy/View+Snappy.swift @@ -42,10 +42,24 @@ public extension View { public var snp_centerY: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterY) } public var snp_baseline: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Baseline) } + public var snp_firstBaseline: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.FirstBaseline) } + + public var snp_leftMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.LeftMargin) } + public var snp_rightMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.RightMargin) } + public var snp_topMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.TopMargin) } + public var snp_bottomMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.BottomMargin) } + public var snp_leadingMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.LeadingMargin) } + public var snp_trailingMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.TrailingMargin) } + public var snp_centerXWithinMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterXWithinMargins) } + public var snp_centerYWithinMargin: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterYWithinMargins) } + public var snp_edges: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Edges) } public var snp_size: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Size) } public var snp_center: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Center) } + public var snp_margins: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Margins) } + public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterWithinMargins) } + public func snp_makeConstraints(block: (maker: ConstraintMaker) -> ()) { ConstraintMaker.makeConstraints(self, block: block) }