Skip to main content

Crate cranpose_macros

Crate cranpose_macros 

Source
Expand description

§cranpose-macros

cranpose-macros provides #[composable] and #[preview], the procedural macros used by Cranpose components. Depend directly on the crate when a framework crate defines composables or preview fixtures. App code can import the macros through cranpose.

§Composable functions

The #[composable] macro gives each function call a composition group. The call-site identity keeps groups stable across recomposition. Value parameters use Clone and PartialEq; callback parameters use stored callback slots, so a new closure value reaches its composition position. #[composable(no_skip)] re-runs the body on each call.

This app example uses the facade and UI dependencies:

use cranpose::*;

#[composable]
fn Greeting(name: String) {
    Text(name, Modifier::empty(), TextStyle::default());
}

#[preview] registers a parameterless component fixture for IDE previews. Combine #[preview] with #[composable]. The cranpose preview feature enables preview registration. Options include name, group, width, height, and dark.

The hot-reload feature selects source-structure keys for development hot reload.

Macros§

message
Captures readable source text and arguments for translation when displayed. Accepts the same syntax as tr!, but works outside composition.
tr
Localizes readable source text using the nearest localization provider. Named arguments use name = expression; optional literal metadata is id, context, comment, and source_locale (default en).
translation_messages
Generates a module of named message accessors from a source-language Fluent file. Syntax: translation_messages!(pub mod messages, "locales/en/app.ftl").
translations
Embeds <directory>/<locale>/<namespace>.ftl catalogs and checks them at compile time. Syntax: translations!("locales", fallback = "en").

Attribute Macros§

composable
Turns a function into a composable: its body runs inside a group keyed by the call site, and recomposition skips it while its arguments are unchanged. #[composable(no_skip)] always re-runs the body.
preview
Registers a parameterless component fixture for IDE previews.