Skip to content

Latest commit

 

History

287 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Taffy4J

Java 11 bindings for Taffy 0.13.0, with Flexbox, Grid, Block, float layout, parsing, measurement callbacks, and native binaries for Linux, Windows, and macOS on x86-64 and ARM64.

Quick start

Add Taffy4J from Maven Central:

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.antepod:taffy4j:0.13.0-2")
}

The artifact includes native libraries for every supported platform; no separate native dependency or java.library.path configuration is required.

import com.antepod.taffy.geometry.Size;
import com.antepod.taffy.style.AvailableSpace;
import com.antepod.taffy.style.Display;
import com.antepod.taffy.style.Style;
import com.antepod.taffy.tree.Layout;
import com.antepod.taffy.tree.NodeId;
import com.antepod.taffy.tree.TaffyTree;

try (TaffyTree<Void> tree = new TaffyTree<>()) {
    NodeId child = tree.newLeaf(Style.builder().size(120.0f, 40.0f).build());
    NodeId root = tree.newWithChildren(
            Style.builder().display(Display.FLEX).size(640.0f, 480.0f).build(),
            child);

    tree.computeLayout(root, new Size<>(
            AvailableSpace.definite(640.0f),
            AvailableSpace.definite(480.0f)));

    Layout layout = tree.layout(child);
    System.out.println(layout.location.x + ", " + layout.location.y);
}

The tree owns native memory, so use try-with-resources. A tree is not thread-safe; synchronize externally if multiple threads share it.

See Getting started, installation, the platform matrix, and layout-change tracking.

Retained-mode layout invalidation

Taffy4J can return exact observable layout changes from one native compute and one packed JNI result:

LayoutChanges changes = tree.computeLayoutWithChanges(root, availableSpace);
for (LayoutChange change : changes) {
    if (change.geometryChanged()) {
        // update retained UI geometry
    }
}

An optional listener provides the same batch one record at a time after native compute has returned. Existing compute methods keep their original non-tracking native path when no listener is installed.

Taffy4J requires Java 11 or newer. Published classes target Java 11 bytecode.

Native access on JDK 24+

Taffy4J loads its bundled JNI library with System.load. JDK 24 and newer warn when native access is not explicitly enabled; a future JDK will deny it by default. Applications using Taffy4J from the class path should start with:

java --enable-native-access=ALL-UNNAMED ...

For Gradle's application plugin:

application {
    applicationDefaultJvmArgs = listOf("--enable-native-access=ALL-UNNAMED")
}

About

A high performance rust-powered UI layout library in Java

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages