Skip to content

Commit f0042dc

Browse files
committed
wrap operation
1 parent 0c99a7d commit f0042dc

32 files changed

+651
-274
lines changed

Demos/Demos.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@
392392
buildSettings = {
393393
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
394394
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
395+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
395396
DEVELOPMENT_TEAM = 3W5V93WN72;
396397
INFOPLIST_FILE = Demos/Info.plist;
397398
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

Demos/Demos/Base.lproj/LaunchScreen.storyboard

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1108" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<scenes>
812
<!--View Controller-->
@@ -14,9 +18,9 @@
1418
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
1519
</layoutGuides>
1620
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
17-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1822
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
23+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2024
</view>
2125
</viewController>
2226
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>

Demos/Demos/Put.swift

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,172 @@ class PutDemo_FixFlexGrid: UIView, DemoViewProtocol {
322322

323323
static let title = "Fix+Flex grid"
324324
static let comments = "Elegant way to layout views in grid using just one hput and one vput"
325-
}
325+
}
326+
327+
class PutDemo_DigiMax: UIView, DemoViewProtocol {
328+
329+
let topView1 = makeViewWithColor(.red)
330+
let topView2 = makeViewWithColor(.blue)
331+
let topView3 = makeViewWithColor(.cyan)
332+
let cardView1 = makeViewWithColor(.green)
333+
let cardView2 = makeViewWithColor(.orange)
334+
let cardView3 = makeViewWithColor(.brown)
335+
let cardView4 = makeViewWithColor(.purple)
336+
337+
let bottomView = makeViewWithColor(.gray)
338+
339+
340+
override init(frame: CGRect) {
341+
super.init(frame: frame)
342+
343+
addSubview(topView1)
344+
addSubview(topView2)
345+
addSubview(topView3)
346+
addSubview(cardView1)
347+
addSubview(cardView2)
348+
addSubview(cardView3)
349+
addSubview(cardView4)
350+
351+
addSubview(bottomView)
352+
}
353+
354+
required init?(coder aDecoder: NSCoder) {
355+
fatalError("init(coder:) has not been implemented")
356+
}
357+
358+
359+
360+
override func layoutSubviews() {
361+
super.layoutSubviews()
362+
363+
let topSize = CGSize(width: 60, height: 60)
364+
let topPadding: CGFloat = 10
365+
366+
let topLeftRightPadding: CGFloat = 20
367+
368+
topView1.lx.set(size: topSize)
369+
.alignTop(topPadding)
370+
topView2.lx.set(size: topSize)
371+
.alignTop(topPadding)
372+
topView3.lx.set(size: topSize)
373+
.alignTop(topPadding)
374+
375+
lx.hput(
376+
Fix(topLeftRightPadding),
377+
Fix(topView1),
378+
Flex(),
379+
Fix(topView2),
380+
Flex(),
381+
Fix(topView3),
382+
Fix(topLeftRightPadding)
383+
)
384+
385+
let cardSize = bounds.width < bounds.height ? CGSize(width: 80, height: 120) : CGSize(width: 60, height: 90)
386+
let cardLeftRightPadding: CGFloat = 25
387+
388+
cardView1.lx.set(size: cardSize)
389+
cardView2.lx.set(size: cardSize)
390+
cardView3.lx.set(size: cardSize)
391+
cardView4.lx.set(size: cardSize)
392+
393+
394+
if bounds.width < bounds.height {
395+
cardView1.lx.vcenter()
396+
cardView2.lx.vcenter()
397+
398+
lx.hput(
399+
Fix(cardLeftRightPadding),
400+
Fix(cardView1),
401+
Flex(),
402+
Fix(cardView2),
403+
Fix(cardLeftRightPadding)
404+
)
405+
406+
cardView3.lx.hcenter()
407+
cardView4.lx.hcenter()
408+
409+
lx.vput(
410+
Flex(),
411+
Fix(cardView3),
412+
Fix(60),
413+
Fix(cardView4),
414+
Flex()
415+
)
416+
} else {
417+
cardView1.lx.vcenter()
418+
cardView2.lx.vcenter()
419+
cardView3.lx.vcenter()
420+
cardView4.lx.vcenter()
421+
422+
lx.hput(
423+
Fix(cardLeftRightPadding),
424+
Fix(cardView1),
425+
Flex(),
426+
Fix(cardView3),
427+
Flex(),
428+
Fix(cardView4),
429+
Flex(),
430+
Fix(cardView2),
431+
Fix(cardLeftRightPadding)
432+
)
433+
}
434+
435+
436+
bottomView.lx.set(height: 40)
437+
.hfill(inset: 100)
438+
.alignBottom(15)
439+
}
440+
441+
static let title = "Digimax"
442+
static let comments = "AL Battle"
443+
}
444+
445+
class PutDemo_Wrap: UIView, DemoViewProtocol {
446+
447+
let container = makeGreenView()
448+
let title = makeTitleLabel()
449+
let details = makeDetailsLabel()
450+
451+
override init(frame: CGRect) {
452+
super.init(frame: frame)
453+
454+
addSubview(container)
455+
container.addSubview(title)
456+
container.addSubview(details)
457+
}
458+
459+
required init?(coder aDecoder: NSCoder) {
460+
fatalError("init(coder:) has not been implemented")
461+
}
462+
463+
override func layoutSubviews() {
464+
super.layoutSubviews()
465+
466+
let maxLabelsWidth: CGFloat = 250
467+
468+
title.lx.sizeToFit(width: .value(maxLabelsWidth), height: .max)
469+
details.lx.sizeToFit(width: .value(maxLabelsWidth), height: .max)
470+
471+
container.lx.hwrap(
472+
Fix(10),
473+
Fix([title, details], .max), //fixing for view with greatest width
474+
Fix(10)
475+
)
476+
477+
container.lx.vwrap(
478+
Fix(10),
479+
Fix(title),
480+
Fix(10),
481+
Fix(details),
482+
Fix(10)
483+
)
484+
485+
container.lx.center()
486+
}
487+
488+
489+
static let title = "Wrap"
490+
static let comments = "Derivative from put operation. Accepts only Fix. Modifies parent frame to wrap childs. Method to perform selfsizing."
491+
}
492+
493+

