Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inamiy/cassowary
An incremental linear constraint-solving algorithm (Auto Layout) in Swift.
https://github.com/inamiy/cassowary
algorithm auto-layout cassowary constraint-solver dsl linear-programming simplex swift
Last synced: 3 days ago
JSON representation
An incremental linear constraint-solving algorithm (Auto Layout) in Swift.
- Host: GitHub
- URL: https://github.com/inamiy/cassowary
- Owner: inamiy
- License: mit
- Created: 2017-09-15T00:12:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-16T22:26:12.000Z (over 7 years ago)
- Last Synced: 2025-01-14T07:08:17.553Z (10 days ago)
- Topics: algorithm, auto-layout, cassowary, constraint-solver, dsl, linear-programming, simplex, swift
- Language: Swift
- Size: 59.6 KB
- Stars: 502
- Watchers: 9
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cassowary
An incremental linear constraint-solving algorithm (Auto Layout) in Swift, originally from the paper:
[Solving Linear Arithmetic Constraints for User Interface Applications (1997)](https://constraints.cs.washington.edu/solvers/uist97.html)This repository consists of 3 frameworks:
- [Simplex](Sources/Simplex): Simplex tableau and its common operations
- [Cassowary](Sources/Cassowary): Core constraint-solving algorithm using Simplex
- [CassowaryUI](Sources/CassowaryUI): UIKit/AppKit wrapper on top of Cassowary## How to use
### CassowaryUI
```swift
import Cassowary
import CassowaryUIlet rootSize = CGSize(width: 320, height: 480)
var solver = CassowaryUI.Solver()try! solver.addConstraints(view1, view2) { v1, v2 in
return [
// `v1` has fixed size (4:3 aspect ratio)
v1.width == rootSize.width - 40,
v1.height == v1.width * 3 / 4,// `v2` has fixed origin.x & width (flexible in vertical)
v2.width == v1.width,
v1.centerX == rootFrame.width / 2,
v2.centerX == v1.centerX,// equal spacing (vertical)
v1.top == 40 ~ .high,
v2.top - v1.bottom == v1.top ~ .high,
rootSize.height - v2.bottom == v1.top ~ .high,
]
}
solver.applyLayout()
```This will result:
```
>
| >
| >
```## Acknowledgments
- [Solving Linear Arithmetic Constraints for User Interface Applications (1997)](https://constraints.cs.washington.edu/solvers/uist97.html) by Alan Borning, Kim Marriott, Peter Stuckey, and Yi Xiao
- [ユーザインタフェースのための線形等式・不等式制約解消系 (2002)](https://www.jstage.jst.go.jp/article/jssst/19/6/19_6_437/_article/-char/ja/) by 細部 博史
- [pybee/cassowary](https://github.com/pybee/cassowary) (Python version)
- [robb/Cartography](https://github.com/robb/Cartography) (Auto Layout DSL in Swift)## References
- [AutoLayout Algorithm // Speaker Deck](https://speakerdeck.com/inamiy/autolayout-algorithm) (in Japanese)
## License
[MIT](LICENSE)