| Crates.io | blinc_macros |
| lib.rs | blinc_macros |
| version | 0.1.12 |
| created_at | 2026-01-14 17:18:46.023005+00 |
| updated_at | 2026-01-19 00:25:09.740955+00 |
| description | Procedural macros for Blinc UI framework |
| homepage | |
| repository | https://github.com/project-blinc/Blinc |
| max_upload_size | |
| id | 2043273 |
| size | 26,328 |
Part of the Blinc UI Framework
This crate is a component of Blinc, a GPU-accelerated UI framework for Rust. For full documentation and guides, visit the Blinc documentation.
Procedural macros for Blinc UI.
blinc_macros provides derive macros for generating boilerplate code in Blinc applications.
Generate component infrastructure including unique keys, animation hooks, and state management:
use blinc_macros::BlincComponent;
#[derive(BlincComponent)]
struct MyButton {
label: String,
#[animate]
scale: f32,
#[animate]
opacity: f32,
}
impl MyButton {
fn new(label: impl Into<String>) -> Self {
Self {
label: label.into(),
scale: 1.0,
opacity: 1.0,
}
}
fn render(&self) -> impl ElementBuilder {
button(&self.label)
.transform(Transform::scale(self.scale, self.scale))
.opacity(self.opacity)
}
}
The BlincComponent derive generates:
impl MyButton {
// Unique component key for diffing
fn component_key() -> &'static str {
"MyButton_abc123" // Compile-time unique ID
}
// Instance key for multiple instances
fn instance_key(&self) -> String {
format!("{}_{}", Self::component_key(), /* instance id */)
}
// Animation state accessors
fn animated_scale(&self) -> AnimatedValue<f32> { ... }
fn animated_opacity(&self) -> AnimatedValue<f32> { ... }
}
#[animate]Mark a field as animatable:
#[derive(BlincComponent)]
struct Card {
#[animate]
height: f32, // Generates AnimatedValue<f32>
#[animate(spring = "bouncy")]
scale: f32, // Use bouncy spring preset
#[animate(duration = 300)]
opacity: f32, // 300ms duration
}
#[state]Mark a field as reactive state:
#[derive(BlincComponent)]
struct Counter {
#[state]
count: i32, // Generates Signal<i32>
}
// Usage:
counter.count.set(5);
let value = counter.count.get();
#[key]Customize instance key generation:
#[derive(BlincComponent)]
#[key(field = "id")]
struct ListItem {
id: String,
label: String,
}
// Instance key will use the `id` field
// Single instance (default)
#[derive(BlincComponent)]
struct Header { ... }
// Multiple instances with auto key
#[derive(BlincComponent)]
#[key(auto)]
struct ListItem { ... }
// Multiple instances with explicit key field
#[derive(BlincComponent)]
#[key(field = "item_id")]
struct ListItem {
item_id: String,
...
}
syn and quote for macro implementationMIT OR Apache-2.0