Demos/Demos/TableViewController.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ class TableViewController: UIViewController {
118118

119119
if width == referenceWidth {
120120
self.nodeModels = nodeModels
121-
tableView.reloadData()
122121
}
123122
}
124123
}
@@ -144,14 +143,7 @@ extension TableViewController: UITableViewDelegate, UITableViewDataSource {
144143
}
145144

146145
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
147-
148-
let (_, rootNode) = nodeModels[indexPath.row]
149-
150-
if rootNode.frame.width == tableView.frame.width {
151-
return rootNode.frame.height
152-
}else {
153-
return 100
154-
}
146+
return 100
155147
}
156148

157149
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

Demos/Demos/ViewController.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ class ViewController: UIViewController {
7171
Row<PutDemo_FixFlexCenter>(),
7272
Row<PutDemo_Multi>(),
7373
Row<PutDemo_FixFlexGrid>(),
74-
Row<PutDemo_Labels>()
74+
Row<PutDemo_Labels>(),
75+
Row<PutDemo_DigiMax>(),
76+
Row<PutDemo_Wrap>()
7577
]
7678
),
7779
Section(title: "Viewport", rows:
7880
[
7981
Row<ViewPortDemo>()
8082
]
81-
),
82-
83+
)
8384
]
8485

8586
override func viewDidLoad() {

LayoutOps/LayoutOps.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1B49D7121DB8D02800823FF3 /* Viewport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B49D70B1DB8D02800823FF3 /* Viewport.swift */; };
1818
1B49D7131DB8D02800823FF3 /* Follow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B49D70C1DB8D02800823FF3 /* Follow.swift */; };
1919
1B49D7141DB8D02800823FF3 /* Basic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B49D70D1DB8D02800823FF3 /* Basic.swift */; };
20-
1B49D7151DB8D02800823FF3 /* Put.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B49D70E1DB8D02800823FF3 /* Put.swift */; };
20+
1B49D7151DB8D02800823FF3 /* PutWrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B49D70E1DB8D02800823FF3 /* PutWrap.swift */; };
2121
1B6645E41DB8F44C0059CFC8 /* Accelerate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B6645E31DB8F44C0059CFC8 /* Accelerate.swift */; };
2222
1B7857CE1E6019D00025DD28 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B7857CD1E6019D00025DD28 /* Utils.swift */; };
2323
1BAD4FEF1CDF54CA00692E31 /* LayoutOps.h in Headers */ = {isa = PBXBuildFile; fileRef = 1BAD4FEE1CDF54CA00692E31 /* LayoutOps.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -35,7 +35,7 @@
3535
1B49D70B1DB8D02800823FF3 /* Viewport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Viewport.swift; sourceTree = "<group>"; };
3636
1B49D70C1DB8D02800823FF3 /* Follow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Follow.swift; sourceTree = "<group>"; };
3737
1B49D70D1DB8D02800823FF3 /* Basic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Basic.swift; sourceTree = "<group>"; };
38-
1B49D70E1DB8D02800823FF3 /* Put.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Put.swift; sourceTree = "<group>"; };
38+
1B49D70E1DB8D02800823FF3 /* PutWrap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PutWrap.swift; sourceTree = "<group>"; };
3939
1B6645E31DB8F44C0059CFC8 /* Accelerate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Accelerate.swift; sourceTree = "<group>"; };
4040
1B7857CD1E6019D00025DD28 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
4141
1BAD4FEB1CDF54CA00692E31 /* LayoutOps.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LayoutOps.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -91,7 +91,7 @@
9191
1B2B82971DCD1F90008B6450 /* Anchor.swift */,
9292
1B49D70D1DB8D02800823FF3 /* Basic.swift */,
9393
1B49D70C1DB8D02800823FF3 /* Follow.swift */,
94-
1B49D70E1DB8D02800823FF3 /* Put.swift */,
94+
1B49D70E1DB8D02800823FF3 /* PutWrap.swift */,
9595
1B49D7091DB8D02800823FF3 /* SizeToFit.swift */,
9696
1B49D70B1DB8D02800823FF3 /* Viewport.swift */,
9797
1B6645E31DB8F44C0059CFC8 /* Accelerate.swift */,
@@ -197,7 +197,7 @@
197197
1B11ECF71DE4F915001FEBE7 /* Node.swift in Sources */,
198198
1B49D7141DB8D02800823FF3 /* Basic.swift in Sources */,
199199
1B6645E41DB8F44C0059CFC8 /* Accelerate.swift in Sources */,
200-
1B49D7151DB8D02800823FF3 /* Put.swift in Sources */,
200+
1B49D7151DB8D02800823FF3 /* PutWrap.swift in Sources */,
201201
1B11ECFE1DE57CC6001FEBE7 /* LabelNode.swift in Sources */,
202202
1BDCF03F1E3BD43800BEADEE /* LX.swift in Sources */,
203203
1B11ED001DE57D03001FEBE7 /* ImageNode.swift in Sources */,

LayoutOps/LayoutOps/Accelerate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright © 2016 Pavel Sharanda. All rights reserved.
44
//
55

6-
import UIKit
6+
import Foundation
77

88
//some common, but very specific ops
99

LayoutOps/LayoutOps/Basic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright © 2016 Pavel Sharanda. All rights reserved.
44
//
55

6-
import UIKit
6+
import Foundation
77

88
private func centerStart(_ value: CGFloat, superValue: CGFloat, start: CGFloat, finish: CGFloat) -> CGFloat {
99
return start + (superValue - start - finish - value)/2

LayoutOps/LayoutOps/Follow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright © 2016 Pavel Sharanda. All rights reserved.
44
//
55

6-
import UIKit
6+
import Foundation
77

88
private func follow_helper(_ anchorToFollow: Anchor, followerAnchor: Anchor) {
99
let toFollowView = anchorToFollow.view

0 commit comments

Comments
 (0)