Coder Social home page Coder Social logo

bwetherfield / simplex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inamiy/cassowary

0.0 0.0 0.0 61 KB

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

License: MIT License

Swift 99.37% Makefile 0.40% Objective-C 0.23%

simplex's Introduction

Cassowary

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

CassowaryUI

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)
        v1.top == 40 ~ .high,
        v2.top - v1.bottom == v1.top ~ .high,
        rootSize.height - v2.bottom == v1.top ~ .high,
    ]
}
solver.applyLayout()

This will result:

<UIView: 0x7f8f1ee018c0; frame = (0 0; 320 480); layer = <CALayer: 0x608000220800>>
   | <UIView: 0x7f8f21001010; frame = (20 40; 280 210); layer = <CALayer: 0x60c000220da0>>
   | <UIView: 0x7f8f1ec015c0; frame = (20 290; 280 150); layer = <CALayer: 0x60c000220840>>

Acknowledgments

References

License

MIT

simplex's People

Contributors

inamiy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.