| Crates.io | clay-layout |
| lib.rs | clay-layout |
| version | 0.4.0 |
| created_at | 2024-12-26 13:14:22.450586+00 |
| updated_at | 2025-06-03 16:54:29.594084+00 |
| description | Rust bindings for Clay, a UI layout library written in C. |
| homepage | |
| repository | https://github.com/clay-ui-rs/clay |
| max_upload_size | |
| id | 1495641 |
| size | 571,559 |
Rust bindings for Clay, a UI layout library written in C.
# Cargo.toml
[dependencies]
clay-layout = "0.4"
Example usage:
use clay_layout::{fixed, Clay, Declaration};
fn main() {
// Create the clay instance
let mut clay = Clay::new((800., 600.).into());
// Begin the layout
let mut clay = clay.begin::<(), ()>();
// Adds a red rectangle with a corner radius of 5.
// The Layout makes the rectangle have a width and height of 50.
clay.with(&Declaration::new()
.id(clay.id("red_rectangle"))
.layout()
.width(fixed!(50.))
.height(fixed!(50.))
.end()
.corner_radius()
.all(5.)
.end()
.background_color((0xFF, 0x00, 0x00).into()), |_| {},
);
// Return the list of render commands of your layout
let render_commands = clay.end();
for command in render_commands {
println!("Id of the element: {}", command.id); // Note: Ids are in fact numbers generated by Clay
println!("Bounding box: {:?}", command.bounding_box);
println!("Type and config: {:?}", command.config);
}
}
Examples can be found in the examples/ directory. They can be ran using cargo:
cargo run --example basic_rectangle
cargo run --example raylib_renderer --features raylib-renderer
Notice that building the bindings is only required if you update the clay.h
To build bindings you need to use the generate_bindings script.
It needs bindgen installed as a CLI, you can install it with cargo install bindgen.
Calling it will use the clay.h in the project root, or any clay.h file provided with CLAY_HEADER_PATH.
Using the clay header it will generate src/bindings/bindings.rs and src/bindings/bindings_debug.rs.