by inamiy

inamiy /Cassowary

An incremental linear constraint-solving algorithm (Auto Layout) in Swift.

451 Stars 13 Forks Last release: Not found MIT License 4 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


An incremental linear constraint-solving algorithm (Auto Layout) in Swift, originally from the paper: Solving Linear Arithmetic Constraints for User Interface Applications (1997)

This repository consists of 3 frameworks:

  • Simplex: Simplex tableau and its common operations
  • Cassowary: Core constraint-solving algorithm using Simplex
  • CassowaryUI: UIKit/AppKit wrapper on top of Cassowary

How to use


import Cassowary
import CassowaryUI

let 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) == 40 ~ .high, - v1.bottom == ~ .high,
    rootSize.height - v2.bottom == ~ .high,

} solver.applyLayout()

This will result:

   | >
   | >





We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.