PHPackages                             php-tui/cassowary - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. php-tui/cassowary

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

php-tui/cassowary
=================

Cassowary constraint solving algorithm implementation

0.1.0(2y ago)21759.9k↓17.8%1[1 PRs](https://github.com/php-tui/cassowary/pulls)1MITPHPPHP ^8.1

Since Oct 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/php-tui/cassowary)[ Packagist](https://packagist.org/packages/php-tui/cassowary)[ RSS](/packages/php-tui-cassowary/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (1)

PHP Cassowary
=============

[](#php-cassowary)

[![CI](https://github.com/php-tui/cassowary/actions/workflows/ci.yml/badge.svg)](https://github.com/php-tui/cassowary/actions/workflows/ci.yml)

Implementation of the Cassowary constraint solving algorithm. Based heavily on [cassowary-rs](https://github.com/dylanede/cassowary-rs) which is based on [kiwi](https://github.com/nucleic/kiwi).

This library can be used to specify and resolve constraints for user interfaces.

Status
------

[](#status)

I've ported just enough of the code to support solving constraints. I *have not* ported support for edit variables or changing constraints. PRs welcome.

Installation
------------

[](#installation)

```
$ composer require phptui/cassowary

```

What does it do?
----------------

[](#what-does-it-do)

Given we want to render a layout on a screen with a defined size. The layout have two two sections:

```
+-------+-------------------+
|   A   |         B         |
+-------+-------------------+

```

We would need to introduce variables for each of the points in sections `a` and `b`:

```
       0                           30

       ax1     ax2,bx1             bx2
0  y1  +-------+-------------------+
       |       |                   |
2  y2  +-------+-------------------+

```

And then specify the constraints that must be maintained:

```
ax1 = 0         // the left-most point is CONSTANT at 0
ax2 >= ax1      // ax2 is REQUIRED to be greater than equal to ax1
ax2 >= ax1 + 10 // ax2 must have a WEAK requirement to be greater than equal to ax1 plus 10
bx1 = ax2       // bx1 and bx2 are REQUIRED to be contiguous
bx2 = 30        // bx2 is REQUIRED be at the right-most point - 30
// etc

```

There are two interesting things:

- Constraints can relate to each other
- Constraints have a *strength* which determines which constraint to take into account if there is a conflict.

The constraint solver is able to resolve such constraints into an optimal solution.

Usage
-----

[](#usage)

Using the above example:

```
