PHPackages                             sugarcraft/candy-layout - 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. sugarcraft/candy-layout

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

sugarcraft/candy-layout
=======================

Constraint-based layout solver (Cassowary simplex + greedy fallback)

02.9k↑27%PHP

Since Jul 10Pushed 1w agoCompare

[ Source](https://github.com/sugarcraft/candy-layout)[ Packagist](https://packagist.org/packages/sugarcraft/candy-layout)[ RSS](/packages/sugarcraft-candy-layout/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

CandyLayout
===========

[](#candylayout)

[![CI](https://github.com/detain/sugarcraft/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/detain/sugarcraft/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/d67d272415fe58afa5b3a24c753f9ebdc12ee5146aba795aa361a28faff8d209/68747470733a2f2f636f6465636f762e696f2f67682f64657461696e2f737567617263726166742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f666c61673d63616e64792d6c61796f7574)](https://app.codecov.io/gh/detain/sugarcraft?flags%5B0%5D=candy-layout)[![Packagist Version](https://camo.githubusercontent.com/29f9dba2d167142bd058fb2b126136f9e82dc329cb72fb6be4d44af06adaf44b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737567617263726166742f63616e64792d6c61796f75743f6c6162656c3d7061636b6167697374)](https://packagist.org/packages/sugarcraft/candy-layout)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/fd3accad83cd317a9843432403191b4e555c55d57d63e10897f3f1dff5ed169e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135382e332d3838393262662e737667)](https://www.php.net/)

Constraint-based layout solver for terminal grid layouts.

**GreedySolver is the default and only supported solver.** It is deterministic and fully implements every constraint type (Length/Min/Max/Fill/Percentage/Ratio).

`CassowarySolver` is **deprecated** — its Big-M simplex never converged (it hit the 1000-pivot cap on every call, including trivial layouts, and silently returned wrong state; its Ratio path returned 0). Rather than rewrite the simplex, `CassowarySolver::solve()` now emits `E_USER_DEPRECATED` and delegates wholly to `GreedySolver`. The class is retained only for backward compatibility; new code should use `GreedySolver` directly.

Install
-------

[](#install)

```
composer require sugarcraft/candy-layout
```

Quickstart
----------

[](#quickstart)

```
use SugarCraft\Layout\{Constraint, Direction, GreedySolver, Region};

$solver = GreedySolver::new();
$region = Region::fromSize(100, 24);

$rects = $solver->solve($region, Direction::Horizontal, [
    Constraint::length(20),      // exactly 20 cells
    Constraint::min(10),         // at least 10, takes more if available
    Constraint::fill(1),         // fills remaining space (weight 1)
    Constraint::percentage(30),  // 30% of total
    Constraint::ratio(1, 3),     // 1/3 of remaining after fixed
    Constraint::max(50),        // ceiling — greedy but clamped
]);
```

Solvers
-------

[](#solvers)

SolverUse caseStatusGreedySolverDeterministic, fast, no deps; all constraint typesSupportedCassowarySolverDeprecated; `solve()` delegates to GreedySolver + warnsDeprecatedConstraint types
----------------

[](#constraint-types)

- `Constraint::length(int)` — fixed cell count
- `Constraint::min(int)` — floor, grows if slack available
- `Constraint::max(int)` — ceiling, greedy, clamped
- `Constraint::fill(int $weight = 1)` — proportional remainder
- `Constraint::percentage(int 0-100)` — % of total
- `Constraint::ratio(int $num, int $denom)` — fractional proportion

Shared foundations
------------------

[](#shared-foundations)

`candy-layout` is a **foundation package** consumed by `candy-sprinkles` (step-10) and `sugar-bits`/`candy-forms` (step-14/15). The `LayoutSolver` interface is the only public contract. Use `GreedySolver`; `CassowarySolver` is a deprecated shim that delegates to it.

`Region` here is deliberately distinct from `SugarCraft\Buffer\Region` in candy-buffer (a leaf-package name collision that keeps candy-layout dependency-free); candy-sprinkles' `RegionBridge` converts between them.

References
----------

[](#references)

- Mirrors [ratatui/ratatui](https://github.com/ratatui/ratatui) layout constraint system
- Based on Badros &amp; Borning 2001 "The Cassowary Linear Arithmetic Constraint Solving Algorithm"

###  Health Score

27

—

LowBetter than 46% of packages

Maintenance64

Regular maintenance activity

Popularity24

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1036e0717211b8030b83cbe729e8ba6ba442fdbd5285fb97a39d7dcfe339342?d=identicon)[detain](/maintainers/detain)

---

Top Contributors

[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (7 commits)")

### Embed Badge

![Health badge](/badges/sugarcraft-candy-layout/health.svg)

```
[![Health](https://phpackages.com/badges/sugarcraft-candy-layout/health.svg)](https://phpackages.com/packages/sugarcraft-candy-layout)
```

###  Alternatives

[arm092/livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS

3059.5k](/packages/arm092-livewire-datatables)[hirasso/focal-point-picker

Zero-dependency custom focal point picker for your WordPress images 🎯

417.8k](/packages/hirasso-focal-point-picker)[sitegeist/inspectorgadget

Edit value objects in the inspector

1345.0k2](/packages/sitegeist-inspectorgadget)[wordpress/ai-provider-for-anthropic

AI Provider for Anthropic for the PHP AI Client SDK. Works as both a Composer package and WordPress plugin.

191.0k](/packages/wordpress-ai-provider-for-anthropic)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
