All Projects → inamiy → Cassowary

inamiy / Cassowary

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

Programming Languages

swift
15916 projects
dsl
153 projects

Labels

Projects that are alternatives of or similar to Cassowary

Tstl
TypeScript-STL (Standard Template Library, migrated from C++)
Stars: ✭ 397 (-12.56%)
Mutual labels:  algorithm
Bcrypt.net
BCrypt.Net - Bringing updates to the original bcrypt package
Stars: ✭ 422 (-7.05%)
Mutual labels:  algorithm
Js Sorting Algorithm
一本关于排序算法的 GitBook 在线书籍 《十大经典排序算法》,多语言实现。
Stars: ✭ 4,507 (+892.73%)
Mutual labels:  algorithm
Review the national post Graduate entrance examination
🌟复习考研的那些事儿(清华912考研)~~
Stars: ✭ 399 (-12.11%)
Mutual labels:  algorithm
Alass
"Automatic Language-Agnostic Subtitle Synchronization"
Stars: ✭ 421 (-7.27%)
Mutual labels:  algorithm
Pyshorttextcategorization
Various Algorithms for Short Text Mining
Stars: ✭ 429 (-5.51%)
Mutual labels:  algorithm
Ctcwordbeamsearch
Connectionist Temporal Classification (CTC) decoder with dictionary and language model for TensorFlow.
Stars: ✭ 398 (-12.33%)
Mutual labels:  algorithm
Earcut.hpp
Fast, header-only polygon triangulation
Stars: ✭ 447 (-1.54%)
Mutual labels:  algorithm
Aigames
use AI to play some games.
Stars: ✭ 422 (-7.05%)
Mutual labels:  algorithm
React Native Blurhash
🖼️ A library to show colorful blurry placeholders while your content loads.
Stars: ✭ 430 (-5.29%)
Mutual labels:  algorithm
Whatlang Rs
Natural language detection library for Rust. Try demo online: https://www.greyblake.com/whatlang/
Stars: ✭ 400 (-11.89%)
Mutual labels:  algorithm
Kdbush
A fast static index for 2D points
Stars: ✭ 412 (-9.25%)
Mutual labels:  algorithm
Algodeck
An Open-Source Collection of 200+ Algorithmic Flash Cards to Help you Preparing your Algorithm & Data Structure Interview 💯
Stars: ✭ 4,441 (+878.19%)
Mutual labels:  algorithm
Algorithmsanddatastructure
Algorithms And DataStructure Implemented In Python & CPP, Give a Star 🌟If it helps you
Stars: ✭ 400 (-11.89%)
Mutual labels:  algorithm
Usaco Guide
A free collection of curated, high-quality resources to take you from Bronze to Platinum and beyond.
Stars: ✭ 439 (-3.3%)
Mutual labels:  algorithm
Leetcode Swift
Solutions to LeetCode by Swift
Stars: ✭ 4,099 (+802.86%)
Mutual labels:  algorithm
Reinforcement Learning Algorithms
This repository contains most of pytorch implementation based classic deep reinforcement learning algorithms, including - DQN, DDQN, Dueling Network, DDPG, SAC, A2C, PPO, TRPO. (More algorithms are still in progress)
Stars: ✭ 426 (-6.17%)
Mutual labels:  algorithm
Problem Solving Javascript
🔥 Crack you JS interviews ⚡ Collection of most common JS Interview questions with Unit Tests 🚀
Stars: ✭ 451 (-0.66%)
Mutual labels:  algorithm
Causaldiscoverytoolbox
Package for causal inference in graphs and in the pairwise settings. Tools for graph structure recovery and dependencies are included.
Stars: ✭ 447 (-1.54%)
Mutual labels:  algorithm
Lintcode
Java Solutions to problems on LintCode/LeetCode
Stars: ✭ 4,180 (+820.7%)
Mutual labels:  algorithm

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].