A pure Java implementation of the Taffy UI layout library, supporting CSS Flexbox, Grid, and Block layout algorithms. It passes the Taffy test suite, ported to Java.
implementation("dev.aika:taffy:1.2.0")<dependency> <groupId>dev.aika</groupId> <artifactId>taffy</artifactId> <version>1.2.0</version> </dependency>
Use the all classifier (dev.aika:taffy:1.2.0:all) if you do not want the fastutil runtime dependency.
TaffyTree tree = new TaffyTree(); TaffyStyle item = TaffyStyle.builder().size(100f, 50f).build(); NodeId a = tree.newLeaf(item); NodeId b = tree.newLeaf(item); TaffyStyle rootStyle = TaffyStyle.builder() .display(TaffyDisplay.FLEX) .gap(0f, 10f) .build(); NodeId root = tree.newWithChildren(rootStyle, a, b); tree.computeLayout(root, new TaffySize<>( AvailableSpace.definite(800f), AvailableSpace.definite(600f) )); Layout lb = tree.getLayout(b); // b.x == 110
Benchmarks live in src/jmh and run with ./gradlew jmh. The Java port is close to Rust on
typical trees and slower under extreme depth/width; reproduce with the JMH sources in this
repository before relying on any specific number.
- Original Taffy library by DioxusLabs
- Python bindings Stretchable for reference
This Java port was facilitated by AI.