{"id":17146257,"url":"https://github.com/inamiy/cassowary","last_synced_at":"2025-04-07T06:11:57.745Z","repository":{"id":142082971,"uuid":"103594242","full_name":"inamiy/Cassowary","owner":"inamiy","description":"An incremental linear constraint-solving algorithm (Auto Layout) in Swift.","archived":false,"fork":false,"pushed_at":"2017-09-16T22:26:12.000Z","size":61,"stargazers_count":504,"open_issues_count":0,"forks_count":17,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-31T05:05:16.989Z","etag":null,"topics":["algorithm","auto-layout","cassowary","constraint-solver","dsl","linear-programming","simplex","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inamiy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-09-15T00:12:50.000Z","updated_at":"2025-02-03T08:05:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"e74b5e80-60a9-4477-aced-ad9d11427f45","html_url":"https://github.com/inamiy/Cassowary","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FCassowary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FCassowary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FCassowary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FCassowary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inamiy","download_url":"https://codeload.github.com/inamiy/Cassowary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601448,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","auto-layout","cassowary","constraint-solver","dsl","linear-programming","simplex","swift"],"created_at":"2024-10-14T21:08:13.515Z","updated_at":"2025-04-07T06:11:57.727Z","avatar_url":"https://github.com/inamiy.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cassowary\n\nAn incremental linear constraint-solving algorithm (Auto Layout) in Swift, originally from the paper:\n[Solving Linear Arithmetic Constraints for User Interface Applications (1997)](https://constraints.cs.washington.edu/solvers/uist97.html)\n\nThis repository consists of 3 frameworks:\n\n- [Simplex](Sources/Simplex): Simplex tableau and its common operations\n- [Cassowary](Sources/Cassowary): Core constraint-solving algorithm using Simplex\n- [CassowaryUI](Sources/CassowaryUI): UIKit/AppKit wrapper on top of Cassowary\n\n## How to use\n\n### CassowaryUI\n\n```swift\nimport Cassowary\nimport CassowaryUI\n\nlet rootSize = CGSize(width: 320, height: 480)\nvar solver = CassowaryUI.Solver()\n\ntry! solver.addConstraints(view1, view2) { v1, v2 in\n    return [\n        // `v1` has fixed size (4:3 aspect ratio)\n        v1.width == rootSize.width - 40,\n        v1.height == v1.width * 3 / 4,\n\n        // `v2` has fixed origin.x \u0026 width (flexible in vertical)\n        v2.width == v1.width,\n        v1.centerX == rootFrame.width / 2,\n        v2.centerX == v1.centerX,\n\n        // equal spacing (vertical)\n        v1.top == 40 ~ .high,\n        v2.top - v1.bottom == v1.top ~ .high,\n        rootSize.height - v2.bottom == v1.top ~ .high,\n    ]\n}\nsolver.applyLayout()\n```\n\nThis will result:\n\n```\n\u003cUIView: 0x7f8f1ee018c0; frame = (0 0; 320 480); layer = \u003cCALayer: 0x608000220800\u003e\u003e\n   | \u003cUIView: 0x7f8f21001010; frame = (20 40; 280 210); layer = \u003cCALayer: 0x60c000220da0\u003e\u003e\n   | \u003cUIView: 0x7f8f1ec015c0; frame = (20 290; 280 150); layer = \u003cCALayer: 0x60c000220840\u003e\u003e\n```\n\n## Acknowledgments\n\n- [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\n- [ユーザインタフェースのための線形等式・不等式制約解消系 (2002)](https://www.jstage.jst.go.jp/article/jssst/19/6/19_6_437/_article/-char/ja/) by 細部 博史\n- [pybee/cassowary](https://github.com/pybee/cassowary) (Python version)\n- [robb/Cartography](https://github.com/robb/Cartography) (Auto Layout DSL in Swift)\n\n## References\n\n- [AutoLayout Algorithm // Speaker Deck](https://speakerdeck.com/inamiy/autolayout-algorithm) (in Japanese)\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finamiy%2Fcassowary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finamiy%2Fcassowary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finamiy%2Fcassowary/lists"}